Deleted Added
full compact
orm.c (112589) orm.c (116181)
1/*-
2 * Copyright (c) 2000 Nikolai Saoukh
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 AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
1/*-
2 * Copyright (c) 2000 Nikolai Saoukh
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 AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/isa/orm.c 112589 2003-03-25 04:34:33Z mdodd $
27 */
28
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/isa/orm.c 116181 2003-06-11 00:34:37Z obrien $");
29
29/*
30 * Driver to take care of holes in ISA I/O memory occupied
31 * by option rom(s)
32 */
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>
37#include <sys/socket.h>
38
39#include <sys/module.h>
40#include <sys/bus.h>
41
42#include <machine/bus.h>
43#include <machine/resource.h>
44#include <sys/rman.h>
45
46#include <isa/isavar.h>
47#include <isa/pnpvar.h>
48
49#define IOMEM_START 0x0a0000
50#define IOMEM_STEP 0x000800
51#define IOMEM_END 0x100000
52
53#define ORM_ID 0x00004d3e
54
55static struct isa_pnp_id orm_ids[] = {
56 { ORM_ID, NULL }, /* ORM0000 */
57 { 0, NULL },
58};
59
60#define MAX_ROMS 16
61
62struct orm_softc {
63 int rnum;
64 int rid[MAX_ROMS];
65 struct resource *res[MAX_ROMS];
66};
67
68static int
69orm_probe(device_t dev)
70{
71 return (ISA_PNP_PROBE(device_get_parent(dev), dev, orm_ids));
72}
73
74static int
75orm_attach(device_t dev)
76{
77 return (0);
78}
79
80static void
81orm_identify(driver_t* driver, device_t parent)
82{
83 bus_space_handle_t bh;
84 bus_space_tag_t bt;
85 device_t child;
86 u_int32_t chunk = IOMEM_START;
87 struct resource *res;
88 int rid;
89 u_int32_t rom_size;
90 struct orm_softc *sc;
91 u_int8_t buf[3];
92
93 child = BUS_ADD_CHILD(parent, ISA_ORDER_SENSITIVE, "orm", -1);
94 device_set_driver(child, driver);
95 isa_set_logicalid(child, ORM_ID);
96 isa_set_vendorid(child, ORM_ID);
97 sc = device_get_softc(child);
98 sc->rnum = 0;
99 while (chunk < IOMEM_END) {
100 bus_set_resource(child, SYS_RES_MEMORY, sc->rnum, chunk,
101 IOMEM_STEP);
102 rid = sc->rnum;
103 res = bus_alloc_resource(child, SYS_RES_MEMORY, &rid, 0ul,
104 ~0ul, 1, RF_ACTIVE);
105 if (res == NULL) {
106 bus_delete_resource(child, SYS_RES_MEMORY, sc->rnum);
107 chunk += IOMEM_STEP;
108 continue;
109 }
110 bt = rman_get_bustag(res);
111 bh = rman_get_bushandle(res);
112 bus_space_read_region_1(bt, bh, 0, buf, sizeof(buf));
113
114 /*
115 * We need to release and delete the resource since we're
116 * changing its size, or the rom isn't there. There
117 * is a checksum field in the ROM to prevent false
118 * positives. However, some common hardware (IBM thinkpads)
119 * neglects to put a valid checksum in the ROM, so we do
120 * not double check the checksum here. On the ISA bus
121 * areas that have no hardware read back as 0xff, so the
122 * tests to see if we have 0x55 followed by 0xaa are
123 * generally sufficient.
124 */
125 bus_release_resource(child, SYS_RES_MEMORY, rid, res);
126 bus_delete_resource(child, SYS_RES_MEMORY, sc->rnum);
127 if (buf[0] != 0x55 || buf[1] != 0xAA || (buf[2] & 0x03) != 0) {
128 chunk += IOMEM_STEP;
129 continue;
130 }
131 rom_size = buf[2] << 9;
132 bus_set_resource(child, SYS_RES_MEMORY, sc->rnum, chunk,
133 rom_size);
134 rid = sc->rnum;
135 res = bus_alloc_resource(child, SYS_RES_MEMORY, &rid, 0ul,
136 ~0ul, 1, 0);
137 if (res == NULL) {
138 bus_delete_resource(child, SYS_RES_MEMORY, sc->rnum);
139 chunk += IOMEM_STEP;
140 continue;
141 }
142 sc->rid[sc->rnum] = rid;
143 sc->res[sc->rnum] = res;
144 sc->rnum++;
145 chunk += rom_size;
146 }
147
148 if (sc->rnum == 0)
149 device_delete_child(parent, child);
150 else if (sc->rnum == 1)
151 device_set_desc(child, "Option ROM");
152 else
153 device_set_desc(child, "Option ROMs");
154}
155
156static int
157orm_detach(device_t dev)
158{
159 int i;
160 struct orm_softc *sc = device_get_softc(dev);
161
162 for (i = 0; i < sc->rnum; i++)
163 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid[i],
164 sc->res[i]);
165 return (0);
166}
167
168static device_method_t orm_methods[] = {
169 /* Device interface */
170 DEVMETHOD(device_identify, orm_identify),
171 DEVMETHOD(device_probe, orm_probe),
172 DEVMETHOD(device_attach, orm_attach),
173 DEVMETHOD(device_detach, orm_detach),
174 { 0, 0 }
175};
176
177static driver_t orm_driver = {
178 "orm",
179 orm_methods,
180 sizeof (struct orm_softc)
181};
182
183static devclass_t orm_devclass;
184
185DRIVER_MODULE(orm, isa, orm_driver, orm_devclass, 0, 0);
30/*
31 * Driver to take care of holes in ISA I/O memory occupied
32 * by option rom(s)
33 */
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/socket.h>
39
40#include <sys/module.h>
41#include <sys/bus.h>
42
43#include <machine/bus.h>
44#include <machine/resource.h>
45#include <sys/rman.h>
46
47#include <isa/isavar.h>
48#include <isa/pnpvar.h>
49
50#define IOMEM_START 0x0a0000
51#define IOMEM_STEP 0x000800
52#define IOMEM_END 0x100000
53
54#define ORM_ID 0x00004d3e
55
56static struct isa_pnp_id orm_ids[] = {
57 { ORM_ID, NULL }, /* ORM0000 */
58 { 0, NULL },
59};
60
61#define MAX_ROMS 16
62
63struct orm_softc {
64 int rnum;
65 int rid[MAX_ROMS];
66 struct resource *res[MAX_ROMS];
67};
68
69static int
70orm_probe(device_t dev)
71{
72 return (ISA_PNP_PROBE(device_get_parent(dev), dev, orm_ids));
73}
74
75static int
76orm_attach(device_t dev)
77{
78 return (0);
79}
80
81static void
82orm_identify(driver_t* driver, device_t parent)
83{
84 bus_space_handle_t bh;
85 bus_space_tag_t bt;
86 device_t child;
87 u_int32_t chunk = IOMEM_START;
88 struct resource *res;
89 int rid;
90 u_int32_t rom_size;
91 struct orm_softc *sc;
92 u_int8_t buf[3];
93
94 child = BUS_ADD_CHILD(parent, ISA_ORDER_SENSITIVE, "orm", -1);
95 device_set_driver(child, driver);
96 isa_set_logicalid(child, ORM_ID);
97 isa_set_vendorid(child, ORM_ID);
98 sc = device_get_softc(child);
99 sc->rnum = 0;
100 while (chunk < IOMEM_END) {
101 bus_set_resource(child, SYS_RES_MEMORY, sc->rnum, chunk,
102 IOMEM_STEP);
103 rid = sc->rnum;
104 res = bus_alloc_resource(child, SYS_RES_MEMORY, &rid, 0ul,
105 ~0ul, 1, RF_ACTIVE);
106 if (res == NULL) {
107 bus_delete_resource(child, SYS_RES_MEMORY, sc->rnum);
108 chunk += IOMEM_STEP;
109 continue;
110 }
111 bt = rman_get_bustag(res);
112 bh = rman_get_bushandle(res);
113 bus_space_read_region_1(bt, bh, 0, buf, sizeof(buf));
114
115 /*
116 * We need to release and delete the resource since we're
117 * changing its size, or the rom isn't there. There
118 * is a checksum field in the ROM to prevent false
119 * positives. However, some common hardware (IBM thinkpads)
120 * neglects to put a valid checksum in the ROM, so we do
121 * not double check the checksum here. On the ISA bus
122 * areas that have no hardware read back as 0xff, so the
123 * tests to see if we have 0x55 followed by 0xaa are
124 * generally sufficient.
125 */
126 bus_release_resource(child, SYS_RES_MEMORY, rid, res);
127 bus_delete_resource(child, SYS_RES_MEMORY, sc->rnum);
128 if (buf[0] != 0x55 || buf[1] != 0xAA || (buf[2] & 0x03) != 0) {
129 chunk += IOMEM_STEP;
130 continue;
131 }
132 rom_size = buf[2] << 9;
133 bus_set_resource(child, SYS_RES_MEMORY, sc->rnum, chunk,
134 rom_size);
135 rid = sc->rnum;
136 res = bus_alloc_resource(child, SYS_RES_MEMORY, &rid, 0ul,
137 ~0ul, 1, 0);
138 if (res == NULL) {
139 bus_delete_resource(child, SYS_RES_MEMORY, sc->rnum);
140 chunk += IOMEM_STEP;
141 continue;
142 }
143 sc->rid[sc->rnum] = rid;
144 sc->res[sc->rnum] = res;
145 sc->rnum++;
146 chunk += rom_size;
147 }
148
149 if (sc->rnum == 0)
150 device_delete_child(parent, child);
151 else if (sc->rnum == 1)
152 device_set_desc(child, "Option ROM");
153 else
154 device_set_desc(child, "Option ROMs");
155}
156
157static int
158orm_detach(device_t dev)
159{
160 int i;
161 struct orm_softc *sc = device_get_softc(dev);
162
163 for (i = 0; i < sc->rnum; i++)
164 bus_release_resource(dev, SYS_RES_MEMORY, sc->rid[i],
165 sc->res[i]);
166 return (0);
167}
168
169static device_method_t orm_methods[] = {
170 /* Device interface */
171 DEVMETHOD(device_identify, orm_identify),
172 DEVMETHOD(device_probe, orm_probe),
173 DEVMETHOD(device_attach, orm_attach),
174 DEVMETHOD(device_detach, orm_detach),
175 { 0, 0 }
176};
177
178static driver_t orm_driver = {
179 "orm",
180 orm_methods,
181 sizeof (struct orm_softc)
182};
183
184static devclass_t orm_devclass;
185
186DRIVER_MODULE(orm, isa, orm_driver, orm_devclass, 0, 0);