xref: /minix3/minix/drivers/net/dpeth/devio.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /*
2*433d6423SLionel Sambuc **  File:	devio.c		Jun. 11, 2005
3*433d6423SLionel Sambuc **
4*433d6423SLionel Sambuc **  Author:	Giovanni Falzoni <gfalzoni@inwind.it>
5*433d6423SLionel Sambuc **
6*433d6423SLionel Sambuc **  This file contains the routines for readind/writing
7*433d6423SLionel Sambuc **  from/to the device registers.
8*433d6423SLionel Sambuc */
9*433d6423SLionel Sambuc 
10*433d6423SLionel Sambuc #include <minix/drivers.h>
11*433d6423SLionel Sambuc #include <net/gen/ether.h>
12*433d6423SLionel Sambuc #include <net/gen/eth_io.h>
13*433d6423SLionel Sambuc #include "dp.h"
14*433d6423SLionel Sambuc 
15*433d6423SLionel Sambuc #if (USE_IOPL == 0)
16*433d6423SLionel Sambuc 
17*433d6423SLionel Sambuc static void warning(const char *type, int err)
18*433d6423SLionel Sambuc {
19*433d6423SLionel Sambuc 
20*433d6423SLionel Sambuc   printf("Warning: eth#0 sys_%s failed (%d)\n", type, err);
21*433d6423SLionel Sambuc   return;
22*433d6423SLionel Sambuc }
23*433d6423SLionel Sambuc 
24*433d6423SLionel Sambuc /*
25*433d6423SLionel Sambuc **  Name:	unsigned int inb(unsigned short int port);
26*433d6423SLionel Sambuc **  Function:	Reads a byte from specified i/o port.
27*433d6423SLionel Sambuc */
28*433d6423SLionel Sambuc unsigned int inb(unsigned short port)
29*433d6423SLionel Sambuc {
30*433d6423SLionel Sambuc   u32_t value;
31*433d6423SLionel Sambuc   int rc;
32*433d6423SLionel Sambuc 
33*433d6423SLionel Sambuc   if ((rc = sys_inb(port, &value)) != OK) warning("inb", rc);
34*433d6423SLionel Sambuc   return value;
35*433d6423SLionel Sambuc }
36*433d6423SLionel Sambuc 
37*433d6423SLionel Sambuc /*
38*433d6423SLionel Sambuc **  Name:	unsigned int inw(unsigned short int port);
39*433d6423SLionel Sambuc **  Function:	Reads a word from specified i/o port.
40*433d6423SLionel Sambuc */
41*433d6423SLionel Sambuc unsigned int inw(unsigned short port)
42*433d6423SLionel Sambuc {
43*433d6423SLionel Sambuc   u32_t value;
44*433d6423SLionel Sambuc   int rc;
45*433d6423SLionel Sambuc 
46*433d6423SLionel Sambuc   if ((rc = sys_inw(port, &value)) != OK) warning("inw", rc);
47*433d6423SLionel Sambuc   return value;
48*433d6423SLionel Sambuc }
49*433d6423SLionel Sambuc 
50*433d6423SLionel Sambuc /*
51*433d6423SLionel Sambuc **  Name:	unsigned int insb(unsigned short int port, int proc_nr, void *buffer, int count);
52*433d6423SLionel Sambuc **  Function:	Reads a sequence of bytes from specified i/o port to user space buffer.
53*433d6423SLionel Sambuc */
54*433d6423SLionel Sambuc void insb(unsigned short int port, endpoint_t proc_nr,
55*433d6423SLionel Sambuc    void *buffer, int count)
56*433d6423SLionel Sambuc {
57*433d6423SLionel Sambuc   int rc;
58*433d6423SLionel Sambuc 
59*433d6423SLionel Sambuc   if ((rc = sys_insb(port, proc_nr, buffer, count)) != OK)
60*433d6423SLionel Sambuc 	warning("insb", rc);
61*433d6423SLionel Sambuc   return;
62*433d6423SLionel Sambuc }
63*433d6423SLionel Sambuc 
64*433d6423SLionel Sambuc 
65*433d6423SLionel Sambuc /*
66*433d6423SLionel Sambuc **  Name:	void outb(unsigned short int port, unsigned long value);
67*433d6423SLionel Sambuc **  Function:	Writes a byte to specified i/o port.
68*433d6423SLionel Sambuc */
69*433d6423SLionel Sambuc void outb(unsigned short port, unsigned long value)
70*433d6423SLionel Sambuc {
71*433d6423SLionel Sambuc   int rc;
72*433d6423SLionel Sambuc 
73*433d6423SLionel Sambuc   if ((rc = sys_outb(port, value)) != OK) warning("outb", rc);
74*433d6423SLionel Sambuc   return;
75*433d6423SLionel Sambuc }
76*433d6423SLionel Sambuc 
77*433d6423SLionel Sambuc /*
78*433d6423SLionel Sambuc **  Name:	void outw(unsigned short int port, unsigned long value);
79*433d6423SLionel Sambuc **  Function:	Writes a word to specified i/o port.
80*433d6423SLionel Sambuc */
81*433d6423SLionel Sambuc void outw(unsigned short port, unsigned long value)
82*433d6423SLionel Sambuc {
83*433d6423SLionel Sambuc   int rc;
84*433d6423SLionel Sambuc 
85*433d6423SLionel Sambuc   if ((rc = sys_outw(port, value)) != OK) warning("outw", rc);
86*433d6423SLionel Sambuc   return;
87*433d6423SLionel Sambuc }
88*433d6423SLionel Sambuc 
89*433d6423SLionel Sambuc /*
90*433d6423SLionel Sambuc **  Name:	void outsb(unsigned short int port, int proc_nr, void *buffer, int count);
91*433d6423SLionel Sambuc **  Function:	Writes a sequence of bytes from user space to specified i/o port.
92*433d6423SLionel Sambuc */
93*433d6423SLionel Sambuc void outsb(unsigned short port, endpoint_t proc_nr, void *buffer, int count)
94*433d6423SLionel Sambuc {
95*433d6423SLionel Sambuc   int rc;
96*433d6423SLionel Sambuc 
97*433d6423SLionel Sambuc   if ((rc = sys_outsb(port, proc_nr, buffer, count)) != OK)
98*433d6423SLionel Sambuc 	warning("outsb", rc);
99*433d6423SLionel Sambuc   return;
100*433d6423SLionel Sambuc }
101*433d6423SLionel Sambuc 
102*433d6423SLionel Sambuc #else
103*433d6423SLionel Sambuc #error To be implemented
104*433d6423SLionel Sambuc #endif				/* USE_IOPL */
105*433d6423SLionel Sambuc /**  devio.c  **/
106