2 * Copyright (c) 1999, 2001 M. Warner Losh. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * $FreeBSD: src/sys/pccard/pccard_nbk.c,v 1.15.2.11 2002/09/22 20:26:58 imp Exp $
29 * This file contains various kludges to allow the legacy pccard system to
30 * work in the newbus system until the pccard system can be converted
31 * wholesale to newbus. As that is a while off, I'm providing this glue to
32 * allow newbus drivers to have pccard attachments.
34 * We do *NOT* implement ISA ivars at all. We are not an isa bus, and drivers
35 * that abuse isa_{set,get}_* must be fixed in order to work with pccard.
36 * We use ivars for something else anyway, so it becomes fairly awkward
39 * Here's a summary of the glue that we do to make things work.
41 * First, we have pccard node in the device and driver trees. The pccard
42 * device lives in the instance tree attached to the nexus. The pccard
43 * attachments will be attached to that node. This allows one to pass things
44 * up the tree that terminates at the nexus, like other buses. The pccard
45 * code will create a device instance for each of the drivers that are to
48 * These compatibility nodes are called pccnbk. PCCard New Bus Kludge.
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/module.h>
54 #include <sys/kernel.h>
55 #include <sys/sysctl.h>
56 #include <sys/queue.h>
57 #include <sys/types.h>
60 #include <machine/bus.h>
61 #include <machine/resource.h>
63 /* XXX Shouldn't reach into the MD code here */
65 #include <pc98/pc98/pc98.h>
67 #include <i386/isa/isa.h>
70 #include <pccard/cardinfo.h>
71 #include <pccard/slot.h>
73 #include <dev/pccard/pccardvar.h>
74 #include <net/ethernet.h>
78 devclass_t pccard_devclass;
80 #define PCCARD_NPORT 2
85 #define PCCARD_DEVINFO(d) (struct pccard_devinfo *) device_get_ivars(d)
87 SYSCTL_NODE(_machdep, OID_AUTO, pccard, CTLFLAG_RW, 0, "pccard");
90 static u_long mem_start = IOM_BEGIN;
91 static u_long mem_end = IOM_END;
93 static u_long mem_start = 0xd0000;
94 static u_long mem_end = 0xeffff;
97 SYSCTL_ULONG(_machdep_pccard, OID_AUTO, mem_start, CTLFLAG_RW,
99 SYSCTL_ULONG(_machdep_pccard, OID_AUTO, mem_end, CTLFLAG_RW,
102 #if __FreeBSD_version >= 500000
104 * glue for NEWCARD/OLDCARD compat layer
107 pccard_compat_do_probe(device_t bus, device_t dev)
109 return (CARD_COMPAT_PROBE(dev));
113 pccard_compat_do_attach(device_t bus, device_t dev)
115 return (CARD_COMPAT_ATTACH(dev));
120 pccard_probe(device_t dev)
122 device_set_desc(dev, "PC Card 16-bit bus (classic)");
127 pccard_attach(device_t dev)
133 pccard_print_resources(struct resource_list *rl, const char *name, int type,
134 int count, const char *format)
136 struct resource_list_entry *rle;
141 for (i = 0; i < count; i++) {
142 rle = resource_list_find(rl, type, i);
145 printf(" %s ", name);
146 else if (printed > 0)
149 printf(format, rle->start);
150 if (rle->count > 1) {
152 printf(format, rle->start + rle->count - 1);
155 /* check the first few regardless */
162 pccard_print_child(device_t dev, device_t child)
164 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
165 struct resource_list *rl = &devi->resources;
167 int flags = device_get_flags(child);
169 retval += bus_print_child_header(dev, child);
170 retval += printf(" at");
173 pccard_print_resources(rl, "port", SYS_RES_IOPORT,
174 PCCARD_NPORT, "%#lx");
175 pccard_print_resources(rl, "iomem", SYS_RES_MEMORY,
176 PCCARD_NMEM, "%#lx");
177 pccard_print_resources(rl, "irq", SYS_RES_IRQ, PCCARD_NIRQ,
179 pccard_print_resources(rl, "drq", SYS_RES_DRQ, PCCARD_NDRQ,
182 retval += printf(" flags 0x%x", flags);
183 retval += printf(" slot %d", devi->slt->slotnum);
186 retval += bus_print_child_footer(dev, child);
192 pccard_set_resource(device_t dev, device_t child, int type, int rid,
193 u_long start, u_long count)
195 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
196 struct resource_list *rl = &devi->resources;
198 if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY
199 && type != SYS_RES_IRQ && type != SYS_RES_DRQ)
203 if (type == SYS_RES_IOPORT && rid >= PCCARD_NPORT)
205 if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM)
207 if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ)
209 if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ)
212 resource_list_add(rl, type, rid, start, start + count - 1, count);
218 pccard_get_resource(device_t dev, device_t child, int type, int rid,
219 u_long *startp, u_long *countp)
221 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
222 struct resource_list *rl = &devi->resources;
223 struct resource_list_entry *rle;
225 rle = resource_list_find(rl, type, rid);
230 *startp = rle->start;
232 *countp = rle->count;
238 pccard_delete_resource(device_t dev, device_t child, int type, int rid)
240 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
241 struct resource_list *rl = &devi->resources;
242 resource_list_delete(rl, type, rid);
245 static struct resource *
246 pccard_alloc_resource(device_t bus, device_t child, int type, int *rid,
247 u_long start, u_long end, u_long count, u_int flags)
250 * Consider adding a resource definition. We allow rid 0 for
251 * irq, 0-4 for memory and 0-1 for ports
253 int passthrough = (device_get_parent(child) != bus);
255 struct pccard_devinfo *devi = device_get_ivars(child);
256 struct resource_list *rl = &devi->resources;
257 struct resource_list_entry *rle;
258 struct resource *res;
260 if (start == 0 && end == ~0 && type == SYS_RES_MEMORY && count != 1) {
264 isdefault = (start == 0UL && end == ~0UL);
265 if (!passthrough && !isdefault) {
266 rle = resource_list_find(rl, type, *rid);
272 if (*rid >= PCCARD_NIRQ)
276 if (*rid >= PCCARD_NDRQ)
280 if (*rid >= PCCARD_NMEM)
284 if (*rid >= PCCARD_NPORT)
290 resource_list_add(rl, type, *rid, start, end, count);
293 res = resource_list_alloc(rl, bus, child, type, rid, start, end,
299 pccard_release_resource(device_t bus, device_t child, int type, int rid,
302 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
303 struct resource_list *rl = &devi->resources;
304 return (resource_list_release(rl, bus, child, type, rid, r));
308 pccard_read_ivar(device_t bus, device_t child, int which, uintptr_t *result)
310 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
313 case PCCARD_IVAR_ETHADDR:
314 bcopy(devi->misc, result, ETHER_ADDR_LEN);
316 case PCCARD_IVAR_VENDOR:
317 *(u_int32_t *) result = devi->manufacturer;
319 case PCCARD_IVAR_PRODUCT:
320 *(u_int32_t *) result = devi->product;
322 case PCCARD_IVAR_PRODEXT:
323 *(u_int16_t *) result = devi->prodext;
330 pccard_set_res_flags(device_t bus, device_t child, int restype, int rid,
333 return (CARD_SET_RES_FLAGS(device_get_parent(bus), child, restype,
338 pccard_get_res_flags(device_t bus, device_t child, int restype, int rid,
341 return (CARD_GET_RES_FLAGS(device_get_parent(bus), child, restype,
346 pccard_set_memory_offset(device_t bus, device_t child, int rid,
348 #if __FreeBSD_version >= 500000
353 return (CARD_SET_MEMORY_OFFSET(device_get_parent(bus), child, rid,
355 #if __FreeBSD_version >= 500000
362 pccard_get_memory_offset(device_t bus, device_t child, int rid,
365 return (CARD_GET_MEMORY_OFFSET(device_get_parent(bus), child, rid,
369 #if __FreeBSD_version >= 500000
371 pccard_get_function_num(device_t bus, device_t child, int *function)
378 pccard_activate_function(device_t bus, device_t child)
380 /* pccardd has alrady activated the function */
385 pccard_deactivate_function(device_t bus, device_t child)
387 /* pccardd will deactivate the function */
391 static const struct pccard_product *
392 pccard_do_product_lookup(device_t bus, device_t dev,
393 const struct pccard_product *tab,
394 size_t ent_size, pccard_product_match_fn matchfn)
400 static device_method_t pccard_methods[] = {
401 /* Device interface */
402 DEVMETHOD(device_probe, pccard_probe),
403 DEVMETHOD(device_attach, pccard_attach),
404 DEVMETHOD(device_shutdown, bus_generic_shutdown),
405 DEVMETHOD(device_suspend, pccard_suspend),
406 DEVMETHOD(device_resume, pccard_resume),
409 DEVMETHOD(bus_print_child, pccard_print_child),
410 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
411 DEVMETHOD(bus_alloc_resource, pccard_alloc_resource),
412 DEVMETHOD(bus_release_resource, pccard_release_resource),
413 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
414 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
415 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
416 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
417 DEVMETHOD(bus_set_resource, pccard_set_resource),
418 DEVMETHOD(bus_get_resource, pccard_get_resource),
419 DEVMETHOD(bus_delete_resource, pccard_delete_resource),
420 DEVMETHOD(bus_read_ivar, pccard_read_ivar),
423 DEVMETHOD(card_set_res_flags, pccard_set_res_flags),
424 DEVMETHOD(card_get_res_flags, pccard_get_res_flags),
425 DEVMETHOD(card_set_memory_offset, pccard_set_memory_offset),
426 DEVMETHOD(card_get_memory_offset, pccard_get_memory_offset),
427 #if __FreeBSD_version >= 500000
428 DEVMETHOD(card_get_function, pccard_get_function_num),
429 DEVMETHOD(card_activate_function, pccard_activate_function),
430 DEVMETHOD(card_deactivate_function, pccard_deactivate_function),
431 DEVMETHOD(card_compat_do_probe, pccard_compat_do_probe),
432 DEVMETHOD(card_compat_do_attach, pccard_compat_do_attach),
433 DEVMETHOD(card_do_product_lookup, pccard_do_product_lookup),
438 static driver_t pccard_driver = {
444 DRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0);
445 DRIVER_MODULE(pccard, mecia, pccard_driver, pccard_devclass, 0, 0);
446 MODULE_VERSION(pccard, 1);