5 #include "../drivers.h"
9 #include <minix/endpoint.h>
13 PUBLIC
struct pci_acl pci_acl
[NR_DRIVERS
];
15 FORWARD
_PROTOTYPE( void do_init
, (message
*mp
) );
16 FORWARD
_PROTOTYPE( void do_first_dev
, (message
*mp
) );
17 FORWARD
_PROTOTYPE( void do_next_dev
, (message
*mp
) );
18 FORWARD
_PROTOTYPE( void do_find_dev
, (message
*mp
) );
19 FORWARD
_PROTOTYPE( void do_ids
, (message
*mp
) );
20 FORWARD
_PROTOTYPE( void do_dev_name
, (message
*mp
) );
21 FORWARD
_PROTOTYPE( void do_dev_name_s
, (message
*mp
) );
22 FORWARD
_PROTOTYPE( void do_slot_name_s
, (message
*mp
) );
23 FORWARD
_PROTOTYPE( void do_set_acl
, (message
*mp
) );
24 FORWARD
_PROTOTYPE( void do_del_acl
, (message
*mp
) );
25 FORWARD
_PROTOTYPE( void do_reserve
, (message
*mp
) );
26 FORWARD
_PROTOTYPE( void do_attr_r8
, (message
*mp
) );
27 FORWARD
_PROTOTYPE( void do_attr_r16
, (message
*mp
) );
28 FORWARD
_PROTOTYPE( void do_attr_r32
, (message
*mp
) );
29 FORWARD
_PROTOTYPE( void do_attr_w8
, (message
*mp
) );
30 FORWARD
_PROTOTYPE( void do_attr_w16
, (message
*mp
) );
31 FORWARD
_PROTOTYPE( void do_attr_w32
, (message
*mp
) );
32 FORWARD
_PROTOTYPE( void do_rescan_bus
, (message
*mp
) );
33 FORWARD
_PROTOTYPE( void reply
, (message
*mp
, int result
) );
34 FORWARD
_PROTOTYPE( struct rs_pci
*find_acl
, (int endpoint
) );
38 /* SEF functions and variables. */
39 FORWARD
_PROTOTYPE( void sef_local_startup
, (void) );
46 /* SEF local startup. */
51 r
= sef_receive(ANY
, &m
);
54 printf("PCI: sef_receive from ANY failed: %d\n", r
);
58 if (is_notify(m
.m_type
)) {
59 switch (_ENDPOINT_P(m
.m_source
)) {
63 printf("PCI: got notify from %d\n",
68 /* done, get a new message */
74 case BUSC_PCI_INIT
: do_init(&m
); break;
75 case BUSC_PCI_FIRST_DEV
: do_first_dev(&m
); break;
76 case BUSC_PCI_NEXT_DEV
: do_next_dev(&m
); break;
77 case BUSC_PCI_FIND_DEV
: do_find_dev(&m
); break;
78 case BUSC_PCI_IDS
: do_ids(&m
); break;
79 case BUSC_PCI_DEV_NAME
: do_dev_name(&m
); break;
80 case BUSC_PCI_RESERVE
: do_reserve(&m
); break;
81 case BUSC_PCI_ATTR_R8
: do_attr_r8(&m
); break;
82 case BUSC_PCI_ATTR_R16
: do_attr_r16(&m
); break;
83 case BUSC_PCI_ATTR_R32
: do_attr_r32(&m
); break;
84 case BUSC_PCI_ATTR_W8
: do_attr_w8(&m
); break;
85 case BUSC_PCI_ATTR_W16
: do_attr_w16(&m
); break;
86 case BUSC_PCI_ATTR_W32
: do_attr_w32(&m
); break;
87 case BUSC_PCI_RESCAN
: do_rescan_bus(&m
); break;
88 case BUSC_PCI_DEV_NAME_S
: do_dev_name_s(&m
); break;
89 case BUSC_PCI_SLOT_NAME_S
: do_slot_name_s(&m
); break;
90 case BUSC_PCI_SET_ACL
: do_set_acl(&m
); break;
91 case BUSC_PCI_DEL_ACL
: do_del_acl(&m
); break;
93 printf("PCI: got message from %d, type %d\n",
94 m
.m_source
, m
.m_type
);
102 /*===========================================================================*
103 * sef_local_startup *
104 *===========================================================================*/
105 PRIVATE
void sef_local_startup()
107 /* Register init callbacks. */
108 sef_setcb_init_fresh(sef_cb_init_fresh
);
109 sef_setcb_init_lu(sef_cb_init_fresh
);
110 sef_setcb_init_restart(sef_cb_init_fresh
);
112 /* Register live update callbacks. */
113 sef_setcb_lu_prepare(sef_cb_lu_prepare_always_ready
);
114 sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_standard
);
116 /* Let SEF perform startup. */
120 PRIVATE
void do_init(mp
)
126 printf("PCI: do_init: called by '%d'\n", mp
->m_source
);
130 r
= send(mp
->m_source
, mp
);
132 printf("PCI: do_init: unable to send to %d: %d\n",
136 PRIVATE
void do_first_dev(mp
)
143 aclp
= find_acl(mp
->m_source
);
146 printf("PCI: do_first_dev: no acl for caller %d\n",
149 r
= pci_first_dev_a(aclp
, &devind
, &vid
, &did
);
157 r
= send(mp
->m_source
, mp
);
160 printf("PCI: do_first_dev: unable to send to %d: %d\n",
165 PRIVATE
void do_next_dev(mp
)
173 aclp
= find_acl(mp
->m_source
);
175 r
= pci_next_dev_a(aclp
, &devind
, &vid
, &did
);
183 r
= send(mp
->m_source
, mp
);
186 printf("PCI: do_next_dev: unable to send to %d: %d\n",
191 PRIVATE
void do_find_dev(mp
)
201 r
= pci_find_dev(bus
, dev
, func
, &devind
);
205 r
= send(mp
->m_source
, mp
);
208 printf("PCI: do_find_dev: unable to send to %d: %d\n",
213 PRIVATE
void do_ids(mp
)
221 r
= pci_ids_s(devind
, &vid
, &did
);
224 printf("pci:do_ids: failed for devind %d: %d\n",
231 r
= send(mp
->m_source
, mp
);
234 printf("PCI: do_ids: unable to send to %d: %d\n",
239 PRIVATE
void do_dev_name(mp
)
242 int r
, name_len
, len
;
244 char *name_ptr
, *name
;
251 name
= pci_dev_name(vid
, did
);
262 printf("PCI: pci`do_dev_name: calling do_vircopy\n");
263 r
= sys_vircopy(SELF
, D
, (vir_bytes
)name
, mp
->m_source
, D
,
264 (vir_bytes
)name_ptr
, len
);
268 r
= send(mp
->m_source
, mp
);
271 printf("PCI: do_dev_name: unable to send to %d: %d\n",
276 PRIVATE
void do_dev_name_s(mp
)
279 int r
, name_len
, len
;
281 cp_grant_id_t name_gid
;
289 name
= pci_dev_name(vid
, did
);
300 r
= sys_safecopyto(mp
->m_source
, name_gid
, 0, (vir_bytes
)name
,
305 r
= send(mp
->m_source
, mp
);
308 printf("PCI: do_dev_name: unable to send to %d: %d\n",
313 PRIVATE
void do_slot_name_s(mp
)
316 int r
, devind
, name_len
, len
;
324 r
= pci_slot_name_s(devind
, &name
);
327 printf("pci:do_slot_name_s: failed for devind %d: %d\n",
336 r
= sys_safecopyto(mp
->m_source
, gid
, 0,
337 (vir_bytes
)name
, len
, D
);
341 r
= send(mp
->m_source
, mp
);
344 printf("PCI: do_slot_name: unable to send to %d: %d\n",
349 PRIVATE
void do_set_acl(mp
)
354 if (mp
->m_source
!= RS_PROC_NR
)
356 printf("PCI: do_set_acl: not from RS\n");
361 for (i
= 0; i
<NR_DRIVERS
; i
++)
363 if (!pci_acl
[i
].inuse
)
368 printf("PCI: do_set_acl: table is full\n");
375 r
= sys_safecopyfrom(mp
->m_source
, gid
, 0, (vir_bytes
)&pci_acl
[i
].acl
,
376 sizeof(pci_acl
[i
].acl
), D
);
379 printf("PCI: do_set_acl: safecopyfrom failed\n");
385 printf("PCI: do_acl: setting ACL for %d ('%s') at entry %d\n",
386 pci_acl
[i
].acl
.rsp_endpoint
, pci_acl
[i
].acl
.rsp_label
,
392 PRIVATE
void do_del_acl(mp
)
397 if (mp
->m_source
!= RS_PROC_NR
)
399 printf("do_del_acl: not from RS\n");
406 for (i
= 0; i
<NR_DRIVERS
; i
++)
408 if (!pci_acl
[i
].inuse
)
410 if (pci_acl
[i
].acl
.rsp_endpoint
== proc_nr
)
416 printf("do_del_acl: nothing found for %d\n", proc_nr
);
423 printf("do_acl: deleting ACL for %d ('%s') at entry %d\n",
424 pci_acl
[i
].acl
.rsp_endpoint
, pci_acl
[i
].acl
.rsp_label
, i
);
427 /* Also release all devices held by this process */
428 pci_release(proc_nr
);
433 PRIVATE
void do_reserve(mp
)
440 mp
->m_type
= pci_reserve2(devind
, mp
->m_source
);
441 r
= send(mp
->m_source
, mp
);
444 printf("do_reserve: unable to send to %d: %d\n",
449 PRIVATE
void do_attr_r8(mp
)
458 r
= pci_attr_r8_s(devind
, port
, &v
);
462 "pci:do_attr_r8: pci_attr_r8_s(%d, %d, ...) failed: %d\n",
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 r
= pci_attr_r32_s(devind
, port
, &v
);
508 "pci:do_attr_r32: pci_attr_r32_s(%d, %d, ...) failed: %d\n",
513 r
= send(mp
->m_source
, mp
);
516 printf("do_attr_r32: unable to send to %d: %d\n",
521 PRIVATE
void do_attr_w8(mp
)
531 pci_attr_w8(devind
, port
, v
);
533 r
= send(mp
->m_source
, mp
);
536 printf("do_attr_w8: unable to send to %d: %d\n",
541 PRIVATE
void do_attr_w16(mp
)
551 pci_attr_w16(devind
, port
, v
);
553 r
= send(mp
->m_source
, mp
);
556 printf("do_attr_w16: unable to send to %d: %d\n",
561 PRIVATE
void do_attr_w32(mp
)
571 pci_attr_w32(devind
, port
, v
);
573 r
= send(mp
->m_source
, mp
);
576 printf("do_attr_w32: unable to send to %d: %d\n",
581 PRIVATE
void do_rescan_bus(mp
)
588 pci_rescan_bus(busnr
);
590 r
= send(mp
->m_source
, mp
);
593 printf("do_rescan_bus: unable to send to %d: %d\n",
599 PRIVATE
void reply(mp
, result
)
607 r
= send(mp
->m_source
, &m
);
609 printf("reply: unable to send to %d: %d\n", mp
->m_source
, r
);
613 PRIVATE
struct rs_pci
*find_acl(endpoint
)
618 /* Find ACL entry for caller */
619 for (i
= 0; i
<NR_DRIVERS
; i
++)
621 if (!pci_acl
[i
].inuse
)
623 if (pci_acl
[i
].acl
.rsp_endpoint
== endpoint
)
624 return &pci_acl
[i
].acl
;