Home | History | Annotate | Line # | Download | only in dev
gayle_pcmcia.c revision 1.10.4.3
      1  1.10.4.3  nathanw /*	$NetBSD: gayle_pcmcia.c,v 1.10.4.3 2002/10/18 02:34:52 nathanw Exp $ */
      2  1.10.4.2  nathanw 
      3  1.10.4.2  nathanw /* public domain */
      4  1.10.4.2  nathanw 
      5  1.10.4.2  nathanw #include <sys/cdefs.h>
      6  1.10.4.3  nathanw __KERNEL_RCSID(0, "$NetBSD: gayle_pcmcia.c,v 1.10.4.3 2002/10/18 02:34:52 nathanw Exp $");
      7  1.10.4.2  nathanw 
      8  1.10.4.2  nathanw /* PCMCIA front-end driver for A1200's and A600's. */
      9  1.10.4.2  nathanw 
     10  1.10.4.2  nathanw #include <sys/param.h>
     11  1.10.4.2  nathanw #include <sys/device.h>
     12  1.10.4.2  nathanw #include <sys/kernel.h>
     13  1.10.4.2  nathanw #include <sys/kthread.h>
     14  1.10.4.2  nathanw #include <sys/systm.h>
     15  1.10.4.2  nathanw 
     16  1.10.4.2  nathanw #include <uvm/uvm.h>
     17  1.10.4.2  nathanw 
     18  1.10.4.2  nathanw #include <dev/pcmcia/pcmciareg.h>
     19  1.10.4.2  nathanw #include <dev/pcmcia/pcmciavar.h>
     20  1.10.4.2  nathanw 
     21  1.10.4.2  nathanw #include <machine/cpu.h>
     22  1.10.4.2  nathanw #include <amiga/amiga/custom.h>
     23  1.10.4.2  nathanw #include <amiga/amiga/device.h>
     24  1.10.4.2  nathanw #include <amiga/amiga/gayle.h>
     25  1.10.4.2  nathanw #include <amiga/amiga/isr.h>
     26  1.10.4.2  nathanw 
     27  1.10.4.2  nathanw 
     28  1.10.4.2  nathanw /* There is one of these for each slot. And yes, there is only one slot. */
     29  1.10.4.2  nathanw struct pccard_slot {
     30  1.10.4.2  nathanw 	struct	pccard_softc *sc;	/* refer to `parent' */
     31  1.10.4.2  nathanw 	int	(*intr_func)(void *);
     32  1.10.4.2  nathanw 	void *	intr_arg;
     33  1.10.4.2  nathanw 	struct	device *card;
     34  1.10.4.2  nathanw 	int	flags;
     35  1.10.4.2  nathanw #define SLOT_OCCUPIED		0x01
     36  1.10.4.2  nathanw #define SLOT_NEW_CARD_EVENT	0x02
     37  1.10.4.2  nathanw };
     38  1.10.4.2  nathanw 
     39  1.10.4.2  nathanw struct pccard_softc {
     40  1.10.4.2  nathanw 	struct device sc_dev;
     41  1.10.4.2  nathanw 	struct bus_space_tag io_space;
     42  1.10.4.2  nathanw 	struct bus_space_tag attr_space;
     43  1.10.4.2  nathanw 	struct bus_space_tag mem_space;
     44  1.10.4.2  nathanw 	struct pccard_slot devs[1];
     45  1.10.4.2  nathanw 	struct isr intr6;
     46  1.10.4.2  nathanw 	struct isr intr2;
     47  1.10.4.2  nathanw };
     48  1.10.4.2  nathanw 
     49  1.10.4.2  nathanw static int	pccard_probe(struct device *, struct cfdata *, void *);
     50  1.10.4.2  nathanw static void	pccard_attach(struct device *, struct device *, void *);
     51  1.10.4.2  nathanw static void	pccard_attach_slot(struct pccard_slot *);
     52  1.10.4.2  nathanw static int	pccard_intr6(void *);
     53  1.10.4.2  nathanw static int	pccard_intr2(void *);
     54  1.10.4.2  nathanw static void	pccard_create_kthread(void *);
     55  1.10.4.2  nathanw static void	pccard_kthread(void *);
     56  1.10.4.2  nathanw 
     57  1.10.4.2  nathanw static int pcf_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
     58  1.10.4.2  nathanw 		struct pcmcia_mem_handle *);
     59  1.10.4.2  nathanw static void pcf_mem_free(pcmcia_chipset_handle_t, struct pcmcia_mem_handle *);
     60  1.10.4.2  nathanw static int pcf_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t,
     61  1.10.4.2  nathanw 		struct pcmcia_mem_handle *, bus_addr_t *, int *);
     62  1.10.4.2  nathanw static void pcf_mem_unmap(pcmcia_chipset_handle_t, int);
     63  1.10.4.2  nathanw static int pcf_io_alloc(pcmcia_chipset_handle_t, bus_addr_t, bus_size_t,
     64  1.10.4.2  nathanw 		bus_size_t, struct pcmcia_io_handle *);
     65  1.10.4.2  nathanw static void pcf_io_free(pcmcia_chipset_handle_t, struct pcmcia_io_handle *);
     66  1.10.4.2  nathanw static int pcf_io_map(pcmcia_chipset_handle_t, int, bus_addr_t, bus_size_t,
     67  1.10.4.2  nathanw 		struct pcmcia_io_handle *, int *);
     68  1.10.4.2  nathanw static void pcf_io_unmap(pcmcia_chipset_handle_t, int);
     69  1.10.4.2  nathanw static void *pcf_intr_establish(pcmcia_chipset_handle_t,
     70  1.10.4.2  nathanw 		struct pcmcia_function *, int, int (*)(void *), void *);
     71  1.10.4.2  nathanw static void pcf_intr_disestablish(pcmcia_chipset_handle_t, void *);
     72  1.10.4.2  nathanw static void pcf_socket_enable(pcmcia_chipset_handle_t);
     73  1.10.4.2  nathanw static void pcf_socket_disable(pcmcia_chipset_handle_t);
     74  1.10.4.2  nathanw 
     75  1.10.4.2  nathanw static bsr(pcmio_bsr1, u_int8_t);
     76  1.10.4.2  nathanw static bsw(pcmio_bsw1, u_int8_t);
     77  1.10.4.2  nathanw static bsrm(pcmio_bsrm1, u_int8_t);
     78  1.10.4.2  nathanw static bswm(pcmio_bswm1, u_int8_t);
     79  1.10.4.2  nathanw static bsrm(pcmio_bsrr1, u_int8_t);
     80  1.10.4.2  nathanw static bswm(pcmio_bswr1, u_int8_t);
     81  1.10.4.2  nathanw static bssr(pcmio_bssr1, u_int8_t);
     82  1.10.4.2  nathanw static bscr(pcmio_bscr1, u_int8_t);
     83  1.10.4.2  nathanw 
     84  1.10.4.3  nathanw CFATTACH_DECL(pccard, sizeof(struct pccard_softc),
     85  1.10.4.3  nathanw     pccard_probe, pccard_attach, NULL, NULL);
     86  1.10.4.2  nathanw 
     87  1.10.4.2  nathanw struct pcmcia_chip_functions chip_functions = {
     88  1.10.4.2  nathanw 	pcf_mem_alloc,		pcf_mem_free,
     89  1.10.4.2  nathanw 	pcf_mem_map,		pcf_mem_unmap,
     90  1.10.4.2  nathanw 	pcf_io_alloc,		pcf_io_free,
     91  1.10.4.2  nathanw 	pcf_io_map,		pcf_io_unmap,
     92  1.10.4.2  nathanw 	pcf_intr_establish,	pcf_intr_disestablish,
     93  1.10.4.2  nathanw 	pcf_socket_enable,	pcf_socket_disable
     94  1.10.4.2  nathanw };
     95  1.10.4.2  nathanw 
     96  1.10.4.2  nathanw struct amiga_bus_space_methods pcmio_bs_methods;
     97  1.10.4.2  nathanw 
     98  1.10.4.2  nathanw static u_int8_t *reset_card_reg;
     99  1.10.4.2  nathanw 
    100  1.10.4.2  nathanw static int
    101  1.10.4.2  nathanw pccard_probe(struct device *dev, struct cfdata *cfd, void *aux)
    102  1.10.4.2  nathanw {
    103  1.10.4.2  nathanw 
    104  1.10.4.2  nathanw 	return (/*is_a600() || */is_a1200()) && matchname(aux, "pccard");
    105  1.10.4.2  nathanw }
    106  1.10.4.2  nathanw 
    107  1.10.4.2  nathanw static void
    108  1.10.4.2  nathanw pccard_attach(struct device *parent, struct device *myself, void *aux)
    109  1.10.4.2  nathanw {
    110  1.10.4.2  nathanw 	struct pccard_softc *self = (struct pccard_softc *) myself;
    111  1.10.4.2  nathanw 	struct pcmciabus_attach_args paa;
    112  1.10.4.2  nathanw 	vaddr_t pcmcia_base = GAYLE_PCMCIA_START;
    113  1.10.4.2  nathanw 	vaddr_t i;
    114  1.10.4.2  nathanw 	int ret;
    115  1.10.4.2  nathanw 
    116  1.10.4.2  nathanw 	printf("\n");
    117  1.10.4.2  nathanw 
    118  1.10.4.2  nathanw 	gayle_init();
    119  1.10.4.2  nathanw 
    120  1.10.4.2  nathanw 	ret = uvm_map(kernel_map, &pcmcia_base,
    121  1.10.4.2  nathanw 		GAYLE_PCMCIA_END - GAYLE_PCMCIA_START, NULL,
    122  1.10.4.2  nathanw 		UVM_UNKNOWN_OFFSET, 0,
    123  1.10.4.2  nathanw 		UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE,
    124  1.10.4.2  nathanw 		UVM_INH_NONE, UVM_ADV_RANDOM, 0));
    125  1.10.4.2  nathanw 	if (ret != 0) {
    126  1.10.4.2  nathanw 		printf("attach failed (no virtual memory)\n");
    127  1.10.4.2  nathanw 		return;
    128  1.10.4.2  nathanw 	}
    129  1.10.4.2  nathanw 
    130  1.10.4.2  nathanw 	for (i = GAYLE_PCMCIA_START; i < GAYLE_PCMCIA_END; i += PAGE_SIZE)
    131  1.10.4.2  nathanw 		pmap_enter(kernel_map->pmap,
    132  1.10.4.2  nathanw 		    i - GAYLE_PCMCIA_START + pcmcia_base, i,
    133  1.10.4.2  nathanw 		    VM_PROT_READ | VM_PROT_WRITE, TRUE);
    134  1.10.4.2  nathanw 	pmap_update(kernel_map->pmap);
    135  1.10.4.2  nathanw 
    136  1.10.4.2  nathanw 	/* override the one-byte access methods for I/O space */
    137  1.10.4.2  nathanw 	pcmio_bs_methods = amiga_bus_stride_1;
    138  1.10.4.2  nathanw 	pcmio_bs_methods.bsr1 = pcmio_bsr1;
    139  1.10.4.2  nathanw 	pcmio_bs_methods.bsw1 = pcmio_bsw1;
    140  1.10.4.2  nathanw 	pcmio_bs_methods.bsrm1 = pcmio_bsrm1;
    141  1.10.4.2  nathanw 	pcmio_bs_methods.bswm1 = pcmio_bswm1;
    142  1.10.4.2  nathanw 	pcmio_bs_methods.bsrr1 = pcmio_bsrr1;
    143  1.10.4.2  nathanw 	pcmio_bs_methods.bswr1 = pcmio_bswr1;
    144  1.10.4.2  nathanw 	pcmio_bs_methods.bssr1 = pcmio_bssr1;
    145  1.10.4.2  nathanw 	pcmio_bs_methods.bscr1 = pcmio_bscr1;
    146  1.10.4.2  nathanw 
    147  1.10.4.2  nathanw 	reset_card_reg = (u_int8_t *) pcmcia_base - GAYLE_PCMCIA_START +
    148  1.10.4.2  nathanw 	    GAYLE_PCMCIA_RESET;
    149  1.10.4.2  nathanw 
    150  1.10.4.2  nathanw 	self->io_space.base = (u_int) pcmcia_base - GAYLE_PCMCIA_START +
    151  1.10.4.2  nathanw 	    GAYLE_PCMCIA_IO_START;
    152  1.10.4.2  nathanw 	self->io_space.absm = &pcmio_bs_methods;
    153  1.10.4.2  nathanw 
    154  1.10.4.2  nathanw 	self->attr_space.base = (u_int) pcmcia_base - GAYLE_PCMCIA_START +
    155  1.10.4.2  nathanw 	    GAYLE_PCMCIA_ATTR_START;
    156  1.10.4.2  nathanw 	self->attr_space.absm = &amiga_bus_stride_1;
    157  1.10.4.2  nathanw 
    158  1.10.4.2  nathanw 	/* XXX we should check if the 4M of common memory are actually
    159  1.10.4.2  nathanw 	 *	RAM or PCMCIA usable.
    160  1.10.4.2  nathanw 	 * For now, we just do as if the 4M were RAM and make common memory
    161  1.10.4.2  nathanw 	 * point to attribute memory, which is OK for some I/O cards.
    162  1.10.4.2  nathanw 	 */
    163  1.10.4.2  nathanw 	self->mem_space.base = (u_int) pcmcia_base;
    164  1.10.4.2  nathanw 	self->mem_space.absm = &amiga_bus_stride_1;
    165  1.10.4.2  nathanw 
    166  1.10.4.2  nathanw 	self->devs[0].sc = self;
    167  1.10.4.2  nathanw 	self->devs[0].intr_func = NULL;
    168  1.10.4.2  nathanw 	self->devs[0].intr_arg = NULL;
    169  1.10.4.2  nathanw 	self->devs[0].flags = 0;
    170  1.10.4.2  nathanw 
    171  1.10.4.2  nathanw 	gayle.pcc_status = 0;
    172  1.10.4.2  nathanw 	gayle.intreq = 0;
    173  1.10.4.2  nathanw 	gayle.pcc_config = 0;
    174  1.10.4.2  nathanw 	gayle.intena &= GAYLE_INT_IDE;
    175  1.10.4.2  nathanw 
    176  1.10.4.2  nathanw 	paa.paa_busname = "pcmcia";
    177  1.10.4.2  nathanw 	paa.pct = &chip_functions;
    178  1.10.4.2  nathanw 	paa.pch = &self->devs[0];
    179  1.10.4.2  nathanw 	paa.iobase = 0;
    180  1.10.4.2  nathanw 	paa.iosize = 0;
    181  1.10.4.2  nathanw 	self->devs[0].card =
    182  1.10.4.2  nathanw 		config_found_sm(myself, &paa, simple_devprint, NULL);
    183  1.10.4.2  nathanw 	if (self->devs[0].card == NULL) {
    184  1.10.4.2  nathanw 		printf("attach failed, config_found_sm() returned NULL\n");
    185  1.10.4.2  nathanw 		return;
    186  1.10.4.2  nathanw 	}
    187  1.10.4.2  nathanw 
    188  1.10.4.2  nathanw 	self->intr6.isr_intr = pccard_intr6;
    189  1.10.4.2  nathanw 	self->intr6.isr_arg = self;
    190  1.10.4.2  nathanw 	self->intr6.isr_ipl = 6;
    191  1.10.4.2  nathanw 	add_isr(&self->intr6);
    192  1.10.4.2  nathanw 
    193  1.10.4.2  nathanw 	self->intr2.isr_intr = pccard_intr2;
    194  1.10.4.2  nathanw 	self->intr2.isr_arg = self;
    195  1.10.4.2  nathanw 	self->intr2.isr_ipl = 2;
    196  1.10.4.2  nathanw 	add_isr(&self->intr2);
    197  1.10.4.2  nathanw 
    198  1.10.4.2  nathanw 	kthread_create(pccard_create_kthread, self);
    199  1.10.4.2  nathanw 
    200  1.10.4.2  nathanw 	gayle.intena |= GAYLE_INT_DETECT | GAYLE_INT_IREQ;
    201  1.10.4.2  nathanw 
    202  1.10.4.2  nathanw 	/* reset the card if it's already there */
    203  1.10.4.2  nathanw 	if (gayle.pcc_status & GAYLE_CCMEM_DETECT) {
    204  1.10.4.2  nathanw 		volatile u_int8_t x;
    205  1.10.4.2  nathanw 		*reset_card_reg = 0x0;
    206  1.10.4.2  nathanw 		delay(1000);
    207  1.10.4.2  nathanw 		x = *reset_card_reg;
    208  1.10.4.2  nathanw 		gayle.pcc_status = GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR;
    209  1.10.4.2  nathanw 	}
    210  1.10.4.2  nathanw 
    211  1.10.4.2  nathanw 	pccard_attach_slot(&self->devs[0]);
    212  1.10.4.2  nathanw }
    213  1.10.4.2  nathanw 
    214  1.10.4.2  nathanw /* This is called as soon as it is possible to create a kernel thread */
    215  1.10.4.2  nathanw static void
    216  1.10.4.2  nathanw pccard_create_kthread(void *arg)
    217  1.10.4.2  nathanw {
    218  1.10.4.2  nathanw 	struct pccard_softc *self = arg;
    219  1.10.4.2  nathanw 
    220  1.10.4.2  nathanw 	if (kthread_create1(pccard_kthread, self, NULL, "pccard thread")) {
    221  1.10.4.2  nathanw 		printf("%s: can't create kernel thread\n",
    222  1.10.4.2  nathanw 			self->sc_dev.dv_xname);
    223  1.10.4.2  nathanw 		panic("pccard kthread_create() failed");
    224  1.10.4.2  nathanw 	}
    225  1.10.4.2  nathanw }
    226  1.10.4.2  nathanw 
    227  1.10.4.2  nathanw static int
    228  1.10.4.2  nathanw pccard_intr6(void *arg)
    229  1.10.4.2  nathanw {
    230  1.10.4.2  nathanw 	struct pccard_softc *self = arg;
    231  1.10.4.2  nathanw 
    232  1.10.4.2  nathanw 	if (gayle.intreq & GAYLE_INT_DETECT) {
    233  1.10.4.2  nathanw 		gayle.intreq = GAYLE_INT_IDE | GAYLE_INT_STSCHG |
    234  1.10.4.2  nathanw 		    GAYLE_INT_SPKR | GAYLE_INT_WP | GAYLE_INT_IREQ;
    235  1.10.4.2  nathanw 		self->devs[0].flags |= SLOT_NEW_CARD_EVENT;
    236  1.10.4.2  nathanw 		return 1;
    237  1.10.4.2  nathanw 	}
    238  1.10.4.2  nathanw 	return 0;
    239  1.10.4.2  nathanw }
    240  1.10.4.2  nathanw 
    241  1.10.4.2  nathanw static int
    242  1.10.4.2  nathanw pccard_intr2(void *arg)
    243  1.10.4.2  nathanw {
    244  1.10.4.2  nathanw 	struct pccard_softc *self = arg;
    245  1.10.4.2  nathanw 	struct pccard_slot *slot = &self->devs[0];
    246  1.10.4.2  nathanw 
    247  1.10.4.2  nathanw 	if (slot->flags & SLOT_NEW_CARD_EVENT) {
    248  1.10.4.2  nathanw 		slot->flags &= ~SLOT_NEW_CARD_EVENT;
    249  1.10.4.2  nathanw 
    250  1.10.4.2  nathanw 		/* reset the registers */
    251  1.10.4.2  nathanw 		gayle.intreq = GAYLE_INT_IDE | GAYLE_INT_DETECT;
    252  1.10.4.2  nathanw 		gayle.pcc_status = GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR;
    253  1.10.4.2  nathanw 		gayle.pcc_config = 0;
    254  1.10.4.2  nathanw 		pccard_attach_slot(&self->devs[0]);
    255  1.10.4.2  nathanw 	} else {
    256  1.10.4.2  nathanw 		int intreq = gayle.intreq &
    257  1.10.4.2  nathanw 		    (GAYLE_INT_STSCHG | GAYLE_INT_WP | GAYLE_INT_IREQ);
    258  1.10.4.2  nathanw 		if (intreq) {
    259  1.10.4.2  nathanw 			gayle.intreq = (intreq ^ 0x2c) | 0xc0;
    260  1.10.4.2  nathanw 
    261  1.10.4.2  nathanw 			return slot->flags & SLOT_OCCUPIED &&
    262  1.10.4.2  nathanw 		   		slot->intr_func != NULL &&
    263  1.10.4.2  nathanw 				slot->intr_func(slot->intr_arg);
    264  1.10.4.2  nathanw 		}
    265  1.10.4.2  nathanw 	}
    266  1.10.4.2  nathanw 	return 0;
    267  1.10.4.2  nathanw }
    268  1.10.4.2  nathanw 
    269  1.10.4.2  nathanw static void
    270  1.10.4.2  nathanw pccard_kthread(void *arg)
    271  1.10.4.2  nathanw {
    272  1.10.4.2  nathanw 	struct pccard_softc *self = arg;
    273  1.10.4.2  nathanw 	struct pccard_slot *slot = &self->devs[0];
    274  1.10.4.2  nathanw 
    275  1.10.4.2  nathanw 	for (;;) {
    276  1.10.4.2  nathanw 		int s = spl2();
    277  1.10.4.2  nathanw 
    278  1.10.4.2  nathanw 		if (slot->flags & SLOT_NEW_CARD_EVENT) {
    279  1.10.4.2  nathanw 			slot->flags &= ~SLOT_NEW_CARD_EVENT;
    280  1.10.4.2  nathanw 			gayle.intreq = 0xc0;
    281  1.10.4.2  nathanw 
    282  1.10.4.2  nathanw 			/* reset the registers */
    283  1.10.4.2  nathanw 			gayle.intreq = GAYLE_INT_IDE | GAYLE_INT_DETECT;
    284  1.10.4.2  nathanw 			gayle.pcc_status = GAYLE_CCMEM_WP | GAYLE_CCIO_SPKR;
    285  1.10.4.2  nathanw 			gayle.pcc_config = 0;
    286  1.10.4.2  nathanw 			pccard_attach_slot(&self->devs[0]);
    287  1.10.4.2  nathanw 		}
    288  1.10.4.2  nathanw 		splx(s);
    289  1.10.4.2  nathanw 
    290  1.10.4.2  nathanw 		tsleep(slot, PWAIT, "pccthread", hz);
    291  1.10.4.2  nathanw 	}
    292  1.10.4.2  nathanw }
    293  1.10.4.2  nathanw 
    294  1.10.4.2  nathanw static void
    295  1.10.4.2  nathanw pccard_attach_slot(struct pccard_slot *slot)
    296  1.10.4.2  nathanw {
    297  1.10.4.2  nathanw 
    298  1.10.4.2  nathanw 	if (!(slot->flags & SLOT_OCCUPIED) &&
    299  1.10.4.2  nathanw 			gayle.pcc_status & GAYLE_CCMEM_DETECT) {
    300  1.10.4.2  nathanw 		if (pcmcia_card_attach(slot->card) == 0)
    301  1.10.4.2  nathanw 			slot->flags |= SLOT_OCCUPIED;
    302  1.10.4.2  nathanw 	}
    303  1.10.4.2  nathanw }
    304  1.10.4.2  nathanw 
    305  1.10.4.2  nathanw static int
    306  1.10.4.2  nathanw pcf_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t bsz,
    307  1.10.4.2  nathanw 	      struct pcmcia_mem_handle *pcmh)
    308  1.10.4.2  nathanw {
    309  1.10.4.2  nathanw 	struct pccard_slot *slot = (struct pccard_slot *) pch;
    310  1.10.4.2  nathanw 
    311  1.10.4.2  nathanw 	pcmh->memt = &slot->sc->attr_space;
    312  1.10.4.2  nathanw 	pcmh->memh = pcmh->memt->base;
    313  1.10.4.2  nathanw 	return 0;
    314  1.10.4.2  nathanw }
    315  1.10.4.2  nathanw 
    316  1.10.4.2  nathanw static void
    317  1.10.4.2  nathanw pcf_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *memh)
    318  1.10.4.2  nathanw {
    319  1.10.4.2  nathanw }
    320  1.10.4.2  nathanw 
    321  1.10.4.2  nathanw static int
    322  1.10.4.2  nathanw pcf_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t addr,
    323  1.10.4.2  nathanw 	    bus_size_t size, struct pcmcia_mem_handle *pcmh,
    324  1.10.4.2  nathanw 	    bus_addr_t *offsetp, int *windowp)
    325  1.10.4.2  nathanw {
    326  1.10.4.2  nathanw 	struct pccard_slot *slot = (struct pccard_slot *) pch;
    327  1.10.4.2  nathanw 
    328  1.10.4.2  nathanw 	/* Ignore width requirements */
    329  1.10.4.2  nathanw 	kind &= ~PCMCIA_WIDTH_MEM_MASK;
    330  1.10.4.2  nathanw 
    331  1.10.4.2  nathanw 	switch (kind) {
    332  1.10.4.2  nathanw 	case PCMCIA_MEM_ATTR:
    333  1.10.4.2  nathanw 		pcmh->memt = &slot->sc->attr_space;
    334  1.10.4.2  nathanw 		break;
    335  1.10.4.2  nathanw 	case PCMCIA_MEM_COMMON:
    336  1.10.4.2  nathanw 		pcmh->memt = &slot->sc->mem_space;
    337  1.10.4.2  nathanw 		break;
    338  1.10.4.2  nathanw 	default:
    339  1.10.4.2  nathanw 		/* This means that this code needs an update/a bugfix */
    340  1.10.4.2  nathanw 		printf(__FILE__ ": unknown kind %d of PCMCIA memory\n", kind);
    341  1.10.4.2  nathanw 		return 1;
    342  1.10.4.2  nathanw 	}
    343  1.10.4.2  nathanw 
    344  1.10.4.2  nathanw 	bus_space_map(pcmh->memt, addr, size, 0, &pcmh->memh);
    345  1.10.4.2  nathanw 	*offsetp = 0;
    346  1.10.4.2  nathanw 	*windowp = 0;			/* unused */
    347  1.10.4.2  nathanw 
    348  1.10.4.2  nathanw 	return 0;
    349  1.10.4.2  nathanw }
    350  1.10.4.2  nathanw 
    351  1.10.4.2  nathanw static void
    352  1.10.4.2  nathanw pcf_mem_unmap(pcmcia_chipset_handle_t pch, int win)
    353  1.10.4.2  nathanw {
    354  1.10.4.2  nathanw }
    355  1.10.4.2  nathanw 
    356  1.10.4.2  nathanw static int
    357  1.10.4.2  nathanw pcf_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, bus_size_t size,
    358  1.10.4.2  nathanw 	     bus_size_t align, struct pcmcia_io_handle *pcihp)
    359  1.10.4.2  nathanw {
    360  1.10.4.2  nathanw 	struct pccard_slot *slot = (struct pccard_slot *) pch;
    361  1.10.4.2  nathanw 
    362  1.10.4.2  nathanw 	pcihp->iot = &slot->sc->io_space;
    363  1.10.4.2  nathanw 	pcihp->ioh = pcihp->iot->base;
    364  1.10.4.2  nathanw 	return 0;
    365  1.10.4.2  nathanw }
    366  1.10.4.2  nathanw 
    367  1.10.4.2  nathanw static void
    368  1.10.4.2  nathanw pcf_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pcihp)
    369  1.10.4.2  nathanw {
    370  1.10.4.2  nathanw }
    371  1.10.4.2  nathanw 
    372  1.10.4.2  nathanw static int
    373  1.10.4.2  nathanw pcf_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
    374  1.10.4.2  nathanw 	   bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp)
    375  1.10.4.2  nathanw {
    376  1.10.4.2  nathanw 	struct pccard_slot *slot = (struct pccard_slot *) pch;
    377  1.10.4.2  nathanw 
    378  1.10.4.2  nathanw 	pcihp->iot = &slot->sc->io_space;
    379  1.10.4.2  nathanw 	pcihp->ioh = offset;
    380  1.10.4.2  nathanw 
    381  1.10.4.2  nathanw 	*windowp = 0;		/* unused */
    382  1.10.4.2  nathanw 	return 0;
    383  1.10.4.2  nathanw }
    384  1.10.4.2  nathanw 
    385  1.10.4.2  nathanw static void
    386  1.10.4.2  nathanw pcf_io_unmap(pcmcia_chipset_handle_t pch, int win)
    387  1.10.4.2  nathanw {
    388  1.10.4.2  nathanw }
    389  1.10.4.2  nathanw 
    390  1.10.4.2  nathanw static void *
    391  1.10.4.2  nathanw pcf_intr_establish(pcmcia_chipset_handle_t pch, struct pcmcia_function *pf,
    392  1.10.4.2  nathanw 		   int ipl, int (*func)(void *), void *arg)
    393  1.10.4.2  nathanw {
    394  1.10.4.2  nathanw 	struct pccard_slot *slot = (struct pccard_slot *) pch;
    395  1.10.4.2  nathanw 	int s;
    396  1.10.4.2  nathanw 
    397  1.10.4.2  nathanw 	s = splhigh();
    398  1.10.4.2  nathanw 	if (slot->intr_func == NULL) {
    399  1.10.4.2  nathanw 		slot->intr_func = func;
    400  1.10.4.2  nathanw 		slot->intr_arg = arg;
    401  1.10.4.2  nathanw 	} else {
    402  1.10.4.2  nathanw 		/* if we are here, we need to put intrs into a list */
    403  1.10.4.2  nathanw 		printf("ARGH! see " __FILE__ "\n");
    404  1.10.4.2  nathanw 		slot = NULL;
    405  1.10.4.2  nathanw 	}
    406  1.10.4.2  nathanw 	splx(s);
    407  1.10.4.2  nathanw 
    408  1.10.4.2  nathanw 	return slot;
    409  1.10.4.2  nathanw }
    410  1.10.4.2  nathanw 
    411  1.10.4.2  nathanw static void
    412  1.10.4.2  nathanw pcf_intr_disestablish(pcmcia_chipset_handle_t pch, void *intr_handler)
    413  1.10.4.2  nathanw {
    414  1.10.4.2  nathanw 	struct pccard_slot *slot = (struct pccard_slot *) intr_handler;
    415  1.10.4.2  nathanw 
    416  1.10.4.2  nathanw 	if (slot != NULL) {
    417  1.10.4.2  nathanw 		slot->intr_func = NULL;
    418  1.10.4.2  nathanw 		slot->intr_arg = NULL;
    419  1.10.4.2  nathanw 	}
    420  1.10.4.2  nathanw }
    421  1.10.4.2  nathanw 
    422  1.10.4.2  nathanw static void
    423  1.10.4.2  nathanw pcf_socket_enable(pcmcia_chipset_handle_t pch)
    424  1.10.4.2  nathanw {
    425  1.10.4.2  nathanw }
    426  1.10.4.2  nathanw 
    427  1.10.4.2  nathanw static void
    428  1.10.4.2  nathanw pcf_socket_disable(pcmcia_chipset_handle_t pch)
    429  1.10.4.2  nathanw {
    430  1.10.4.2  nathanw }
    431  1.10.4.2  nathanw 
    432  1.10.4.2  nathanw 
    433  1.10.4.2  nathanw static u_int8_t
    434  1.10.4.2  nathanw pcmio_bsr1(bus_space_handle_t h, bus_size_t o)
    435  1.10.4.2  nathanw {
    436  1.10.4.2  nathanw 
    437  1.10.4.2  nathanw 	return *((volatile u_int8_t *) h + o + (o & 1 ? 0xffff : 0));
    438  1.10.4.2  nathanw }
    439  1.10.4.2  nathanw 
    440  1.10.4.2  nathanw static void
    441  1.10.4.2  nathanw pcmio_bsw1(bus_space_handle_t h, bus_size_t o, unsigned v)
    442  1.10.4.2  nathanw {
    443  1.10.4.2  nathanw 
    444  1.10.4.2  nathanw 	*((volatile u_int8_t *) h + o + (o & 1 ? 0xffff : 0)) = v;
    445  1.10.4.2  nathanw }
    446  1.10.4.2  nathanw 
    447  1.10.4.2  nathanw static void
    448  1.10.4.2  nathanw pcmio_bsrm1(bus_space_handle_t h, bus_size_t o, u_int8_t *p, bus_size_t c)
    449  1.10.4.2  nathanw {
    450  1.10.4.2  nathanw 	volatile u_int8_t *src = (volatile u_int8_t *)
    451  1.10.4.2  nathanw 		(h + o + (o & 1 ? 0xffff : 0));
    452  1.10.4.2  nathanw 
    453  1.10.4.2  nathanw 
    454  1.10.4.2  nathanw 	/* XXX we can (should, must) optimize this if c >= 4 */
    455  1.10.4.2  nathanw 	for (; c > 0; c--)
    456  1.10.4.2  nathanw 		*p++ = *src;
    457  1.10.4.2  nathanw }
    458  1.10.4.2  nathanw 
    459  1.10.4.2  nathanw 
    460  1.10.4.2  nathanw static void
    461  1.10.4.2  nathanw pcmio_bswm1(bus_space_handle_t h, bus_size_t o, const u_int8_t *p, bus_size_t c)
    462  1.10.4.2  nathanw {
    463  1.10.4.2  nathanw 	volatile u_int8_t *dst = (volatile u_int8_t *)
    464  1.10.4.2  nathanw 		(h + o + (o & 1 ? 0xffff : 0));
    465  1.10.4.2  nathanw 
    466  1.10.4.2  nathanw 
    467  1.10.4.2  nathanw 	/* XXX we can (should, must) optimize this if c >= 4 */
    468  1.10.4.2  nathanw 	for (; c > 0; c--)
    469  1.10.4.2  nathanw 		*dst = *p++;
    470  1.10.4.2  nathanw }
    471  1.10.4.2  nathanw 
    472  1.10.4.2  nathanw static void
    473  1.10.4.2  nathanw pcmio_bsrr1(bus_space_handle_t h, bus_size_t o, u_int8_t *p, bus_size_t c)
    474  1.10.4.2  nathanw {
    475  1.10.4.2  nathanw 	volatile u_int8_t *cp1;
    476  1.10.4.2  nathanw 	volatile u_int8_t *cp2;
    477  1.10.4.2  nathanw 	volatile u_int8_t *temp;
    478  1.10.4.2  nathanw 
    479  1.10.4.2  nathanw 	if (o & 1) {
    480  1.10.4.2  nathanw 		cp1 = (volatile u_int8_t *) h + o + 0x10000;
    481  1.10.4.2  nathanw 		cp2 = (volatile u_int8_t *) h + o;
    482  1.10.4.2  nathanw 	} else {
    483  1.10.4.2  nathanw 		cp1 = (volatile u_int8_t *) h + o;
    484  1.10.4.2  nathanw 		cp2 = (volatile u_int8_t *) h + o + 0x10000 + 2;
    485  1.10.4.2  nathanw 	}
    486  1.10.4.2  nathanw 
    487  1.10.4.2  nathanw 	/* XXX we can (should, must) optimize this if c >= 4 */
    488  1.10.4.2  nathanw 	for (; c > 0; c--) {
    489  1.10.4.2  nathanw 		*p++ = *cp1;
    490  1.10.4.2  nathanw 		cp1 += 2;
    491  1.10.4.2  nathanw 
    492  1.10.4.2  nathanw 		/* swap pointers - hope gcc generates exg for this ;) */
    493  1.10.4.2  nathanw 		temp = cp1;
    494  1.10.4.2  nathanw 		cp1 = cp2;
    495  1.10.4.2  nathanw 		cp2 = temp;
    496  1.10.4.2  nathanw 	}
    497  1.10.4.2  nathanw }
    498  1.10.4.2  nathanw 
    499  1.10.4.2  nathanw 
    500  1.10.4.2  nathanw static void
    501  1.10.4.2  nathanw pcmio_bswr1(bus_space_handle_t h, bus_size_t o, const u_int8_t *p, bus_size_t c)
    502  1.10.4.2  nathanw {
    503  1.10.4.2  nathanw 	volatile u_int8_t *cp1;
    504  1.10.4.2  nathanw 	volatile u_int8_t *cp2;
    505  1.10.4.2  nathanw 	volatile u_int8_t *temp;
    506  1.10.4.2  nathanw 
    507  1.10.4.2  nathanw 	if (o & 1) {
    508  1.10.4.2  nathanw 		cp1 = (volatile u_int8_t *) h + o + 0x10000;
    509  1.10.4.2  nathanw 		cp2 = (volatile u_int8_t *) h + o;
    510  1.10.4.2  nathanw 	} else {
    511  1.10.4.2  nathanw 		cp1 = (volatile u_int8_t *) h + o;
    512  1.10.4.2  nathanw 		cp2 = (volatile u_int8_t *) h + o + 0x10000 + 2;
    513  1.10.4.2  nathanw 	}
    514  1.10.4.2  nathanw 
    515  1.10.4.2  nathanw 	/* XXX we can (should, must) optimize this if c >= 4 */
    516  1.10.4.2  nathanw 	for (; c > 0; c--) {
    517  1.10.4.2  nathanw 		*cp1 = *p++;
    518  1.10.4.2  nathanw 		cp1 += 2;
    519  1.10.4.2  nathanw 
    520  1.10.4.2  nathanw 		/* swap pointers - hope gcc generates exg for this ;) */
    521  1.10.4.2  nathanw 		temp = cp1;
    522  1.10.4.2  nathanw 		cp1 = cp2;
    523  1.10.4.2  nathanw 		cp2 = temp;
    524  1.10.4.2  nathanw 	}
    525  1.10.4.2  nathanw }
    526  1.10.4.2  nathanw 
    527  1.10.4.2  nathanw void
    528  1.10.4.2  nathanw pcmio_bssr1(bus_space_handle_t h, bus_size_t o, unsigned v, bus_size_t c)
    529  1.10.4.2  nathanw {
    530  1.10.4.2  nathanw 
    531  1.10.4.2  nathanw 	panic("pcmio_bssr1 is not defined (" __FILE__ ")");
    532  1.10.4.2  nathanw }
    533  1.10.4.2  nathanw 
    534  1.10.4.2  nathanw void
    535  1.10.4.2  nathanw pcmio_bscr1(bus_space_handle_t h, bus_size_t o, bus_space_handle_t g,
    536  1.10.4.2  nathanw 	    bus_size_t q, bus_size_t c)
    537  1.10.4.2  nathanw {
    538  1.10.4.2  nathanw 
    539  1.10.4.2  nathanw 	panic("pcmio_bscr1 is not defined (" __FILE__ ")");
    540  1.10.4.2  nathanw }
    541