2 * Port-based I/O routines. These are in a separate module because most
3 * drivers will not use them, and system services are statically linked.
5 #include <minix/drivers.h>
6 #include <minix/netdriver.h>
12 * Port-based I/O byte sequence copy routine.
15 netdriver_portb(struct netdriver_data
* data
, size_t off
, long port
,
16 size_t size
, int portin
)
22 off
= netdriver_prepare_copy(data
, off
, size
, &i
);
24 req
= portin
? DIO_SAFE_INPUT_BYTE
: DIO_SAFE_OUTPUT_BYTE
;
27 chunk
= data
->iovec
[i
].iov_size
- off
;
32 if ((r
= sys_sdevio(req
, port
, data
->endpt
,
33 (void *)data
->iovec
[i
].iov_grant
, chunk
, off
)) != OK
)
34 panic("netdriver: port I/O failed: %d", r
);
43 * Transfer bytes from hardware to a destination buffer using port-based I/O.
46 netdriver_portinb(struct netdriver_data
* data
, size_t off
, long port
,
50 return netdriver_portb(data
, off
, port
, size
, TRUE
/*portin*/);
54 * Transfer bytes from a source buffer to hardware using port-based I/O.
57 netdriver_portoutb(struct netdriver_data
* data
, size_t off
, long port
,
61 return netdriver_portb(data
, off
, port
, size
, FALSE
/*portin*/);
65 * Transfer words from hardware to a destination buffer using port-based I/O.
68 netdriver_portinw(struct netdriver_data
* data
, size_t off
, long port
,
77 off
= netdriver_prepare_copy(data
, off
, size
, &i
);
81 chunk
= data
->iovec
[i
].iov_size
- off
;
87 if ((r
= sys_safecopyto(data
->endpt
,
88 data
->iovec
[i
].iov_grant
, off
,
89 (vir_bytes
)&((char *)&buf
)[1], 1)) != OK
)
90 panic("netdriver: unable to copy data: %d", r
);
101 if ((r
= sys_safe_insw(port
, data
->endpt
,
102 data
->iovec
[i
].iov_grant
, off
, chunk
)) != OK
)
103 panic("netdriver: port input failed: %d", r
);
110 if ((r
= sys_inw(port
, &value
)) != OK
)
111 panic("netdriver: port input failed: %d", r
);
112 buf
= (uint16_t)value
;
114 if ((r
= sys_safecopyto(data
->endpt
,
115 data
->iovec
[i
].iov_grant
, off
,
116 (vir_bytes
)&((char *)&buf
)[0], 1)) != OK
)
117 panic("netdriver: unable to copy data: %d", r
);
128 * Transfer words from a source buffer to hardware using port-based I/O.
131 netdriver_portoutw(struct netdriver_data
* data
, size_t off
, long port
,
139 off
= netdriver_prepare_copy(data
, off
, size
, &i
);
143 chunk
= data
->iovec
[i
].iov_size
- off
;
149 if ((r
= sys_safecopyfrom(data
->endpt
,
150 data
->iovec
[i
].iov_grant
, off
,
151 (vir_bytes
)&((char *)&buf
)[1], 1)) != OK
)
152 panic("netdriver: unable to copy data: %d", r
);
154 if ((r
= sys_outw(port
, buf
)) != OK
)
155 panic("netdriver: port output failed: %d", r
);
162 odd_byte
= chunk
& 1;
166 if ((r
= sys_safe_outsw(port
, data
->endpt
,
167 data
->iovec
[i
].iov_grant
, off
, chunk
)) != OK
)
168 panic("netdriver: port output failed: %d", r
);
175 if ((r
= sys_safecopyfrom(data
->endpt
,
176 data
->iovec
[i
].iov_grant
, off
,
177 (vir_bytes
)&((char *)&buf
)[0], 1)) != OK
)
178 panic("netdriver: unable to copy data: %d", r
);
188 ((char *)&buf
)[1] = 0;
190 if ((r
= sys_outw(port
, buf
)) != OK
)
191 panic("netdriver: port output failed: %d", r
);