39 #define DIVA_DIDD_MAX_NOTIFICATIONS 256
40 static didd_adapter_change_notification_t \
46 static dword Adapters = 0;
51 static void no_printf(
unsigned char *
format, ...)
79 diva_dadapter_request };
83 static dword diva_register_adapter_callback(\
86 static void diva_remove_adapter_callback(
dword handle);
87 static void diva_notify_adapter_change(
DESCRIPTOR *
d,
int removal);
93 memset(&HandleTable[0], 0x00,
sizeof(HandleTable));
94 memset(&NotificationTable[0], 0x00,
sizeof(NotificationTable));
95 diva_os_initialize_spin_lock(&didd_spin,
"didd");
108 static int diva_didd_add_descriptor(
DESCRIPTOR *
d) {
115 diva_notify_adapter_change(&MAdapter, 0);
119 diva_notify_adapter_change(&MAdapter, 1);
125 for (i = 0; i < NEW_MAX_DESCRIPTORS; i++) {
126 diva_os_enter_spin_lock(&didd_spin, &irql,
"didd_add");
127 if (HandleTable[i].
type == 0) {
128 memcpy(&HandleTable[i], d,
sizeof(*d));
130 diva_os_leave_spin_lock(&didd_spin, &irql,
"didd_add");
131 diva_notify_adapter_change(d, 0);
135 diva_os_leave_spin_lock(&didd_spin, &irql, "didd_add");
148 if (request == MAdapter.request) {
151 diva_notify_adapter_change(&MAdapter, 1);
152 MAdapter.request = (
IDI_CALL)no_printf;
155 for (i = 0; (Adapters && (i < NEW_MAX_DESCRIPTORS)); i++) {
156 if (HandleTable[i].request == request) {
157 diva_notify_adapter_change(&HandleTable[i], 1);
158 diva_os_enter_spin_lock(&didd_spin, &irql,
"didd_rm");
159 memset(&HandleTable[i], 0x00,
sizeof(HandleTable[0]));
161 diva_os_leave_spin_lock(&didd_spin, &irql,
"didd_rm");
162 DBG_TRC((
"Remove adapter[%d], request=%08x", (i + 1), request))
166 DBG_ERR(("Invalid request=%08
x, can'
t remove adapter", request))
176 memset(buffer, 0x00, length);
178 DBG_TRC((
"DIDD_Read, space = %d, Adapters = %d", length, Adapters + 2))
180 diva_os_enter_spin_lock(&didd_spin, &irql, "didd_read");
181 for (src = 0, dst = 0;
182 (Adapters && (src < NEW_MAX_DESCRIPTORS) && (dst < length));
184 if (HandleTable[src].
type) {
189 diva_os_leave_spin_lock(&didd_spin, &irql,
"didd_read");
194 DBG_ERR((
"Can't write DIMAINT. Array too small"))
200 DBG_ERR((
"Can't write DADAPTER. Array too small"))
202 DBG_TRC((
"Read %d adapters", dst))
203 return (dst == length);
215 DBG_ERR((
"Can't process async request, Req=%02x", e->Req))
224 pinfo->
handle = diva_register_adapter_callback( \
231 diva_remove_adapter_callback(pinfo->
handle);
261 DBG_ERR((
"Can't process sync request, Req=%02x", e->Rc))
268 static
dword diva_register_adapter_callback( \
275 diva_os_enter_spin_lock(&didd_spin, &irql,
"didd_nfy_add");
276 if (!NotificationTable[i].callback) {
279 diva_os_leave_spin_lock(&didd_spin, &irql,
"didd_nfy_add");
280 DBG_TRC((
"Register adapter notification[%d]=%08x", i + 1, callback))
283 diva_os_leave_spin_lock(&didd_spin, &irql, "didd_nfy_add");
291 static
void diva_remove_adapter_callback(
dword handle) {
293 if (handle && ((--handle) < DIVA_DIDD_MAX_NOTIFICATIONS)) {
294 diva_os_enter_spin_lock(&didd_spin, &irql,
"didd_nfy_rm");
297 diva_os_leave_spin_lock(&didd_spin, &irql,
"didd_nfy_rm");
298 DBG_TRC((
"Remove adapter notification[%d]", (
int)(handle + 1)))
301 DBG_ERR(("Can'
t remove adapter notification, handle=%d", handle))
309 static
void diva_notify_adapter_change(
DESCRIPTOR *d,
int removal) {
315 diva_os_enter_spin_lock(&didd_spin, &irql,
"didd_nfy");
316 if (NotificationTable[i].callback) {
317 memcpy(&nfy, &NotificationTable[i],
sizeof(nfy));
320 diva_os_leave_spin_lock(&didd_spin, &irql,
"didd_nfy");
363 diva_didd_read_adapter_array(buffer, length);