kernel: Fix a bunch of drm warnings.
[dragonfly.git] / sys / dev / netif / ar / if_ar_isa.c
1 /*-
2  * Copyright (c) 1995 - 2001 John Hay.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the author nor the names of any co-contributors
13  *    may be used to endorse or promote products derived from this software
14  *    without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY John Hay ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL John Hay BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD: src/sys/dev/ar/if_ar_isa.c,v 1.54 2005/01/06 01:42:28 imp Exp $
29  */
30
31 /*
32  * Programming assumptions and other issues.
33  *
34  * The descriptors of a DMA channel will fit in a 16K memory window.
35  *
36  * The buffers of a transmit DMA channel will fit in a 16K memory window.
37  *
38  * Only the ISA bus cards with X.21 and V.35 is tested.
39  *
40  * When interface is going up, handshaking is set and it is only cleared
41  * when the interface is down'ed.
42  *
43  * There should be a way to set/reset Raw HDLC/PPP, Loopback, DCE/DTE,
44  * internal/external clock, etc.....
45  */
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
50 #include <sys/module.h>
51 #include <sys/bus.h>
52 #include <sys/rman.h>
53
54 #include <bus/isa/isavar.h>
55 #include "isa_if.h"
56
57 #include <dev/netif/ic_layer/hd64570.h>
58 #include <dev/netif/ar/if_arregs.h>
59
60 #ifdef TRACE
61 #define TRC(x)               x
62 #else
63 #define TRC(x)
64 #endif
65
66 #define TRCL(x)              x
67
68 static int ar_isa_probe (device_t);
69 static int ar_isa_attach (device_t);
70
71 static struct isa_pnp_id ar_ids[] = {
72         {0,             NULL}
73 };
74
75 static device_method_t ar_methods[] = {
76         DEVMETHOD(device_probe,         ar_isa_probe),
77         DEVMETHOD(device_attach,        ar_isa_attach),
78         DEVMETHOD(device_detach,        ar_detach),
79         DEVMETHOD_END
80 };
81
82 static driver_t ar_isa_driver = {
83         "ar",
84         ar_methods,
85         sizeof (struct ar_hardc)
86 };
87
88 DRIVER_MODULE(if_ar, isa, ar_isa_driver, ar_devclass, NULL, NULL);
89
90 /*
91  * Probe to see if it is there.
92  * Get its information and fill it in.
93  */
94 static int
95 ar_isa_probe(device_t device)
96 {
97         int error;
98         u_long membase, memsize;
99         struct ar_hardc *hc;
100
101         error = ISA_PNP_PROBE(device_get_parent(device), device, ar_ids);
102         if(error == ENXIO || error == 0)
103                 return (error);
104
105         hc = (struct ar_hardc *)device_get_softc(device);
106
107         if((error = ar_allocate_ioport(device, 0, ARC_IO_SIZ))) {
108                 return (ENXIO);
109         }
110
111         /*
112          * Now see if the card is realy there.
113          *
114          * XXX For now I just check the undocumented ports
115          * for "570". We will probably have to do more checking.
116          */
117         if((ar_inb(hc, AR_ID_5) != '5') ||
118            (ar_inb(hc, AR_ID_7) != '7') ||
119            (ar_inb(hc, AR_ID_0) != '0')) {
120                 ar_deallocate_resources(device);
121                 return (ENXIO);
122         }
123         membase = bus_get_resource_start(device, SYS_RES_MEMORY, 0);
124         memsize = ar_inb(hc, AR_REV);
125         memsize = 1 << ((memsize & AR_WSIZ_MSK) >> AR_WSIZ_SHFT);
126         memsize *= ARC_WIN_SIZ;
127         error = bus_set_resource(device, SYS_RES_MEMORY, 0, membase, memsize,
128             -1);
129         ar_deallocate_resources(device);
130
131         return (error);
132 }
133
134 /*
135  * Malloc memory for the softc structures.
136  * Reset the card to put it in a known state.
137  * Register the ports on the adapter.
138  * Fill in the info for each port.
139  * Attach each port to sppp and bpf.
140  */
141 static int
142 ar_isa_attach(device_t device)
143 {
144         u_int tmp;
145         u_long irq, junk;
146         struct ar_hardc *hc;
147
148         hc = (struct ar_hardc *)device_get_softc(device);
149         if(ar_allocate_ioport(device, 0, ARC_IO_SIZ))
150                 return (ENXIO);
151
152         tmp = ar_inb(hc, AR_BMI);
153         hc->bustype = tmp & AR_BUS_MSK;
154         hc->memsize = (tmp & AR_MEM_MSK) >> AR_MEM_SHFT;
155         hc->memsize = 1 << hc->memsize;
156         hc->memsize <<= 16;
157         hc->interface[0] = (tmp & AR_IFACE_MSK);
158         hc->interface[1] = hc->interface[0];
159         hc->interface[2] = hc->interface[0];
160         hc->interface[3] = hc->interface[0];
161         tmp = ar_inb(hc, AR_REV);
162         hc->revision = tmp & AR_REV_MSK;
163         hc->winsize = 1 << ((tmp & AR_WSIZ_MSK) >> AR_WSIZ_SHFT);
164         hc->winsize *= ARC_WIN_SIZ;
165         hc->winmsk = hc->winsize - 1;
166         hc->numports = ar_inb(hc, AR_PNUM);
167         hc->handshake = ar_inb(hc, AR_HNDSH);
168
169         if(ar_allocate_memory(device, 0, hc->winsize))
170                 return (ENXIO);
171
172         hc->mem_start = rman_get_virtual(hc->res_memory);
173         hc->mem_end = hc->mem_start + hc->winsize;
174         hc->cunit = device_get_unit(device);
175
176         switch(hc->interface[0]) {
177         case AR_IFACE_EIA_232:
178                 kprintf("ar%d: The EIA 232 interface is not supported.\n",
179                         hc->cunit);
180                 ar_deallocate_resources(device);
181                 return (ENXIO);
182         case AR_IFACE_V_35:
183                 break;
184         case AR_IFACE_EIA_530:
185                 kprintf("ar%d: WARNING: The EIA 530 interface is untested.\n",
186                         hc->cunit);
187                 break;
188         case AR_IFACE_X_21:
189                 break;
190         case AR_IFACE_COMBO:
191                 kprintf("ar%d: WARNING: The COMBO interface is untested.\n",
192                         hc->cunit);
193                 break;
194         }
195
196         /*
197          * Do a little sanity check.
198          */
199         if((hc->numports > NPORT) || (hc->memsize > (512*1024))) {
200                 ar_deallocate_resources(device);
201                 return (ENXIO);
202         }
203
204         if(ar_allocate_irq(device, 0, 1))
205                 return (ENXIO);
206
207         if(bus_get_resource(device, SYS_RES_IRQ, 0, &irq, &junk)) {
208                 ar_deallocate_resources(device);
209                 return (ENXIO);
210         }
211         hc->isa_irq = irq;
212
213         if(ar_attach(device)) {
214                 ar_deallocate_resources(device);
215                 return (ENXIO);
216         }
217
218         return (0);
219 }
220
221 /*
222  ********************************* END ************************************
223  */