5 #include "../drivers.h"
26 FORWARD
_PROTOTYPE( void do_init
, (message
*mp
) );
27 FORWARD
_PROTOTYPE( void do_sig_handler
, (void) );
28 FORWARD
_PROTOTYPE( void do_first_dev
, (message
*mp
) );
29 FORWARD
_PROTOTYPE( void do_next_dev
, (message
*mp
) );
30 FORWARD
_PROTOTYPE( void do_find_dev
, (message
*mp
) );
31 FORWARD
_PROTOTYPE( void do_ids
, (message
*mp
) );
32 FORWARD
_PROTOTYPE( void do_dev_name
, (message
*mp
) );
33 FORWARD
_PROTOTYPE( void do_dev_name_s
, (message
*mp
) );
34 FORWARD
_PROTOTYPE( void do_slot_name
, (message
*mp
) );
35 FORWARD
_PROTOTYPE( void do_slot_name_s
, (message
*mp
) );
36 FORWARD
_PROTOTYPE( void do_acl
, (message
*mp
) );
37 FORWARD
_PROTOTYPE( void do_reserve
, (message
*mp
) );
38 FORWARD
_PROTOTYPE( void do_attr_r8
, (message
*mp
) );
39 FORWARD
_PROTOTYPE( void do_attr_r16
, (message
*mp
) );
40 FORWARD
_PROTOTYPE( void do_attr_r32
, (message
*mp
) );
41 FORWARD
_PROTOTYPE( void do_attr_w8
, (message
*mp
) );
42 FORWARD
_PROTOTYPE( void do_attr_w16
, (message
*mp
) );
43 FORWARD
_PROTOTYPE( void do_attr_w32
, (message
*mp
) );
44 FORWARD
_PROTOTYPE( void do_rescan_bus
, (message
*mp
) );
45 FORWARD
_PROTOTYPE( void reply
, (message
*mp
, int result
) );
46 FORWARD
_PROTOTYPE( struct rs_pci
*find_acl
, (int endpoint
) );
57 for (i
= 0; i
<NR_DRIVERS
; i
++)
65 printf("PCI: receive from ANY failed: %d\n", r
);
70 case BUSC_PCI_INIT
: do_init(&m
); break;
71 case BUSC_PCI_FIRST_DEV
: do_first_dev(&m
); break;
72 case BUSC_PCI_NEXT_DEV
: do_next_dev(&m
); break;
73 case BUSC_PCI_FIND_DEV
: do_find_dev(&m
); break;
74 case BUSC_PCI_IDS
: do_ids(&m
); break;
75 case BUSC_PCI_DEV_NAME
: do_dev_name(&m
); break;
76 case BUSC_PCI_SLOT_NAME
: do_slot_name(&m
); break;
77 case BUSC_PCI_RESERVE
: do_reserve(&m
); break;
78 case BUSC_PCI_ATTR_R8
: do_attr_r8(&m
); break;
79 case BUSC_PCI_ATTR_R16
: do_attr_r16(&m
); break;
80 case BUSC_PCI_ATTR_R32
: do_attr_r32(&m
); break;
81 case BUSC_PCI_ATTR_W8
: do_attr_w8(&m
); break;
82 case BUSC_PCI_ATTR_W16
: do_attr_w16(&m
); break;
83 case BUSC_PCI_ATTR_W32
: do_attr_w32(&m
); break;
84 case BUSC_PCI_RESCAN
: do_rescan_bus(&m
); break;
85 case BUSC_PCI_DEV_NAME_S
: do_dev_name_s(&m
); break;
86 case BUSC_PCI_SLOT_NAME_S
: do_slot_name_s(&m
); break;
87 case BUSC_PCI_ACL
: do_acl(&m
); break;
88 case PROC_EVENT
: do_sig_handler(); break;
90 printf("PCI: got message from %d, type %d\n",
91 m
.m_source
, m
.m_type
);
99 /*===========================================================================*
101 *===========================================================================*/
102 PRIVATE
void do_sig_handler()
107 /* Try to obtain signal set from PM. */
108 if (getsigset(&sigset
) != 0) return;
110 /* Check for known signals. */
111 if (sigismember(&sigset
, SIGTERM
)) {
116 PRIVATE
void do_init(mp
)
122 printf("PCI: pci_init: called by '%s'\n", mp
->m3_ca1
);
125 for (i
= 0; i
<NR_DRIVERS
; i
++)
127 if (empty
== -1 && names
[i
].tasknr
== ANY
)
129 if (strcmp(names
[i
].name
, mp
->m3_ca1
) == 0)
135 panic("pci", "do_init: too many clients", NR_DRIVERS
);
137 strcpy(names
[i
].name
, mp
->m3_ca1
);
139 else if (names
[i
].tasknr
== mp
->m_source
)
141 /* Ignore all init calls for a process after the first one */
145 pci_release(names
[i
].name
);
147 names
[i
].tasknr
= mp
->m_source
;
150 r
= send(mp
->m_source
, mp
);
152 printf("PCI: do_init: unable to send to %d: %d\n",
156 PRIVATE
void do_first_dev(mp
)
163 aclp
= find_acl(mp
->m_source
);
166 printf("PCI: do_first_dev: no acl for caller %d\n",
169 r
= pci_first_dev_a(aclp
, &devind
, &vid
, &did
);
177 r
= send(mp
->m_source
, mp
);
180 printf("PCI: do_first_dev: unable to send to %d: %d\n",
185 PRIVATE
void do_next_dev(mp
)
193 aclp
= find_acl(mp
->m_source
);
195 r
= pci_next_dev_a(aclp
, &devind
, &vid
, &did
);
203 r
= send(mp
->m_source
, mp
);
206 printf("PCI: do_next_dev: unable to send to %d: %d\n",
211 PRIVATE
void do_find_dev(mp
)
221 r
= pci_find_dev(bus
, dev
, func
, &devind
);
225 r
= send(mp
->m_source
, mp
);
228 printf("PCI: do_find_dev: unable to send to %d: %d\n",
233 PRIVATE
void do_ids(mp
)
241 pci_ids(devind
, &vid
, &did
);
245 r
= send(mp
->m_source
, mp
);
248 printf("PCI: do_ids: unable to send to %d: %d\n",
253 PRIVATE
void do_dev_name(mp
)
256 int r
, name_len
, len
;
258 char *name_ptr
, *name
;
265 name
= pci_dev_name(vid
, did
);
276 printf("PCI: pci`do_dev_name: calling do_vircopy\n");
277 r
= sys_vircopy(SELF
, D
, (vir_bytes
)name
, mp
->m_source
, D
,
278 (vir_bytes
)name_ptr
, len
);
282 r
= send(mp
->m_source
, mp
);
285 printf("PCI: do_dev_name: unable to send to %d: %d\n",
290 PRIVATE
void do_dev_name_s(mp
)
293 int r
, name_len
, len
;
295 cp_grant_id_t name_gid
;
303 name
= pci_dev_name(vid
, did
);
314 r
= sys_safecopyto(mp
->m_source
, name_gid
, 0, (vir_bytes
)name
,
319 r
= send(mp
->m_source
, mp
);
322 printf("PCI: do_dev_name: unable to send to %d: %d\n",
327 PRIVATE
void do_slot_name(mp
)
330 int r
, devind
, name_len
, len
;
331 char *name_ptr
, *name
;
337 name
= pci_slot_name(devind
);
342 printf("PCI: pci`do_slot_name: calling do_vircopy\n");
343 r
= sys_vircopy(SELF
, D
, (vir_bytes
)name
, mp
->m_source
, D
,
344 (vir_bytes
)name_ptr
, len
);
347 r
= send(mp
->m_source
, mp
);
350 printf("PCI: do_slot_name: unable to send to %d: %d\n",
355 PRIVATE
void do_slot_name_s(mp
)
358 int r
, devind
, name_len
, len
;
366 name
= pci_slot_name(devind
);
371 r
= sys_safecopyto(mp
->m_source
, gid
, 0, (vir_bytes
)name
, len
, D
);
374 r
= send(mp
->m_source
, mp
);
377 printf("PCI: do_slot_name: unable to send to %d: %d\n",
382 PRIVATE
void do_acl(mp
)
387 if (mp
->m_source
!= RS_PROC_NR
)
389 printf("PCI: do_acl: not from RS\n");
394 for (i
= 0; i
<NR_DRIVERS
; i
++)
401 printf("PCI: do_acl: table is full\n");
408 r
= sys_safecopyfrom(mp
->m_source
, gid
, 0, (vir_bytes
)&acl
[i
].acl
,
409 sizeof(acl
[i
].acl
), D
);
412 printf("PCI: do_acl: safecopyfrom failed\n");
418 printf("PCI: do_acl: setting ACL for %d ('%s') at entry %d\n",
419 acl
[i
].acl
.rsp_endpoint
, acl
[i
].acl
.rsp_label
,
425 PRIVATE
void do_reserve(mp
)
430 /* Find the name of the caller */
431 for (i
= 0; i
<NR_DRIVERS
; i
++)
433 if (names
[i
].tasknr
== mp
->m_source
)
438 printf("pci`do_reserve: task %d did not call pci_init\n",
446 mp
->m_type
= pci_reserve3(devind
, mp
->m_source
, names
[i
].name
);
447 r
= send(mp
->m_source
, mp
);
450 printf("do_reserve: unable to send to %d: %d\n",
455 PRIVATE
void do_attr_r8(mp
)
464 v
= pci_attr_r8(devind
, port
);
467 r
= send(mp
->m_source
, mp
);
470 printf("do_attr_r8: unable to send to %d: %d\n",
475 PRIVATE
void do_attr_r16(mp
)
484 v
= pci_attr_r16(devind
, port
);
487 r
= send(mp
->m_source
, mp
);
490 printf("do_attr_r16: unable to send to %d: %d\n",
495 PRIVATE
void do_attr_r32(mp
)
504 v
= pci_attr_r32(devind
, port
);
507 r
= send(mp
->m_source
, mp
);
510 printf("do_attr_r32: unable to send to %d: %d\n",
515 PRIVATE
void do_attr_w8(mp
)
525 pci_attr_w8(devind
, port
, v
);
527 r
= send(mp
->m_source
, mp
);
530 printf("do_attr_w8: unable to send to %d: %d\n",
535 PRIVATE
void do_attr_w16(mp
)
545 pci_attr_w16(devind
, port
, v
);
547 r
= send(mp
->m_source
, mp
);
550 printf("do_attr_w16: unable to send to %d: %d\n",
555 PRIVATE
void do_attr_w32(mp
)
565 pci_attr_w32(devind
, port
, v
);
567 r
= send(mp
->m_source
, mp
);
570 printf("do_attr_w32: unable to send to %d: %d\n",
575 PRIVATE
void do_rescan_bus(mp
)
582 pci_rescan_bus(busnr
);
584 r
= send(mp
->m_source
, mp
);
587 printf("do_rescan_bus: unable to send to %d: %d\n",
593 PRIVATE
void reply(mp
, result
)
601 r
= send(mp
->m_source
, &m
);
603 printf("reply: unable to send to %d: %d\n", mp
->m_source
, r
);
607 PRIVATE
struct rs_pci
*find_acl(endpoint
)
612 /* Find ACL entry for caller */
613 for (i
= 0; i
<NR_DRIVERS
; i
++)
617 if (acl
[i
].acl
.rsp_endpoint
== endpoint
)