]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/sio/sio_ebus.c
network interface driver changes:
[FreeBSD/FreeBSD.git] / sys / dev / sio / sio_ebus.c
1 /*-
2  * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/bus.h>
32 #include <sys/kernel.h>
33 #include <sys/timepps.h>
34 #include <sys/tty.h>
35
36 #include <machine/bus.h>
37
38 #include <dev/sio/siovar.h>
39
40 #include <ofw/openfirm.h>
41 #include <sparc64/ebus/ebusvar.h>
42
43 int     sio_ofw_inlist(char *name, char *list[]);
44 static  int     sio_ebus_attach(device_t dev);
45 static  int     sio_ebus_probe(device_t dev);
46
47 static device_method_t sio_ebus_methods[] = {
48         /* Device interface */
49         DEVMETHOD(device_probe,         sio_ebus_probe),
50         DEVMETHOD(device_attach,        sio_ebus_attach),
51
52         { 0, 0 }
53 };
54
55 static driver_t sio_ebus_driver = {
56         sio_driver_name,
57         sio_ebus_methods,
58         0,
59 };
60
61 DRIVER_MODULE(sio, ebus, sio_ebus_driver, sio_devclass, 0, 0);
62
63 /* Needed for EBus attach and sparc64 console support */
64 char *sio_ofw_names[] = {
65         "serial",
66         "su",
67         "su_pnp",
68         NULL
69 };
70
71 char *sio_ofw_compat[] = {
72         "su",
73         "su16550",
74         NULL
75 };
76
77 int
78 sio_ofw_inlist(name, list)
79         char    *name;
80         char    *list[];
81 {
82         int     i;
83
84         if (name == NULL)
85                 return (0);
86         for (i = 0; list[i] != NULL; i++) {
87                 if (strcmp(name, list[i]) == 0)
88                         return (1);
89         }
90         return (0);
91 }
92
93 static int
94 sio_ebus_probe(dev)
95         device_t        dev;
96 {
97         char    *n;
98
99         n = ebus_get_name(dev);
100         if (!sio_ofw_inlist(n, sio_ofw_names) && (strcmp(n, "serial") != 0 ||
101             !sio_ofw_inlist(ebus_get_compat(dev), sio_ofw_compat)))
102                 return (ENXIO);
103         /* Do not probe IRQ - isa_irq_pending() does not work for ebus. */
104         return (sioprobe(dev, 0, 0UL, 1));
105 }
106
107 static int
108 sio_ebus_attach(dev)
109         device_t        dev;
110 {
111
112         return (sioattach(dev, 0, 0UL));
113 }