]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/si/si_pci.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / dev / si / si_pci.c
1 /*-
2  * Device driver for Specialix range (SI/XIO) of serial line multiplexors.
3  *
4  * Copyright (C) 2000, Peter Wemm <peter@netplex.com.au>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notices, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notices, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
16  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18  * NO EVENT SHALL THE AUTHORS BE LIABLE.
19  */
20
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
23
24 #include <sys/param.h>
25 #include <sys/systm.h>
26 #include <sys/kernel.h>
27 #include <sys/module.h>
28 #include <sys/bus.h>
29 #include <machine/bus.h>
30 #include <sys/rman.h>
31 #include <machine/resource.h>
32
33 #include <dev/si/sireg.h>
34 #include <dev/si/sivar.h>
35
36 #include <dev/pci/pcireg.h>
37 #include <dev/pci/pcivar.h>
38
39 static int
40 si_pci_probe(device_t dev)
41 {
42         const char *desc = NULL;
43
44         switch (pci_get_devid(dev)) {
45         case 0x400011cb:
46                 desc = "Specialix SI/XIO PCI host card";
47                 break;
48         case 0x200011cb:
49                 if (pci_read_config(dev, SIJETSSIDREG, 4) == 0x020011cb)
50                         desc = "Specialix SX PCI host card";
51                 break;
52         }
53         if (desc) {
54                 device_set_desc(dev, desc);
55                 return BUS_PROBE_DEFAULT;
56         }
57         return ENXIO;
58 }
59
60 static int
61 si_pci_attach(device_t dev)
62 {
63         struct si_softc *sc;
64         void *ih;
65         int error;
66
67         error = 0;
68         ih = NULL;
69         sc = device_get_softc(dev);
70
71         switch (pci_get_devid(dev)) {
72         case 0x400011cb:
73                 sc->sc_type = SIPCI;
74                 sc->sc_mem_rid = SIPCIBADR;
75                 break;
76         case 0x200011cb:
77                 sc->sc_type = SIJETPCI;
78                 sc->sc_mem_rid = SIJETBADR;
79                 break;
80         }
81
82         sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
83                                                 &sc->sc_mem_rid,
84                                                 RF_ACTIVE);
85         if (!sc->sc_mem_res) {
86                 device_printf(dev, "couldn't map memory\n");
87                 goto fail;
88         }
89         sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
90         sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
91
92         sc->sc_irq_rid = 0;
93         sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
94                                                 &sc->sc_irq_rid,
95                                                 RF_ACTIVE | RF_SHAREABLE);
96         if (!sc->sc_irq_res) {
97                 device_printf(dev, "couldn't map interrupt\n");
98                 goto fail;
99         }
100         sc->sc_irq = rman_get_start(sc->sc_irq_res);
101         error = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_TTY,
102                                NULL, si_intr, sc, &ih);
103         if (error) {
104                 device_printf(dev, "could not activate interrupt\n");
105                 goto fail;
106         }
107
108         error = siattach(dev);
109         if (error)
110                 goto fail;
111         return (0);             /* success */
112
113 fail:
114         if (error == 0)
115                 error = ENXIO;
116         if (sc->sc_irq_res) {
117                 if (ih)
118                         bus_teardown_intr(dev, sc->sc_irq_res, ih);
119                 bus_release_resource(dev, SYS_RES_IRQ,
120                                      sc->sc_irq_rid, sc->sc_irq_res);
121                 sc->sc_irq_res = 0;
122         }
123         if (sc->sc_mem_res) {
124                 bus_release_resource(dev, SYS_RES_MEMORY,
125                                      sc->sc_mem_rid, sc->sc_mem_res);
126                 sc->sc_mem_res = 0;
127         }
128         return (error);
129 }
130
131 static device_method_t si_pci_methods[] = {
132         /* Device interface */
133         DEVMETHOD(device_probe,         si_pci_probe),
134         DEVMETHOD(device_attach,        si_pci_attach),
135
136         { 0, 0 }
137 };
138
139 static driver_t si_pci_driver = {
140         "si",
141         si_pci_methods,
142         sizeof(struct si_softc),
143 };
144
145 DRIVER_MODULE(si, pci, si_pci_driver, si_devclass, 0, 0);