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