Deleted Added
full compact
si_pci.c (119287) si_pci.c (119419)
1/*
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.
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 * $FreeBSD: head/sys/dev/si/si_pci.c 119287 2003-08-22 07:08:17Z imp $
21 */
22
19 */
20
21#include <sys/cdefs.h>
22__FBSDID("$FreeBSD: head/sys/dev/si/si_pci.c 119419 2003-08-24 18:03:45Z obrien $");
23
23#include <sys/param.h>
24#include <sys/systm.h>
25#include <sys/kernel.h>
26#include <sys/bus.h>
27#include <machine/bus.h>
28#include <sys/rman.h>
29#include <machine/resource.h>
30
31#include <dev/si/sireg.h>
32#include <dev/si/sivar.h>
33
34#include <dev/pci/pcivar.h>
35
36static int
37si_pci_probe(device_t dev)
38{
39 const char *desc = NULL;
40
41 switch (pci_get_devid(dev)) {
42 case 0x400011cb:
43 desc = "Specialix SI/XIO PCI host card";
44 break;
45 case 0x200011cb:
46 if (pci_read_config(dev, SIJETSSIDREG, 4) == 0x020011cb)
47 desc = "Specialix SX PCI host card";
48 break;
49 }
50 if (desc) {
51 device_set_desc(dev, desc);
52 return 0;
53 }
54 return ENXIO;
55}
56
57static int
58si_pci_attach(device_t dev)
59{
60 struct si_softc *sc;
61 void *ih;
62 int error;
63
64 error = 0;
65 ih = NULL;
66 sc = device_get_softc(dev);
67
68 switch (pci_get_devid(dev)) {
69 case 0x400011cb:
70 sc->sc_type = SIPCI;
71 sc->sc_mem_rid = SIPCIBADR;
72 break;
73 case 0x200011cb:
74 sc->sc_type = SIJETPCI;
75 sc->sc_mem_rid = SIJETBADR;
76 break;
77 }
78
79 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
80 &sc->sc_mem_rid,
81 0, ~0, 1, RF_ACTIVE);
82 if (!sc->sc_mem_res) {
83 device_printf(dev, "couldn't map memory\n");
84 goto fail;
85 }
86 sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
87 sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
88
89 sc->sc_irq_rid = 0;
90 sc->sc_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irq_rid,
91 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
92 if (!sc->sc_irq_res) {
93 device_printf(dev, "couldn't map interrupt\n");
94 goto fail;
95 }
96 sc->sc_irq = rman_get_start(sc->sc_irq_res);
97 error = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_TTY,
98 si_intr, sc, &ih);
99 if (error) {
100 device_printf(dev, "could not activate interrupt\n");
101 goto fail;
102 }
103
104 error = siattach(dev);
105 if (error)
106 goto fail;
107 return (0); /* success */
108
109fail:
110 if (error == 0)
111 error = ENXIO;
112 if (sc->sc_irq_res) {
113 if (ih)
114 bus_teardown_intr(dev, sc->sc_irq_res, ih);
115 bus_release_resource(dev, SYS_RES_IRQ,
116 sc->sc_irq_rid, sc->sc_irq_res);
117 sc->sc_irq_res = 0;
118 }
119 if (sc->sc_mem_res) {
120 bus_release_resource(dev, SYS_RES_MEMORY,
121 sc->sc_mem_rid, sc->sc_mem_res);
122 sc->sc_mem_res = 0;
123 }
124 return (error);
125}
126
127static device_method_t si_pci_methods[] = {
128 /* Device interface */
129 DEVMETHOD(device_probe, si_pci_probe),
130 DEVMETHOD(device_attach, si_pci_attach),
131
132 { 0, 0 }
133};
134
135static driver_t si_pci_driver = {
136 "si",
137 si_pci_methods,
138 sizeof(struct si_softc),
139};
140
141DRIVER_MODULE(si, pci, si_pci_driver, si_devclass, 0, 0);
24#include <sys/param.h>
25#include <sys/systm.h>
26#include <sys/kernel.h>
27#include <sys/bus.h>
28#include <machine/bus.h>
29#include <sys/rman.h>
30#include <machine/resource.h>
31
32#include <dev/si/sireg.h>
33#include <dev/si/sivar.h>
34
35#include <dev/pci/pcivar.h>
36
37static int
38si_pci_probe(device_t dev)
39{
40 const char *desc = NULL;
41
42 switch (pci_get_devid(dev)) {
43 case 0x400011cb:
44 desc = "Specialix SI/XIO PCI host card";
45 break;
46 case 0x200011cb:
47 if (pci_read_config(dev, SIJETSSIDREG, 4) == 0x020011cb)
48 desc = "Specialix SX PCI host card";
49 break;
50 }
51 if (desc) {
52 device_set_desc(dev, desc);
53 return 0;
54 }
55 return ENXIO;
56}
57
58static int
59si_pci_attach(device_t dev)
60{
61 struct si_softc *sc;
62 void *ih;
63 int error;
64
65 error = 0;
66 ih = NULL;
67 sc = device_get_softc(dev);
68
69 switch (pci_get_devid(dev)) {
70 case 0x400011cb:
71 sc->sc_type = SIPCI;
72 sc->sc_mem_rid = SIPCIBADR;
73 break;
74 case 0x200011cb:
75 sc->sc_type = SIJETPCI;
76 sc->sc_mem_rid = SIJETBADR;
77 break;
78 }
79
80 sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
81 &sc->sc_mem_rid,
82 0, ~0, 1, RF_ACTIVE);
83 if (!sc->sc_mem_res) {
84 device_printf(dev, "couldn't map memory\n");
85 goto fail;
86 }
87 sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
88 sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
89
90 sc->sc_irq_rid = 0;
91 sc->sc_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irq_rid,
92 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
93 if (!sc->sc_irq_res) {
94 device_printf(dev, "couldn't map interrupt\n");
95 goto fail;
96 }
97 sc->sc_irq = rman_get_start(sc->sc_irq_res);
98 error = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_TTY,
99 si_intr, sc, &ih);
100 if (error) {
101 device_printf(dev, "could not activate interrupt\n");
102 goto fail;
103 }
104
105 error = siattach(dev);
106 if (error)
107 goto fail;
108 return (0); /* success */
109
110fail:
111 if (error == 0)
112 error = ENXIO;
113 if (sc->sc_irq_res) {
114 if (ih)
115 bus_teardown_intr(dev, sc->sc_irq_res, ih);
116 bus_release_resource(dev, SYS_RES_IRQ,
117 sc->sc_irq_rid, sc->sc_irq_res);
118 sc->sc_irq_res = 0;
119 }
120 if (sc->sc_mem_res) {
121 bus_release_resource(dev, SYS_RES_MEMORY,
122 sc->sc_mem_rid, sc->sc_mem_res);
123 sc->sc_mem_res = 0;
124 }
125 return (error);
126}
127
128static device_method_t si_pci_methods[] = {
129 /* Device interface */
130 DEVMETHOD(device_probe, si_pci_probe),
131 DEVMETHOD(device_attach, si_pci_attach),
132
133 { 0, 0 }
134};
135
136static driver_t si_pci_driver = {
137 "si",
138 si_pci_methods,
139 sizeof(struct si_softc),
140};
141
142DRIVER_MODULE(si, pci, si_pci_driver, si_devclass, 0, 0);