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