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
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.
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/module.h>
56 #include <sys/kernel.h>
57 #include <sys/sysctl.h>
58 #include <sys/queue.h>
59 #include <sys/types.h>
62 #include <machine/bus.h>
63 #include <machine/resource.h>
65 /* XXX Shouldn't reach into the MD code here */
67 #include <pc98/pc98/pc98.h>
69 #include <i386/isa/isa.h>
72 #include <pccard/cardinfo.h>
73 #include <pccard/slot.h>
75 #include <dev/pccard/pccardvar.h>
76 #include <net/ethernet.h>
80 devclass_t pccard_devclass;
82 #define PCCARD_NPORT 2
87 #define PCCARD_DEVINFO(d) (struct pccard_devinfo *) device_get_ivars(d)
89 SYSCTL_NODE(_machdep, OID_AUTO, pccard, CTLFLAG_RW, 0, "pccard");
92 static u_long mem_start = IOM_BEGIN;
93 static u_long mem_end = IOM_END;
95 static u_long mem_start = 0xd0000;
96 static u_long mem_end = 0xeffff;
99 SYSCTL_ULONG(_machdep_pccard, OID_AUTO, mem_start, CTLFLAG_RW,
101 SYSCTL_ULONG(_machdep_pccard, OID_AUTO, mem_end, CTLFLAG_RW,
104 #if __FreeBSD_version >= 500000
106 * glue for NEWCARD/OLDCARD compat layer
109 pccard_compat_do_probe(device_t bus, device_t dev)
111 return (CARD_COMPAT_PROBE(dev));
115 pccard_compat_do_attach(device_t bus, device_t dev)
117 return (CARD_COMPAT_ATTACH(dev));
122 pccard_probe(device_t dev)
124 device_set_desc(dev, "PC Card 16-bit bus (classic)");
129 pccard_attach(device_t dev)
135 pccard_print_resources(struct resource_list *rl, const char *name, int type,
136 int count, const char *format)
138 struct resource_list_entry *rle;
143 for (i = 0; i < count; i++) {
144 rle = resource_list_find(rl, type, i);
147 printf(" %s ", name);
148 else if (printed > 0)
151 printf(format, rle->start);
152 if (rle->count > 1) {
154 printf(format, rle->start + rle->count - 1);
157 /* check the first few regardless */
164 pccard_print_child(device_t dev, device_t child)
166 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
167 struct resource_list *rl = &devi->resources;
169 int flags = device_get_flags(child);
171 retval += bus_print_child_header(dev, child);
172 retval += printf(" at");
175 pccard_print_resources(rl, "port", SYS_RES_IOPORT,
176 PCCARD_NPORT, "%#lx");
177 pccard_print_resources(rl, "iomem", SYS_RES_MEMORY,
178 PCCARD_NMEM, "%#lx");
179 pccard_print_resources(rl, "irq", SYS_RES_IRQ, PCCARD_NIRQ,
181 pccard_print_resources(rl, "drq", SYS_RES_DRQ, PCCARD_NDRQ,
184 retval += printf(" flags 0x%x", flags);
185 retval += printf(" slot %d", devi->slt->slotnum);
188 retval += bus_print_child_footer(dev, child);
194 pccard_set_resource(device_t dev, device_t child, int type, int rid,
195 u_long start, u_long count)
197 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
198 struct resource_list *rl = &devi->resources;
200 if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY
201 && type != SYS_RES_IRQ && type != SYS_RES_DRQ)
205 if (type == SYS_RES_IOPORT && rid >= PCCARD_NPORT)
207 if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM)
209 if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ)
211 if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ)
214 resource_list_add(rl, type, rid, start, start + count - 1, count);
220 pccard_get_resource(device_t dev, device_t child, int type, int rid,
221 u_long *startp, u_long *countp)
223 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
224 struct resource_list *rl = &devi->resources;
225 struct resource_list_entry *rle;
227 rle = resource_list_find(rl, type, rid);
232 *startp = rle->start;
234 *countp = rle->count;
240 pccard_delete_resource(device_t dev, device_t child, int type, int rid)
242 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
243 struct resource_list *rl = &devi->resources;
244 resource_list_delete(rl, type, rid);
247 static struct resource *
248 pccard_alloc_resource(device_t bus, device_t child, int type, int *rid,
249 u_long start, u_long end, u_long count, u_int flags)
252 * Consider adding a resource definition. We allow rid 0 for
253 * irq, 0-4 for memory and 0-1 for ports
255 int passthrough = (device_get_parent(child) != bus);
257 struct pccard_devinfo *devi = device_get_ivars(child);
258 struct resource_list *rl = &devi->resources;
259 struct resource_list_entry *rle;
260 struct resource *res;
262 if (start == 0 && end == ~0 && type == SYS_RES_MEMORY && count != 1) {
266 isdefault = (start == 0UL && end == ~0UL);
267 if (!passthrough && !isdefault) {
268 rle = resource_list_find(rl, type, *rid);
274 if (*rid >= PCCARD_NIRQ)
278 if (*rid >= PCCARD_NDRQ)
282 if (*rid >= PCCARD_NMEM)
286 if (*rid >= PCCARD_NPORT)
292 resource_list_add(rl, type, *rid, start, end, count);
295 res = resource_list_alloc(rl, bus, child, type, rid, start, end,
301 pccard_release_resource(device_t bus, device_t child, int type, int rid,
304 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
305 struct resource_list *rl = &devi->resources;
306 return (resource_list_release(rl, bus, child, type, rid, r));
310 pccard_read_ivar(device_t bus, device_t child, int which, uintptr_t *result)
312 struct pccard_devinfo *devi = PCCARD_DEVINFO(child);
315 case PCCARD_IVAR_ETHADDR:
316 bcopy(devi->misc, result, ETHER_ADDR_LEN);
318 case PCCARD_IVAR_VENDOR:
319 *(u_int32_t *) result = devi->manufacturer;
321 case PCCARD_IVAR_PRODUCT:
322 *(u_int32_t *) result = devi->product;
324 case PCCARD_IVAR_PRODEXT:
325 *(u_int16_t *) result = devi->prodext;
327 case PCCARD_IVAR_VENDOR_STR:
328 *(char **) result = devi->manufstr;
330 case PCCARD_IVAR_PRODUCT_STR:
331 *(char **) result = devi->versstr;
333 case PCCARD_IVAR_CIS3_STR:
334 *(char **) result = devi->cis3str;
336 case PCCARD_IVAR_CIS4_STR:
337 *(char **) result = devi->cis4str;
344 pccard_set_res_flags(device_t bus, device_t child, int restype, int rid,
347 return (CARD_SET_RES_FLAGS(device_get_parent(bus), child, restype,
352 pccard_get_res_flags(device_t bus, device_t child, int restype, int rid,
355 return (CARD_GET_RES_FLAGS(device_get_parent(bus), child, restype,
360 pccard_set_memory_offset(device_t bus, device_t child, int rid,
362 #if __FreeBSD_version >= 500000
367 return (CARD_SET_MEMORY_OFFSET(device_get_parent(bus), child, rid,
369 #if __FreeBSD_version >= 500000
376 pccard_get_memory_offset(device_t bus, device_t child, int rid,
379 return (CARD_GET_MEMORY_OFFSET(device_get_parent(bus), child, rid,
383 #if __FreeBSD_version >= 500000
385 pccard_get_function_num(device_t bus, device_t child, int *function)
392 pccard_activate_function(device_t bus, device_t child)
394 /* pccardd has alrady activated the function */
399 pccard_deactivate_function(device_t bus, device_t child)
401 /* pccardd will deactivate the function */
405 static const struct pccard_product *
406 pccard_do_product_lookup(device_t bus, device_t dev,
407 const struct pccard_product *tab,
408 size_t ent_size, pccard_product_match_fn matchfn)
414 static device_method_t pccard_methods[] = {
415 /* Device interface */
416 DEVMETHOD(device_probe, pccard_probe),
417 DEVMETHOD(device_attach, pccard_attach),
418 DEVMETHOD(device_shutdown, bus_generic_shutdown),
419 DEVMETHOD(device_suspend, pccard_suspend),
420 DEVMETHOD(device_resume, pccard_resume),
423 DEVMETHOD(bus_print_child, pccard_print_child),
424 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
425 DEVMETHOD(bus_alloc_resource, pccard_alloc_resource),
426 DEVMETHOD(bus_release_resource, pccard_release_resource),
427 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
428 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
429 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
430 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
431 DEVMETHOD(bus_set_resource, pccard_set_resource),
432 DEVMETHOD(bus_get_resource, pccard_get_resource),
433 DEVMETHOD(bus_delete_resource, pccard_delete_resource),
434 DEVMETHOD(bus_read_ivar, pccard_read_ivar),
437 DEVMETHOD(card_set_res_flags, pccard_set_res_flags),
438 DEVMETHOD(card_get_res_flags, pccard_get_res_flags),
439 DEVMETHOD(card_set_memory_offset, pccard_set_memory_offset),
440 DEVMETHOD(card_get_memory_offset, pccard_get_memory_offset),
441 #if __FreeBSD_version >= 500000
442 DEVMETHOD(card_get_function, pccard_get_function_num),
443 DEVMETHOD(card_activate_function, pccard_activate_function),
444 DEVMETHOD(card_deactivate_function, pccard_deactivate_function),
445 DEVMETHOD(card_compat_do_probe, pccard_compat_do_probe),
446 DEVMETHOD(card_compat_do_attach, pccard_compat_do_attach),
447 DEVMETHOD(card_do_product_lookup, pccard_do_product_lookup),
452 static driver_t pccard_driver = {
458 DRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0);
459 DRIVER_MODULE(pccard, mecia, pccard_driver, pccard_devclass, 0, 0);
460 MODULE_VERSION(pccard, 1);