]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/dev/si/si_pci.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.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         if (pci_get_devid(dev) == 0x200011cb) {
109                 int rid;
110                 struct resource *plx_res;
111                 uint32_t *addr;
112                 uint32_t oldvalue;
113
114                 /* Perform a PLX control register fixup */
115                 rid = PCIR_BAR(0);
116                 plx_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
117                     RF_ACTIVE);
118                 if (plx_res == NULL) {
119                         device_printf(dev, "couldn't map plx registers\n");
120                 } else {
121                         addr = rman_get_virtual(plx_res);
122                         oldvalue = addr[0x50 / 4];
123                         if (oldvalue != 0x18260000) {
124                                 device_printf(dev, "PLX register 0x50: 0x%08x changed to 0x%08x\n", oldvalue, 0x18260000);
125                                 addr[0x50 / 4] = 0x18260000;
126                         }
127                         bus_release_resource(dev, SYS_RES_MEMORY, rid, plx_res);
128                 }
129         }
130
131         error = siattach(dev);
132         if (error)
133                 goto fail;
134         return (0);             /* success */
135
136 fail:
137         if (error == 0)
138                 error = ENXIO;
139         if (sc->sc_irq_res) {
140                 if (ih)
141                         bus_teardown_intr(dev, sc->sc_irq_res, ih);
142                 bus_release_resource(dev, SYS_RES_IRQ,
143                                      sc->sc_irq_rid, sc->sc_irq_res);
144                 sc->sc_irq_res = 0;
145         }
146         if (sc->sc_mem_res) {
147                 bus_release_resource(dev, SYS_RES_MEMORY,
148                                      sc->sc_mem_rid, sc->sc_mem_res);
149                 sc->sc_mem_res = 0;
150         }
151         return (error);
152 }
153
154 static device_method_t si_pci_methods[] = {
155         /* Device interface */
156         DEVMETHOD(device_probe,         si_pci_probe),
157         DEVMETHOD(device_attach,        si_pci_attach),
158
159         { 0, 0 }
160 };
161
162 static driver_t si_pci_driver = {
163         "si",
164         si_pci_methods,
165         sizeof(struct si_softc),
166 };
167
168 DRIVER_MODULE(si, pci, si_pci_driver, si_devclass, 0, 0);