Home | History | Annotate | Line # | Download | only in ic
i82365.c revision 1.1.2.8
      1  1.1.2.1     marc #define PCICDEBUG
      2  1.1.2.1     marc 
      3  1.1.2.1     marc #include <sys/types.h>
      4  1.1.2.1     marc #include <sys/param.h>
      5  1.1.2.1     marc #include <sys/systm.h>
      6  1.1.2.1     marc #include <sys/device.h>
      7  1.1.2.1     marc #include <sys/extent.h>
      8  1.1.2.1     marc #include <sys/malloc.h>
      9  1.1.2.1     marc 
     10  1.1.2.1     marc #include <vm/vm.h>
     11  1.1.2.1     marc 
     12  1.1.2.1     marc #include <machine/bus.h>
     13  1.1.2.1     marc #include <machine/intr.h>
     14  1.1.2.1     marc 
     15  1.1.2.1     marc #include <dev/pcmcia/pcmciareg.h>
     16  1.1.2.4  thorpej #include <dev/pcmcia/pcmciavar.h>
     17  1.1.2.1     marc 
     18  1.1.2.1     marc #include <dev/ic/i82365reg.h>
     19  1.1.2.8     marc #include <dev/ic/i82365var.h>
     20  1.1.2.1     marc 
     21  1.1.2.1     marc #ifdef PCICDEBUG
     22  1.1.2.2  thorpej int	pcic_debug = 0;
     23  1.1.2.2  thorpej #define DPRINTF(arg) if (pcic_debug) printf arg;
     24  1.1.2.1     marc #else
     25  1.1.2.1     marc #define DPRINTF(arg)
     26  1.1.2.1     marc #endif
     27  1.1.2.1     marc 
     28  1.1.2.1     marc #define PCIC_FLAG_SOCKETP	0x0001
     29  1.1.2.1     marc #define PCIC_FLAG_CARDP		0x0002
     30  1.1.2.1     marc 
     31  1.1.2.1     marc #define PCIC_VENDOR_UNKNOWN		0
     32  1.1.2.1     marc #define PCIC_VENDOR_I82365SLR0		1
     33  1.1.2.1     marc #define PCIC_VENDOR_I82365SLR1		2
     34  1.1.2.1     marc #define PCIC_VENDOR_CIRRUS_PD6710	3
     35  1.1.2.1     marc #define PCIC_VENDOR_CIRRUS_PD672X	4
     36  1.1.2.1     marc 
     37  1.1.2.1     marc /* Individual drivers will allocate their own memory and io regions.
     38  1.1.2.1     marc    Memory regions must be a multiple of 4k, aligned on a 4k boundary. */
     39  1.1.2.1     marc 
     40  1.1.2.1     marc #define PCIC_MEM_ALIGN	PCIC_MEM_PAGESIZE
     41  1.1.2.1     marc 
     42  1.1.2.1     marc void pcic_attach_socket __P((struct pcic_handle *));
     43  1.1.2.1     marc void pcic_init_socket __P((struct pcic_handle *));
     44  1.1.2.1     marc 
     45  1.1.2.1     marc #ifdef __BROKEN_INDIRECT_CONFIG
     46  1.1.2.1     marc int pcic_submatch __P((struct device *, void *, void *));
     47  1.1.2.1     marc #else
     48  1.1.2.1     marc int pcic_submatch __P((struct device *, struct cfdata *, void *));
     49  1.1.2.1     marc #endif
     50  1.1.2.1     marc int pcic_print __P((void *arg, const char *pnp));
     51  1.1.2.1     marc int pcic_intr_socket __P((struct pcic_handle *));
     52  1.1.2.1     marc 
     53  1.1.2.1     marc void pcic_attach_card(struct pcic_handle *);
     54  1.1.2.1     marc void pcic_detach_card(struct pcic_handle *);
     55  1.1.2.1     marc 
     56  1.1.2.1     marc struct cfdriver pcic_cd = {
     57  1.1.2.1     marc 	NULL, "pcic", DV_DULL
     58  1.1.2.1     marc };
     59  1.1.2.1     marc 
     60  1.1.2.1     marc int
     61  1.1.2.1     marc pcic_ident_ok(ident)
     62  1.1.2.1     marc      int ident;
     63  1.1.2.1     marc {
     64  1.1.2.1     marc     /* this is very empirical and heuristic */
     65  1.1.2.1     marc 
     66  1.1.2.1     marc     if ((ident == 0) || (ident == 0xff) || (ident & PCIC_IDENT_ZERO))
     67  1.1.2.1     marc 	return(0);
     68  1.1.2.1     marc 
     69  1.1.2.1     marc     if ((ident & PCIC_IDENT_IFTYPE_MASK) != PCIC_IDENT_IFTYPE_MEM_AND_IO) {
     70  1.1.2.1     marc #ifdef DIAGNOSTIC
     71  1.1.2.1     marc 	printf("pcic: does not support memory and I/O cards, ignored (ident=%0x)\n",
     72  1.1.2.1     marc 	       ident);
     73  1.1.2.1     marc #endif
     74  1.1.2.1     marc 	return(0);
     75  1.1.2.1     marc     }
     76  1.1.2.1     marc 
     77  1.1.2.1     marc     return(1);
     78  1.1.2.1     marc }
     79  1.1.2.1     marc 
     80  1.1.2.1     marc int
     81  1.1.2.1     marc pcic_vendor(h)
     82  1.1.2.1     marc      struct pcic_handle *h;
     83  1.1.2.1     marc {
     84  1.1.2.1     marc     int reg;
     85  1.1.2.1     marc 
     86  1.1.2.8     marc     /* the chip_id of the cirrus toggles between 11 and 00
     87  1.1.2.8     marc        after a write.  weird. */
     88  1.1.2.1     marc 
     89  1.1.2.1     marc     pcic_write(h, PCIC_CIRRUS_CHIP_INFO, 0);
     90  1.1.2.1     marc     reg = pcic_read(h, -1);
     91  1.1.2.1     marc 
     92  1.1.2.1     marc     if ((reg & PCIC_CIRRUS_CHIP_INFO_CHIP_ID) ==
     93  1.1.2.1     marc 	PCIC_CIRRUS_CHIP_INFO_CHIP_ID) {
     94  1.1.2.1     marc 	reg = pcic_read(h, -1);
     95  1.1.2.1     marc 	if ((reg & PCIC_CIRRUS_CHIP_INFO_CHIP_ID) == 0) {
     96  1.1.2.1     marc 	    if (reg & PCIC_CIRRUS_CHIP_INFO_SLOTS)
     97  1.1.2.1     marc 		return(PCIC_VENDOR_CIRRUS_PD672X);
     98  1.1.2.1     marc 	    else
     99  1.1.2.1     marc 		return(PCIC_VENDOR_CIRRUS_PD6710);
    100  1.1.2.1     marc 	}
    101  1.1.2.1     marc     }
    102  1.1.2.1     marc 
    103  1.1.2.8     marc     /* XXX how do I identify the GD6729? */
    104  1.1.2.8     marc 
    105  1.1.2.1     marc     reg = pcic_read(h, PCIC_IDENT);
    106  1.1.2.1     marc 
    107  1.1.2.1     marc     if ((reg & PCIC_IDENT_REV_MASK) == PCIC_IDENT_REV_I82365SLR0)
    108  1.1.2.1     marc 	return(PCIC_VENDOR_I82365SLR0);
    109  1.1.2.1     marc     else
    110  1.1.2.1     marc 	return(PCIC_VENDOR_I82365SLR1);
    111  1.1.2.1     marc 
    112  1.1.2.1     marc     return(PCIC_VENDOR_UNKNOWN);
    113  1.1.2.1     marc }
    114  1.1.2.1     marc 
    115  1.1.2.1     marc char *
    116  1.1.2.1     marc pcic_vendor_to_string(vendor)
    117  1.1.2.1     marc      int vendor;
    118  1.1.2.1     marc {
    119  1.1.2.1     marc     switch (vendor) {
    120  1.1.2.1     marc     case PCIC_VENDOR_I82365SLR0:
    121  1.1.2.1     marc 	return("Intel 82365SL Revision 0");
    122  1.1.2.1     marc     case PCIC_VENDOR_I82365SLR1:
    123  1.1.2.1     marc 	return("Intel 82365SL Revision 1");
    124  1.1.2.1     marc     case PCIC_VENDOR_CIRRUS_PD6710:
    125  1.1.2.1     marc 	return("Cirrus PD6710");
    126  1.1.2.1     marc     case PCIC_VENDOR_CIRRUS_PD672X:
    127  1.1.2.1     marc 	return("Cirrus PD672X");
    128  1.1.2.1     marc     }
    129  1.1.2.1     marc 
    130  1.1.2.1     marc     return("Unknown controller");
    131  1.1.2.1     marc }
    132  1.1.2.1     marc 
    133  1.1.2.1     marc void
    134  1.1.2.8     marc pcic_attach(sc)
    135  1.1.2.8     marc      struct pcic_softc *sc;
    136  1.1.2.1     marc {
    137  1.1.2.6      jtk     int vendor, count, i;
    138  1.1.2.1     marc 
    139  1.1.2.1     marc     /* now check for each controller/socket */
    140  1.1.2.1     marc 
    141  1.1.2.1     marc     /* this could be done with a loop, but it would violate the
    142  1.1.2.1     marc        abstraction */
    143  1.1.2.1     marc 
    144  1.1.2.1     marc     count = 0;
    145  1.1.2.1     marc 
    146  1.1.2.1     marc     sc->handle[0].sc = sc;
    147  1.1.2.1     marc     sc->handle[0].sock = C0SA;
    148  1.1.2.1     marc     if (pcic_ident_ok(pcic_read(&sc->handle[0], PCIC_IDENT))) {
    149  1.1.2.1     marc 	sc->handle[0].flags = PCIC_FLAG_SOCKETP;
    150  1.1.2.1     marc 	count++;
    151  1.1.2.1     marc     } else {
    152  1.1.2.1     marc 	sc->handle[0].flags = 0;
    153  1.1.2.1     marc     }
    154  1.1.2.1     marc 
    155  1.1.2.1     marc     sc->handle[1].sc = sc;
    156  1.1.2.1     marc     sc->handle[1].sock = C0SB;
    157  1.1.2.1     marc     if (pcic_ident_ok(pcic_read(&sc->handle[1], PCIC_IDENT))) {
    158  1.1.2.1     marc 	sc->handle[1].flags = PCIC_FLAG_SOCKETP;
    159  1.1.2.1     marc 	count++;
    160  1.1.2.1     marc     } else {
    161  1.1.2.1     marc 	sc->handle[1].flags = 0;
    162  1.1.2.1     marc     }
    163  1.1.2.1     marc 
    164  1.1.2.1     marc     sc->handle[2].sc = sc;
    165  1.1.2.1     marc     sc->handle[2].sock = C1SA;
    166  1.1.2.1     marc     if (pcic_ident_ok(pcic_read(&sc->handle[2], PCIC_IDENT))) {
    167  1.1.2.1     marc 	sc->handle[2].flags = PCIC_FLAG_SOCKETP;
    168  1.1.2.1     marc 	count++;
    169  1.1.2.1     marc     } else {
    170  1.1.2.1     marc 	sc->handle[2].flags = 0;
    171  1.1.2.1     marc     }
    172  1.1.2.1     marc 
    173  1.1.2.1     marc     sc->handle[3].sc = sc;
    174  1.1.2.1     marc     sc->handle[3].sock = C1SB;
    175  1.1.2.1     marc     if (pcic_ident_ok(pcic_read(&sc->handle[3], PCIC_IDENT))) {
    176  1.1.2.1     marc 	sc->handle[3].flags = PCIC_FLAG_SOCKETP;
    177  1.1.2.1     marc 	count++;
    178  1.1.2.1     marc     } else {
    179  1.1.2.1     marc 	sc->handle[3].flags = 0;
    180  1.1.2.1     marc     }
    181  1.1.2.1     marc 
    182  1.1.2.1     marc     if (count == 0)
    183  1.1.2.1     marc 	panic("pcic_attach: attach found no sockets");
    184  1.1.2.1     marc 
    185  1.1.2.1     marc     /* establish the interrupt */
    186  1.1.2.1     marc 
    187  1.1.2.1     marc     /* XXX block interrupts? */
    188  1.1.2.1     marc 
    189  1.1.2.1     marc     for (i=0; i<PCIC_NSLOTS; i++) {
    190  1.1.2.1     marc 	pcic_write(&sc->handle[i], PCIC_CSC_INTR, 0);
    191  1.1.2.1     marc 	pcic_read(&sc->handle[i], PCIC_CSC);
    192  1.1.2.1     marc     }
    193  1.1.2.1     marc 
    194  1.1.2.1     marc     if ((sc->handle[0].flags & PCIC_FLAG_SOCKETP) ||
    195  1.1.2.1     marc 	(sc->handle[1].flags & PCIC_FLAG_SOCKETP)) {
    196  1.1.2.1     marc 	vendor = pcic_vendor(&sc->handle[0]);
    197  1.1.2.1     marc 
    198  1.1.2.1     marc 	printf("%s: controller 0 (%s) has ", sc->dev.dv_xname,
    199  1.1.2.1     marc 	       pcic_vendor_to_string(vendor));
    200  1.1.2.1     marc 
    201  1.1.2.1     marc 	if ((sc->handle[0].flags & PCIC_FLAG_SOCKETP) &&
    202  1.1.2.1     marc 	    (sc->handle[1].flags & PCIC_FLAG_SOCKETP))
    203  1.1.2.1     marc 	    printf("sockets A and B\n");
    204  1.1.2.1     marc 	else if (sc->handle[0].flags & PCIC_FLAG_SOCKETP)
    205  1.1.2.1     marc 	    printf("socket A only\n");
    206  1.1.2.1     marc 	else
    207  1.1.2.1     marc 	    printf("socket B only\n");
    208  1.1.2.1     marc 
    209  1.1.2.1     marc #if 0
    210  1.1.2.1     marc 	pcic_write(&sc->handle[0], PCIC_GLOBAL_CTL,
    211  1.1.2.1     marc 		   PCIC_GLOBAL_CTL_EXPLICIT_CSC_ACK);
    212  1.1.2.1     marc #endif
    213  1.1.2.1     marc 
    214  1.1.2.8     marc 	if (sc->handle[0].flags & PCIC_FLAG_SOCKETP)
    215  1.1.2.1     marc 	    sc->handle[0].vendor = vendor;
    216  1.1.2.8     marc 	if (sc->handle[1].flags & PCIC_FLAG_SOCKETP)
    217  1.1.2.1     marc 	    sc->handle[1].vendor = vendor;
    218  1.1.2.1     marc     }
    219  1.1.2.1     marc 
    220  1.1.2.1     marc     if ((sc->handle[2].flags & PCIC_FLAG_SOCKETP) ||
    221  1.1.2.1     marc 	(sc->handle[3].flags & PCIC_FLAG_SOCKETP)) {
    222  1.1.2.1     marc 	vendor = pcic_vendor(&sc->handle[2]);
    223  1.1.2.1     marc 
    224  1.1.2.1     marc 	printf("%s: controller 1 (%s) has ", sc->dev.dv_xname,
    225  1.1.2.1     marc 	       pcic_vendor_to_string(vendor));
    226  1.1.2.1     marc 
    227  1.1.2.1     marc 	if ((sc->handle[2].flags & PCIC_FLAG_SOCKETP) &&
    228  1.1.2.1     marc 	    (sc->handle[3].flags & PCIC_FLAG_SOCKETP))
    229  1.1.2.1     marc 	    printf("sockets A and B\n");
    230  1.1.2.1     marc 	else if (sc->handle[2].flags & PCIC_FLAG_SOCKETP)
    231  1.1.2.1     marc 	    printf("socket A only\n");
    232  1.1.2.1     marc 	else
    233  1.1.2.1     marc 	    printf("socket B only\n");
    234  1.1.2.1     marc 
    235  1.1.2.1     marc #if 0
    236  1.1.2.1     marc 	pcic_write(&sc->handle[2], PCIC_GLOBAL_CTL,
    237  1.1.2.1     marc 		   PCIC_GLOBAL_CTL_EXPLICIT_CSC_ACK);
    238  1.1.2.1     marc #endif
    239  1.1.2.1     marc 
    240  1.1.2.8     marc 	if (sc->handle[2].flags & PCIC_FLAG_SOCKETP)
    241  1.1.2.1     marc 	    sc->handle[2].vendor = vendor;
    242  1.1.2.8     marc 	if (sc->handle[3].flags & PCIC_FLAG_SOCKETP)
    243  1.1.2.1     marc 	    sc->handle[3].vendor = vendor;
    244  1.1.2.1     marc     }
    245  1.1.2.1     marc }
    246  1.1.2.1     marc 
    247  1.1.2.1     marc void
    248  1.1.2.8     marc pcic_attach_sockets(sc)
    249  1.1.2.8     marc      struct pcic_softc *sc;
    250  1.1.2.8     marc {
    251  1.1.2.8     marc     int i;
    252  1.1.2.8     marc 
    253  1.1.2.8     marc     for (i=0; i<PCIC_NSLOTS; i++)
    254  1.1.2.8     marc 	if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
    255  1.1.2.8     marc 	    pcic_attach_socket(&sc->handle[i]);
    256  1.1.2.8     marc }
    257  1.1.2.8     marc 
    258  1.1.2.8     marc void
    259  1.1.2.1     marc pcic_attach_socket(h)
    260  1.1.2.1     marc      struct pcic_handle *h;
    261  1.1.2.1     marc {
    262  1.1.2.1     marc    struct pcmciabus_attach_args paa;
    263  1.1.2.1     marc 
    264  1.1.2.1     marc    /* initialize the rest of the handle */
    265  1.1.2.1     marc 
    266  1.1.2.1     marc    h->memalloc = 0;
    267  1.1.2.1     marc    h->ioalloc = 0;
    268  1.1.2.1     marc 
    269  1.1.2.1     marc    /* now, config one pcmcia device per socket */
    270  1.1.2.1     marc 
    271  1.1.2.8     marc    paa.pct = (pcmcia_chipset_tag_t) h->sc->pct;
    272  1.1.2.1     marc    paa.pch = (pcmcia_chipset_handle_t) h;
    273  1.1.2.1     marc 
    274  1.1.2.1     marc    h->pcmcia = config_found_sm(&h->sc->dev, &paa, pcic_print, pcic_submatch);
    275  1.1.2.1     marc 
    276  1.1.2.1     marc    /* if there's actually a pcmcia device attached, initialize the slot */
    277  1.1.2.1     marc 
    278  1.1.2.1     marc    if (h->pcmcia)
    279  1.1.2.1     marc        pcic_init_socket(h);
    280  1.1.2.1     marc }
    281  1.1.2.1     marc 
    282  1.1.2.1     marc void
    283  1.1.2.1     marc pcic_init_socket(h)
    284  1.1.2.1     marc      struct pcic_handle *h;
    285  1.1.2.1     marc {
    286  1.1.2.1     marc     int reg;
    287  1.1.2.1     marc 
    288  1.1.2.1     marc     /* set up the card to interrupt on card detect */
    289  1.1.2.1     marc 
    290  1.1.2.1     marc     pcic_write(h, PCIC_CSC_INTR,
    291  1.1.2.1     marc 	       (h->sc->irq<<PCIC_CSC_INTR_IRQ_SHIFT)|
    292  1.1.2.1     marc 	       PCIC_CSC_INTR_CD_ENABLE);
    293  1.1.2.1     marc     pcic_write(h, PCIC_INTR, 0);
    294  1.1.2.1     marc     pcic_read(h, PCIC_CSC);
    295  1.1.2.1     marc 
    296  1.1.2.1     marc     /* unsleep the cirrus controller */
    297  1.1.2.1     marc 
    298  1.1.2.1     marc     if ((h->vendor == PCIC_VENDOR_CIRRUS_PD6710) ||
    299  1.1.2.1     marc 	(h->vendor == PCIC_VENDOR_CIRRUS_PD672X)) {
    300  1.1.2.1     marc 	reg = pcic_read(h, PCIC_CIRRUS_MISC_CTL_2);
    301  1.1.2.1     marc 	if (reg & PCIC_CIRRUS_MISC_CTL_2_SUSPEND) {
    302  1.1.2.1     marc 	    DPRINTF(("%s: socket %02x was suspended\n", h->sc->dev.dv_xname,
    303  1.1.2.1     marc 		     h->sock));
    304  1.1.2.1     marc 	    reg &= ~PCIC_CIRRUS_MISC_CTL_2_SUSPEND;
    305  1.1.2.1     marc 	    pcic_write(h, PCIC_CIRRUS_MISC_CTL_2, reg);
    306  1.1.2.1     marc 	}
    307  1.1.2.1     marc     }
    308  1.1.2.1     marc 
    309  1.1.2.1     marc     /* if there's a card there, then attach it. */
    310  1.1.2.1     marc 
    311  1.1.2.1     marc     reg = pcic_read(h, PCIC_IF_STATUS);
    312  1.1.2.1     marc 
    313  1.1.2.1     marc     if ((reg & PCIC_IF_STATUS_CARDDETECT_MASK) ==
    314  1.1.2.1     marc 	PCIC_IF_STATUS_CARDDETECT_PRESENT)
    315  1.1.2.1     marc 	pcic_attach_card(h);
    316  1.1.2.1     marc }
    317  1.1.2.1     marc 
    318  1.1.2.1     marc int
    319  1.1.2.1     marc #ifdef __BROKEN_INDIRECT_CONFIG
    320  1.1.2.1     marc pcic_submatch(parent, match, aux)
    321  1.1.2.1     marc #else
    322  1.1.2.1     marc pcic_submatch(parent, cf, aux)
    323  1.1.2.1     marc #endif
    324  1.1.2.1     marc      struct device *parent;
    325  1.1.2.1     marc #ifdef __BROKEN_INDIRECT_CONFIG
    326  1.1.2.1     marc      void *match;
    327  1.1.2.1     marc #else
    328  1.1.2.1     marc      struct cfdata *cf;
    329  1.1.2.1     marc #endif
    330  1.1.2.1     marc      void *aux;
    331  1.1.2.1     marc {
    332  1.1.2.1     marc #ifdef __BROKEN_INDIRECT_CONFIG
    333  1.1.2.1     marc     struct cfdata *cf = match;
    334  1.1.2.1     marc #endif
    335  1.1.2.1     marc 
    336  1.1.2.1     marc     struct pcmciabus_attach_args *paa = (struct pcmciabus_attach_args *) aux;
    337  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) paa->pch;
    338  1.1.2.1     marc 
    339  1.1.2.1     marc     switch (h->sock) {
    340  1.1.2.1     marc     case C0SA:
    341  1.1.2.1     marc 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != 0)
    342  1.1.2.1     marc 	    return 0;
    343  1.1.2.1     marc 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != 0)
    344  1.1.2.1     marc 	    return 0;
    345  1.1.2.1     marc 
    346  1.1.2.1     marc 	break;
    347  1.1.2.1     marc     case C0SB:
    348  1.1.2.1     marc 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != 0)
    349  1.1.2.1     marc 	    return 0;
    350  1.1.2.1     marc 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != 1)
    351  1.1.2.1     marc 	    return 0;
    352  1.1.2.1     marc 
    353  1.1.2.1     marc 	break;
    354  1.1.2.1     marc     case C1SA:
    355  1.1.2.1     marc 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != 1)
    356  1.1.2.1     marc 	    return 0;
    357  1.1.2.1     marc 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != 0)
    358  1.1.2.1     marc 	    return 0;
    359  1.1.2.1     marc 
    360  1.1.2.1     marc 	break;
    361  1.1.2.1     marc     case C1SB:
    362  1.1.2.1     marc 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != 1)
    363  1.1.2.1     marc 	    return 0;
    364  1.1.2.1     marc 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != 1)
    365  1.1.2.1     marc 	    return 0;
    366  1.1.2.1     marc 
    367  1.1.2.1     marc 	break;
    368  1.1.2.1     marc     default:
    369  1.1.2.1     marc 	panic("unknown pcic socket");
    370  1.1.2.1     marc     }
    371  1.1.2.1     marc 
    372  1.1.2.1     marc     return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    373  1.1.2.1     marc }
    374  1.1.2.1     marc 
    375  1.1.2.1     marc int
    376  1.1.2.1     marc pcic_print(arg, pnp)
    377  1.1.2.1     marc      void *arg;
    378  1.1.2.1     marc      const char *pnp;
    379  1.1.2.1     marc {
    380  1.1.2.1     marc     struct pcmciabus_attach_args *paa = (struct pcmciabus_attach_args *) arg;
    381  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) paa->pch;
    382  1.1.2.1     marc 
    383  1.1.2.1     marc     if (pnp)
    384  1.1.2.1     marc 	printf("pcmcia at %s", pnp);
    385  1.1.2.1     marc 
    386  1.1.2.1     marc     switch (h->sock) {
    387  1.1.2.1     marc     case C0SA:
    388  1.1.2.1     marc 	printf(" controller 0 socket 0");
    389  1.1.2.1     marc 	break;
    390  1.1.2.1     marc     case C0SB:
    391  1.1.2.1     marc 	printf(" controller 0 socket 1");
    392  1.1.2.1     marc 	break;
    393  1.1.2.1     marc     case C1SA:
    394  1.1.2.1     marc 	printf(" controller 1 socket 0");
    395  1.1.2.1     marc 	break;
    396  1.1.2.1     marc     case C1SB:
    397  1.1.2.1     marc 	printf(" controller 1 socket 1");
    398  1.1.2.1     marc 	break;
    399  1.1.2.1     marc     default:
    400  1.1.2.1     marc 	panic("unknown pcic socket");
    401  1.1.2.1     marc     }
    402  1.1.2.1     marc 
    403  1.1.2.1     marc     return(UNCONF);
    404  1.1.2.1     marc }
    405  1.1.2.1     marc 
    406  1.1.2.1     marc int
    407  1.1.2.1     marc pcic_intr(arg)
    408  1.1.2.1     marc      void *arg;
    409  1.1.2.1     marc {
    410  1.1.2.1     marc     struct pcic_softc *sc = (struct pcic_softc *) arg;
    411  1.1.2.1     marc     int i, ret = 0;
    412  1.1.2.1     marc 
    413  1.1.2.1     marc     DPRINTF(("%s: intr\n", sc->dev.dv_xname));
    414  1.1.2.1     marc 
    415  1.1.2.1     marc     for (i=0; i<PCIC_NSLOTS; i++)
    416  1.1.2.1     marc 	if (sc->handle[i].flags & PCIC_FLAG_SOCKETP)
    417  1.1.2.1     marc 	    ret += pcic_intr_socket(&sc->handle[i]);
    418  1.1.2.1     marc 
    419  1.1.2.1     marc     return(ret?1:0);
    420  1.1.2.1     marc }
    421  1.1.2.1     marc 
    422  1.1.2.1     marc int
    423  1.1.2.1     marc pcic_intr_socket(h)
    424  1.1.2.1     marc      struct pcic_handle *h;
    425  1.1.2.1     marc {
    426  1.1.2.1     marc     int cscreg;
    427  1.1.2.1     marc 
    428  1.1.2.1     marc     cscreg = pcic_read(h, PCIC_CSC);
    429  1.1.2.1     marc 
    430  1.1.2.1     marc     cscreg &= (PCIC_CSC_GPI |
    431  1.1.2.1     marc 	       PCIC_CSC_CD |
    432  1.1.2.1     marc 	       PCIC_CSC_READY |
    433  1.1.2.1     marc 	       PCIC_CSC_BATTWARN |
    434  1.1.2.1     marc 	       PCIC_CSC_BATTDEAD);
    435  1.1.2.1     marc 
    436  1.1.2.1     marc     if (cscreg & PCIC_CSC_GPI) {
    437  1.1.2.1     marc 	DPRINTF(("%s: %02x GPI\n", h->sc->dev.dv_xname, h->sock));
    438  1.1.2.1     marc     }
    439  1.1.2.1     marc     if (cscreg & PCIC_CSC_CD) {
    440  1.1.2.1     marc 	int statreg;
    441  1.1.2.1     marc 
    442  1.1.2.1     marc 	statreg = pcic_read(h, PCIC_IF_STATUS);
    443  1.1.2.1     marc 
    444  1.1.2.1     marc 	DPRINTF(("%s: %02x CD %x\n", h->sc->dev.dv_xname, h->sock,
    445  1.1.2.1     marc 		 statreg));
    446  1.1.2.1     marc 
    447  1.1.2.8     marc 	/* XXX This should probably schedule something to happen after
    448  1.1.2.8     marc 	   the interrupt handler completes */
    449  1.1.2.8     marc 
    450  1.1.2.1     marc 	if ((statreg & PCIC_IF_STATUS_CARDDETECT_MASK) ==
    451  1.1.2.1     marc 	    PCIC_IF_STATUS_CARDDETECT_PRESENT) {
    452  1.1.2.1     marc 	    if (!(h->flags & PCIC_FLAG_CARDP))
    453  1.1.2.1     marc 		pcic_attach_card(h);
    454  1.1.2.1     marc 	} else {
    455  1.1.2.1     marc 	    if (h->flags & PCIC_FLAG_CARDP)
    456  1.1.2.1     marc 		pcic_detach_card(h);
    457  1.1.2.1     marc 	}
    458  1.1.2.1     marc     }
    459  1.1.2.1     marc     if (cscreg & PCIC_CSC_READY) {
    460  1.1.2.1     marc 	DPRINTF(("%s: %02x READY\n", h->sc->dev.dv_xname, h->sock));
    461  1.1.2.1     marc 	/* shouldn't happen */
    462  1.1.2.1     marc     }
    463  1.1.2.1     marc     if (cscreg & PCIC_CSC_BATTWARN) {
    464  1.1.2.1     marc 	DPRINTF(("%s: %02x BATTWARN\n", h->sc->dev.dv_xname, h->sock));
    465  1.1.2.1     marc     }
    466  1.1.2.1     marc     if (cscreg & PCIC_CSC_BATTDEAD) {
    467  1.1.2.1     marc 	DPRINTF(("%s: %02x BATTDEAD\n", h->sc->dev.dv_xname, h->sock));
    468  1.1.2.1     marc     }
    469  1.1.2.1     marc 
    470  1.1.2.1     marc #if 0
    471  1.1.2.1     marc     /* ack the interrupt */
    472  1.1.2.1     marc 
    473  1.1.2.1     marc     pcic_write(h, PCIC_CSC, cscreg);
    474  1.1.2.1     marc #endif
    475  1.1.2.1     marc 
    476  1.1.2.1     marc     return(cscreg?1:0);
    477  1.1.2.1     marc }
    478  1.1.2.1     marc 
    479  1.1.2.1     marc void
    480  1.1.2.1     marc pcic_attach_card(h)
    481  1.1.2.1     marc      struct pcic_handle *h;
    482  1.1.2.1     marc {
    483  1.1.2.1     marc     int iftype;
    484  1.1.2.1     marc     int reg;
    485  1.1.2.1     marc 
    486  1.1.2.1     marc     if (h->flags & PCIC_FLAG_CARDP)
    487  1.1.2.1     marc 	panic("pcic_attach_card: already attached");
    488  1.1.2.1     marc 
    489  1.1.2.1     marc     /* power down the socket to reset it, clear the card reset pin */
    490  1.1.2.1     marc 
    491  1.1.2.1     marc     pcic_write(h, PCIC_PWRCTL, 0);
    492  1.1.2.1     marc 
    493  1.1.2.1     marc     /* power up the socket */
    494  1.1.2.1     marc 
    495  1.1.2.1     marc     pcic_write(h, PCIC_PWRCTL, PCIC_PWRCTL_PWR_ENABLE);
    496  1.1.2.1     marc     delay(10000);
    497  1.1.2.1     marc     pcic_write(h, PCIC_PWRCTL, PCIC_PWRCTL_PWR_ENABLE | PCIC_PWRCTL_OE);
    498  1.1.2.1     marc 
    499  1.1.2.1     marc     /* clear the reset flag */
    500  1.1.2.1     marc 
    501  1.1.2.1     marc     pcic_write(h, PCIC_INTR, PCIC_INTR_RESET);
    502  1.1.2.1     marc 
    503  1.1.2.1     marc     /* wait 20ms as per pc card standard (r2.01) section 4.3.6 */
    504  1.1.2.1     marc 
    505  1.1.2.1     marc     delay(20000);
    506  1.1.2.1     marc 
    507  1.1.2.1     marc     /* wait for the chip to finish initializing */
    508  1.1.2.1     marc 
    509  1.1.2.1     marc     pcic_wait_ready(h);
    510  1.1.2.1     marc 
    511  1.1.2.1     marc     /* zero out the address windows */
    512  1.1.2.1     marc 
    513  1.1.2.1     marc     pcic_write(h, PCIC_ADDRWIN_ENABLE, 0);
    514  1.1.2.1     marc 
    515  1.1.2.1     marc #if 1
    516  1.1.2.1     marc     pcic_write(h, PCIC_INTR, PCIC_INTR_RESET | PCIC_INTR_CARDTYPE_IO);
    517  1.1.2.1     marc #endif
    518  1.1.2.1     marc 
    519  1.1.2.1     marc     reg = pcic_read(h, PCIC_INTR);
    520  1.1.2.1     marc 
    521  1.1.2.1     marc     DPRINTF(("%s: %02x PCIC_INTR = %02x\n", h->sc->dev.dv_xname,
    522  1.1.2.1     marc 	     h->sock, reg));
    523  1.1.2.1     marc 
    524  1.1.2.1     marc     /* call the MI attach function */
    525  1.1.2.1     marc 
    526  1.1.2.1     marc     pcmcia_attach_card(h->pcmcia, &iftype);
    527  1.1.2.1     marc 
    528  1.1.2.1     marc     /* set the card type */
    529  1.1.2.1     marc 
    530  1.1.2.1     marc     DPRINTF(("%s: %02x cardtype %s\n", h->sc->dev.dv_xname, h->sock,
    531  1.1.2.1     marc 	     ((iftype == PCMCIA_IFTYPE_IO)?"io":"mem")));
    532  1.1.2.1     marc 
    533  1.1.2.1     marc #if 0
    534  1.1.2.1     marc     reg = pcic_read(h, PCIC_INTR);
    535  1.1.2.1     marc     reg &= PCIC_INTR_CARDTYPE_MASK;
    536  1.1.2.1     marc     reg |= ((iftype == PCMCIA_IFTYPE_IO)?
    537  1.1.2.1     marc 	    PCIC_INTR_CARDTYPE_IO:
    538  1.1.2.1     marc 	    PCIC_INTR_CARDTYPE_MEM);
    539  1.1.2.1     marc     pcic_write(h, PCIC_INTR, reg);
    540  1.1.2.1     marc #endif
    541  1.1.2.1     marc 
    542  1.1.2.1     marc     h->flags |= PCIC_FLAG_CARDP;
    543  1.1.2.1     marc }
    544  1.1.2.1     marc 
    545  1.1.2.1     marc void
    546  1.1.2.1     marc pcic_detach_card(h)
    547  1.1.2.1     marc      struct pcic_handle *h;
    548  1.1.2.1     marc {
    549  1.1.2.1     marc     if (!(h->flags & PCIC_FLAG_CARDP))
    550  1.1.2.1     marc 	panic("pcic_attach_card: already attached");
    551  1.1.2.1     marc 
    552  1.1.2.1     marc     h->flags &= ~PCIC_FLAG_CARDP;
    553  1.1.2.1     marc 
    554  1.1.2.1     marc     /* call the MI attach function */
    555  1.1.2.1     marc 
    556  1.1.2.1     marc     pcmcia_detach_card(h->pcmcia);
    557  1.1.2.1     marc 
    558  1.1.2.1     marc     /* disable card detect resume and configuration reset */
    559  1.1.2.1     marc 
    560  1.1.2.1     marc #if 0
    561  1.1.2.1     marc     pcic_write(h, PCIC_CARD_DETECT, 0);
    562  1.1.2.1     marc #endif
    563  1.1.2.1     marc 
    564  1.1.2.1     marc     /* power down the socket */
    565  1.1.2.1     marc 
    566  1.1.2.1     marc     pcic_write(h, PCIC_PWRCTL, 0);
    567  1.1.2.1     marc 
    568  1.1.2.1     marc     /* reset the card */
    569  1.1.2.1     marc 
    570  1.1.2.1     marc     pcic_write(h, PCIC_INTR, 0);
    571  1.1.2.1     marc }
    572  1.1.2.1     marc 
    573  1.1.2.4  thorpej int pcic_chip_mem_alloc(pch, size, pcmhp)
    574  1.1.2.1     marc      pcmcia_chipset_handle_t pch;
    575  1.1.2.1     marc      bus_size_t size;
    576  1.1.2.4  thorpej      struct pcmcia_mem_handle *pcmhp;
    577  1.1.2.1     marc {
    578  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) pch;
    579  1.1.2.4  thorpej     bus_space_handle_t memh;
    580  1.1.2.4  thorpej     bus_addr_t addr;
    581  1.1.2.4  thorpej     bus_size_t sizepg;
    582  1.1.2.4  thorpej     int i, mask, mhandle;
    583  1.1.2.1     marc 
    584  1.1.2.1     marc     /* out of sc->memh, allocate as many pages as necessary */
    585  1.1.2.1     marc 
    586  1.1.2.4  thorpej     /* convert size to PCIC pages */
    587  1.1.2.4  thorpej     sizepg = (size + (PCIC_MEM_ALIGN - 1)) / PCIC_MEM_ALIGN;
    588  1.1.2.1     marc 
    589  1.1.2.4  thorpej     mask = (1 << sizepg) - 1;
    590  1.1.2.1     marc 
    591  1.1.2.4  thorpej     addr = 0;		/* XXX gcc -Wuninitialized */
    592  1.1.2.4  thorpej     mhandle = 0;	/* XXX gcc -Wuninitialized */
    593  1.1.2.8     marc 
    594  1.1.2.4  thorpej     for (i=0; i<(PCIC_MEM_PAGES+1-sizepg); i++) {
    595  1.1.2.1     marc 	if ((h->sc->subregionmask & (mask<<i)) == (mask<<i)) {
    596  1.1.2.1     marc 	    if (bus_space_subregion(h->sc->memt, h->sc->memh,
    597  1.1.2.1     marc 				    i*PCIC_MEM_PAGESIZE,
    598  1.1.2.4  thorpej 				    sizepg*PCIC_MEM_PAGESIZE, &memh))
    599  1.1.2.1     marc 		return(1);
    600  1.1.2.4  thorpej 	    mhandle = mask << i;
    601  1.1.2.4  thorpej 	    addr = h->sc->membase + (i * PCIC_MEM_PAGESIZE);
    602  1.1.2.4  thorpej 	    h->sc->subregionmask &= ~(mhandle);
    603  1.1.2.1     marc 	    break;
    604  1.1.2.1     marc 	}
    605  1.1.2.1     marc     }
    606  1.1.2.1     marc 
    607  1.1.2.1     marc     if (i == (PCIC_MEM_PAGES+1-size))
    608  1.1.2.1     marc 	return(1);
    609  1.1.2.1     marc 
    610  1.1.2.4  thorpej     DPRINTF(("pcic_chip_mem_alloc bus addr 0x%lx+0x%lx\n", (u_long)addr,
    611  1.1.2.4  thorpej              (u_long)size));
    612  1.1.2.4  thorpej 
    613  1.1.2.4  thorpej     pcmhp->memt = h->sc->memt;
    614  1.1.2.4  thorpej     pcmhp->memh = memh;
    615  1.1.2.4  thorpej     pcmhp->addr = addr;
    616  1.1.2.4  thorpej     pcmhp->size = size;
    617  1.1.2.4  thorpej     pcmhp->mhandle = mhandle;
    618  1.1.2.4  thorpej     pcmhp->realsize = sizepg * PCIC_MEM_PAGESIZE;
    619  1.1.2.1     marc 
    620  1.1.2.1     marc     return(0);
    621  1.1.2.1     marc }
    622  1.1.2.1     marc 
    623  1.1.2.4  thorpej void pcic_chip_mem_free(pch, pcmhp)
    624  1.1.2.1     marc      pcmcia_chipset_handle_t pch;
    625  1.1.2.4  thorpej      struct pcmcia_mem_handle *pcmhp;
    626  1.1.2.1     marc {
    627  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) pch;
    628  1.1.2.1     marc 
    629  1.1.2.4  thorpej     h->sc->subregionmask |= pcmhp->mhandle;
    630  1.1.2.1     marc }
    631  1.1.2.1     marc 
    632  1.1.2.1     marc static struct mem_map_index_st {
    633  1.1.2.1     marc     int sysmem_start_lsb;
    634  1.1.2.1     marc     int sysmem_start_msb;
    635  1.1.2.1     marc     int sysmem_stop_lsb;
    636  1.1.2.1     marc     int sysmem_stop_msb;
    637  1.1.2.1     marc     int cardmem_lsb;
    638  1.1.2.1     marc     int cardmem_msb;
    639  1.1.2.1     marc     int memenable;
    640  1.1.2.1     marc } mem_map_index[] = {
    641  1.1.2.1     marc     {
    642  1.1.2.1     marc 	PCIC_SYSMEM_ADDR0_START_LSB,
    643  1.1.2.1     marc 	PCIC_SYSMEM_ADDR0_START_MSB,
    644  1.1.2.1     marc 	PCIC_SYSMEM_ADDR0_STOP_LSB,
    645  1.1.2.1     marc 	PCIC_SYSMEM_ADDR0_STOP_MSB,
    646  1.1.2.1     marc 	PCIC_CARDMEM_ADDR0_LSB,
    647  1.1.2.1     marc 	PCIC_CARDMEM_ADDR0_MSB,
    648  1.1.2.1     marc 	PCIC_ADDRWIN_ENABLE_MEM0,
    649  1.1.2.1     marc     },
    650  1.1.2.1     marc     {
    651  1.1.2.1     marc 	PCIC_SYSMEM_ADDR1_START_LSB,
    652  1.1.2.1     marc 	PCIC_SYSMEM_ADDR1_START_MSB,
    653  1.1.2.1     marc 	PCIC_SYSMEM_ADDR1_STOP_LSB,
    654  1.1.2.1     marc 	PCIC_SYSMEM_ADDR1_STOP_MSB,
    655  1.1.2.1     marc 	PCIC_CARDMEM_ADDR1_LSB,
    656  1.1.2.1     marc 	PCIC_CARDMEM_ADDR1_MSB,
    657  1.1.2.1     marc 	PCIC_ADDRWIN_ENABLE_MEM1,
    658  1.1.2.1     marc     },
    659  1.1.2.1     marc     {
    660  1.1.2.1     marc 	PCIC_SYSMEM_ADDR2_START_LSB,
    661  1.1.2.1     marc 	PCIC_SYSMEM_ADDR2_START_MSB,
    662  1.1.2.1     marc 	PCIC_SYSMEM_ADDR2_STOP_LSB,
    663  1.1.2.1     marc 	PCIC_SYSMEM_ADDR2_STOP_MSB,
    664  1.1.2.1     marc 	PCIC_CARDMEM_ADDR2_LSB,
    665  1.1.2.1     marc 	PCIC_CARDMEM_ADDR2_MSB,
    666  1.1.2.1     marc 	PCIC_ADDRWIN_ENABLE_MEM2,
    667  1.1.2.1     marc     },
    668  1.1.2.1     marc     {
    669  1.1.2.1     marc 	PCIC_SYSMEM_ADDR3_START_LSB,
    670  1.1.2.1     marc 	PCIC_SYSMEM_ADDR3_START_MSB,
    671  1.1.2.1     marc 	PCIC_SYSMEM_ADDR3_STOP_LSB,
    672  1.1.2.1     marc 	PCIC_SYSMEM_ADDR3_STOP_MSB,
    673  1.1.2.1     marc 	PCIC_CARDMEM_ADDR3_LSB,
    674  1.1.2.1     marc 	PCIC_CARDMEM_ADDR3_MSB,
    675  1.1.2.1     marc 	PCIC_ADDRWIN_ENABLE_MEM3,
    676  1.1.2.1     marc     },
    677  1.1.2.1     marc     {
    678  1.1.2.1     marc 	PCIC_SYSMEM_ADDR4_START_LSB,
    679  1.1.2.1     marc 	PCIC_SYSMEM_ADDR4_START_MSB,
    680  1.1.2.1     marc 	PCIC_SYSMEM_ADDR4_STOP_LSB,
    681  1.1.2.1     marc 	PCIC_SYSMEM_ADDR4_STOP_MSB,
    682  1.1.2.1     marc 	PCIC_CARDMEM_ADDR4_LSB,
    683  1.1.2.1     marc 	PCIC_CARDMEM_ADDR4_MSB,
    684  1.1.2.1     marc 	PCIC_ADDRWIN_ENABLE_MEM4,
    685  1.1.2.1     marc     },
    686  1.1.2.1     marc };
    687  1.1.2.1     marc 
    688  1.1.2.4  thorpej int pcic_chip_mem_map(pch, kind, card_addr, size, pcmhp, offsetp, windowp)
    689  1.1.2.1     marc      pcmcia_chipset_handle_t pch;
    690  1.1.2.1     marc      int kind;
    691  1.1.2.4  thorpej      bus_addr_t card_addr;
    692  1.1.2.1     marc      bus_size_t size;
    693  1.1.2.4  thorpej      struct pcmcia_mem_handle *pcmhp;
    694  1.1.2.4  thorpej      bus_addr_t *offsetp;
    695  1.1.2.4  thorpej      int *windowp;
    696  1.1.2.1     marc {
    697  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) pch;
    698  1.1.2.1     marc     int reg;
    699  1.1.2.4  thorpej     bus_addr_t busaddr;
    700  1.1.2.1     marc     long card_offset;
    701  1.1.2.1     marc     int i, win;
    702  1.1.2.1     marc 
    703  1.1.2.1     marc     win = -1;
    704  1.1.2.1     marc     for (i=0; i<(sizeof(mem_map_index)/sizeof(mem_map_index[0])); i++) {
    705  1.1.2.1     marc 	if ((h->memalloc & (1<<i)) == 0) {
    706  1.1.2.1     marc 	    win = i;
    707  1.1.2.1     marc 	    h->memalloc |= (1<<i);
    708  1.1.2.1     marc 	    break;
    709  1.1.2.1     marc 	}
    710  1.1.2.1     marc     }
    711  1.1.2.1     marc 
    712  1.1.2.1     marc     if (win == -1)
    713  1.1.2.1     marc 	return(1);
    714  1.1.2.1     marc 
    715  1.1.2.4  thorpej     *windowp = win;
    716  1.1.2.1     marc 
    717  1.1.2.1     marc     /* XXX this is pretty gross */
    718  1.1.2.1     marc 
    719  1.1.2.4  thorpej     if (h->sc->memt != pcmhp->memt)
    720  1.1.2.1     marc 	panic("pcic_chip_mem_map memt is bogus");
    721  1.1.2.1     marc 
    722  1.1.2.4  thorpej     busaddr = pcmhp->addr;
    723  1.1.2.1     marc 
    724  1.1.2.1     marc     /* compute the address offset to the pcmcia address space for the
    725  1.1.2.1     marc        pcic.  this is intentionally signed.  The masks and shifts
    726  1.1.2.1     marc        below will cause TRT to happen in the pcic registers.  Deal with
    727  1.1.2.1     marc        making sure the address is aligned, and return the alignment
    728  1.1.2.1     marc        offset.  */
    729  1.1.2.1     marc 
    730  1.1.2.4  thorpej     *offsetp = card_addr % PCIC_MEM_ALIGN;
    731  1.1.2.4  thorpej     card_addr -= *offsetp;
    732  1.1.2.1     marc 
    733  1.1.2.4  thorpej     DPRINTF(("pcic_chip_mem_map window %d bus %lx+%lx+%lx at card addr %lx\n",
    734  1.1.2.4  thorpej 	     win, (u_long)busaddr, (u_long)*offsetp, (u_long)size,
    735  1.1.2.4  thorpej 	     (u_long)card_addr));
    736  1.1.2.1     marc 
    737  1.1.2.1     marc     /* include the offset in the size, and decrement size by one,
    738  1.1.2.1     marc        since the hw wants start/stop */
    739  1.1.2.4  thorpej     size += *offsetp - 1;
    740  1.1.2.1     marc 
    741  1.1.2.4  thorpej     card_offset = (((long) card_addr) - ((long) busaddr));
    742  1.1.2.1     marc 
    743  1.1.2.1     marc     pcic_write(h, mem_map_index[win].sysmem_start_lsb,
    744  1.1.2.4  thorpej 	       (busaddr >> PCIC_SYSMEM_ADDRX_SHIFT) & 0xff);
    745  1.1.2.1     marc     pcic_write(h, mem_map_index[win].sysmem_start_msb,
    746  1.1.2.4  thorpej 	       ((busaddr >> (PCIC_SYSMEM_ADDRX_SHIFT + 8)) &
    747  1.1.2.1     marc 		PCIC_SYSMEM_ADDRX_START_MSB_ADDR_MASK));
    748  1.1.2.1     marc 
    749  1.1.2.1     marc #if 0
    750  1.1.2.1     marc     /* XXX do I want 16 bit all the time? */
    751  1.1.2.1     marc     PCIC_SYSMEM_ADDRX_START_MSB_DATASIZE_16BIT;
    752  1.1.2.1     marc #endif
    753  1.1.2.1     marc 
    754  1.1.2.1     marc     pcic_write(h, mem_map_index[win].sysmem_stop_lsb,
    755  1.1.2.4  thorpej 	       ((busaddr + size) >> PCIC_SYSMEM_ADDRX_SHIFT) & 0xff);
    756  1.1.2.1     marc     pcic_write(h, mem_map_index[win].sysmem_stop_msb,
    757  1.1.2.4  thorpej 	       (((busaddr + size) >> (PCIC_SYSMEM_ADDRX_SHIFT + 8)) &
    758  1.1.2.1     marc 		PCIC_SYSMEM_ADDRX_STOP_MSB_ADDR_MASK) |
    759  1.1.2.1     marc 	       PCIC_SYSMEM_ADDRX_STOP_MSB_WAIT2);
    760  1.1.2.1     marc 
    761  1.1.2.1     marc 
    762  1.1.2.1     marc     pcic_write(h, mem_map_index[win].cardmem_lsb,
    763  1.1.2.1     marc 	       (card_offset >> PCIC_CARDMEM_ADDRX_SHIFT) & 0xff);
    764  1.1.2.1     marc     pcic_write(h, mem_map_index[win].cardmem_msb,
    765  1.1.2.1     marc 	       ((card_offset >> (PCIC_CARDMEM_ADDRX_SHIFT + 8)) &
    766  1.1.2.1     marc 		PCIC_CARDMEM_ADDRX_MSB_ADDR_MASK) |
    767  1.1.2.1     marc 	       ((kind == PCMCIA_MEM_ATTR)?
    768  1.1.2.1     marc 		PCIC_CARDMEM_ADDRX_MSB_REGACTIVE_ATTR:0));
    769  1.1.2.1     marc 
    770  1.1.2.1     marc     reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
    771  1.1.2.1     marc     reg |= (mem_map_index[win].memenable | PCIC_ADDRWIN_ENABLE_MEMCS16 );
    772  1.1.2.1     marc     pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
    773  1.1.2.1     marc 
    774  1.1.2.1     marc #ifdef PCICDEBUG
    775  1.1.2.1     marc     {
    776  1.1.2.1     marc 	int r1,r2,r3,r4,r5,r6;
    777  1.1.2.1     marc 
    778  1.1.2.1     marc 	r1 = pcic_read(h, mem_map_index[win].sysmem_start_msb);
    779  1.1.2.1     marc 	r2 = pcic_read(h, mem_map_index[win].sysmem_start_lsb);
    780  1.1.2.1     marc 	r3 = pcic_read(h, mem_map_index[win].sysmem_stop_msb);
    781  1.1.2.1     marc 	r4 = pcic_read(h, mem_map_index[win].sysmem_stop_lsb);
    782  1.1.2.1     marc 	r5 = pcic_read(h, mem_map_index[win].cardmem_msb);
    783  1.1.2.1     marc 	r6 = pcic_read(h, mem_map_index[win].cardmem_lsb);
    784  1.1.2.1     marc 
    785  1.1.2.1     marc 	DPRINTF(("pcic_chip_mem_map window %d: %02x%02x %02x%02x %02x%02x\n",
    786  1.1.2.1     marc 		 win, r1, r2, r3, r4, r5, r6));
    787  1.1.2.1     marc     }
    788  1.1.2.1     marc #endif
    789  1.1.2.1     marc 
    790  1.1.2.1     marc     return(0);
    791  1.1.2.1     marc }
    792  1.1.2.1     marc 
    793  1.1.2.1     marc void pcic_chip_mem_unmap(pch, window)
    794  1.1.2.1     marc      pcmcia_chipset_handle_t pch;
    795  1.1.2.1     marc      int window;
    796  1.1.2.1     marc {
    797  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) pch;
    798  1.1.2.1     marc     int reg;
    799  1.1.2.1     marc 
    800  1.1.2.1     marc     if (window >= (sizeof(mem_map_index)/sizeof(mem_map_index[0])))
    801  1.1.2.1     marc 	panic("pcic_chip_mem_unmap: window out of range");
    802  1.1.2.1     marc 
    803  1.1.2.1     marc     reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
    804  1.1.2.1     marc     reg &= ~mem_map_index[window].memenable;
    805  1.1.2.1     marc     pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
    806  1.1.2.1     marc 
    807  1.1.2.4  thorpej     h->memalloc &= ~(1 << window);
    808  1.1.2.1     marc }
    809  1.1.2.1     marc 
    810  1.1.2.1     marc 
    811  1.1.2.6      jtk /* XXX mycroft recommends this I/O space range.  I should put this
    812  1.1.2.6      jtk    in a header somewhere */
    813  1.1.2.6      jtk 
    814  1.1.2.6      jtk /* XXX some hardware doesn't seem to grok addresses in 0x400 range--
    815  1.1.2.6      jtk    apparently missing a bit or more of address lines.
    816  1.1.2.6      jtk    (e.g. CIRRUS_PD672X with Linksys EthernetCard ne2000 clone in TI
    817  1.1.2.6      jtk    TravelMate 5000--not clear which is at fault)
    818  1.1.2.6      jtk 
    819  1.1.2.6      jtk    Allow them to be overridden by patching a kernel and/or by a config
    820  1.1.2.6      jtk    file option */
    821  1.1.2.6      jtk 
    822  1.1.2.6      jtk #ifndef PCIC_ALLOC_IOBASE
    823  1.1.2.6      jtk #define PCIC_ALLOC_IOBASE 0x400
    824  1.1.2.6      jtk #endif
    825  1.1.2.6      jtk 
    826  1.1.2.6      jtk int pcic_alloc_iobase = PCIC_ALLOC_IOBASE;
    827  1.1.2.6      jtk 
    828  1.1.2.4  thorpej int pcic_chip_io_alloc(pch, start, size, pcihp)
    829  1.1.2.1     marc      pcmcia_chipset_handle_t pch;
    830  1.1.2.1     marc      bus_addr_t start;
    831  1.1.2.1     marc      bus_size_t size;
    832  1.1.2.4  thorpej      struct pcmcia_io_handle *pcihp;
    833  1.1.2.1     marc {
    834  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) pch;
    835  1.1.2.4  thorpej     bus_space_tag_t iot;
    836  1.1.2.4  thorpej     bus_space_handle_t ioh;
    837  1.1.2.1     marc     bus_addr_t ioaddr;
    838  1.1.2.4  thorpej     int flags = 0;
    839  1.1.2.1     marc 
    840  1.1.2.1     marc     /*
    841  1.1.2.8     marc      * Allocate some arbitrary I/O space.
    842  1.1.2.1     marc      */
    843  1.1.2.1     marc 
    844  1.1.2.4  thorpej     iot = h->sc->iot;
    845  1.1.2.1     marc 
    846  1.1.2.1     marc     if (start) {
    847  1.1.2.4  thorpej 	ioaddr = start;
    848  1.1.2.4  thorpej 	if (bus_space_map(iot, start, size, 0, &ioh))
    849  1.1.2.1     marc 	    return(1);
    850  1.1.2.1     marc 	DPRINTF(("pcic_chip_io_alloc map port %lx+%lx\n",
    851  1.1.2.4  thorpej 		 (u_long) ioaddr, (u_long) size));
    852  1.1.2.1     marc     } else {
    853  1.1.2.4  thorpej 	flags |= PCMCIA_IO_ALLOCATED;
    854  1.1.2.6      jtk 	if (bus_space_alloc(iot, pcic_alloc_iobase, 0xfff, size, size,
    855  1.1.2.4  thorpej 			    0, 0, &ioaddr, &ioh))
    856  1.1.2.1     marc 	    return(1);
    857  1.1.2.1     marc 	DPRINTF(("pcic_chip_io_alloc alloc port %lx+%lx\n",
    858  1.1.2.1     marc 		 (u_long) ioaddr, (u_long) size));
    859  1.1.2.1     marc     }
    860  1.1.2.1     marc 
    861  1.1.2.4  thorpej     pcihp->iot = iot;
    862  1.1.2.4  thorpej     pcihp->ioh = ioh;
    863  1.1.2.4  thorpej     pcihp->addr = ioaddr;
    864  1.1.2.4  thorpej     pcihp->size = size;
    865  1.1.2.4  thorpej     pcihp->flags = flags;
    866  1.1.2.4  thorpej 
    867  1.1.2.1     marc     return(0);
    868  1.1.2.1     marc }
    869  1.1.2.1     marc 
    870  1.1.2.4  thorpej void pcic_chip_io_free(pch, pcihp)
    871  1.1.2.1     marc      pcmcia_chipset_handle_t pch;
    872  1.1.2.4  thorpej      struct pcmcia_io_handle *pcihp;
    873  1.1.2.1     marc {
    874  1.1.2.4  thorpej     bus_space_tag_t iot = pcihp->iot;
    875  1.1.2.4  thorpej     bus_space_handle_t ioh = pcihp->ioh;
    876  1.1.2.4  thorpej     bus_size_t size = pcihp->size;
    877  1.1.2.4  thorpej 
    878  1.1.2.4  thorpej     if (pcihp->flags & PCMCIA_IO_ALLOCATED)
    879  1.1.2.4  thorpej 	bus_space_free(iot, ioh, size);
    880  1.1.2.4  thorpej     else
    881  1.1.2.4  thorpej 	bus_space_unmap(iot, ioh, size);
    882  1.1.2.1     marc }
    883  1.1.2.1     marc 
    884  1.1.2.1     marc 
    885  1.1.2.1     marc static struct io_map_index_st {
    886  1.1.2.1     marc     int start_lsb;
    887  1.1.2.1     marc     int start_msb;
    888  1.1.2.1     marc     int stop_lsb;
    889  1.1.2.1     marc     int stop_msb;
    890  1.1.2.1     marc     int ioenable;
    891  1.1.2.1     marc     int ioctlmask;
    892  1.1.2.1     marc     int ioctl8;
    893  1.1.2.1     marc     int ioctl16;
    894  1.1.2.1     marc } io_map_index[] = {
    895  1.1.2.1     marc     {
    896  1.1.2.1     marc 	PCIC_IOADDR0_START_LSB,
    897  1.1.2.1     marc 	PCIC_IOADDR0_START_MSB,
    898  1.1.2.1     marc 	PCIC_IOADDR0_STOP_LSB,
    899  1.1.2.1     marc 	PCIC_IOADDR0_STOP_MSB,
    900  1.1.2.1     marc 	PCIC_ADDRWIN_ENABLE_IO0,
    901  1.1.2.1     marc 	PCIC_IOCTL_IO0_WAITSTATE | PCIC_IOCTL_IO0_ZEROWAIT |
    902  1.1.2.1     marc 	PCIC_IOCTL_IO0_IOCS16SRC_MASK | PCIC_IOCTL_IO0_DATASIZE_MASK,
    903  1.1.2.1     marc 	PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE | PCIC_IOCTL_IO0_DATASIZE_8BIT,
    904  1.1.2.1     marc 	PCIC_IOCTL_IO0_IOCS16SRC_DATASIZE | PCIC_IOCTL_IO0_DATASIZE_16BIT,
    905  1.1.2.1     marc     },
    906  1.1.2.1     marc     {
    907  1.1.2.1     marc 	PCIC_IOADDR1_START_LSB,
    908  1.1.2.1     marc 	PCIC_IOADDR1_START_MSB,
    909  1.1.2.1     marc 	PCIC_IOADDR1_STOP_LSB,
    910  1.1.2.1     marc 	PCIC_IOADDR1_STOP_MSB,
    911  1.1.2.1     marc 	PCIC_ADDRWIN_ENABLE_IO1,
    912  1.1.2.1     marc 	PCIC_IOCTL_IO1_WAITSTATE | PCIC_IOCTL_IO1_ZEROWAIT |
    913  1.1.2.1     marc 	PCIC_IOCTL_IO1_IOCS16SRC_MASK | PCIC_IOCTL_IO1_DATASIZE_MASK,
    914  1.1.2.1     marc 	PCIC_IOCTL_IO1_IOCS16SRC_DATASIZE | PCIC_IOCTL_IO1_DATASIZE_8BIT,
    915  1.1.2.1     marc 	PCIC_IOCTL_IO1_IOCS16SRC_DATASIZE | PCIC_IOCTL_IO1_DATASIZE_16BIT,
    916  1.1.2.1     marc     },
    917  1.1.2.1     marc };
    918  1.1.2.1     marc 
    919  1.1.2.4  thorpej int pcic_chip_io_map(pch, width, offset, size, pcihp, windowp)
    920  1.1.2.1     marc      pcmcia_chipset_handle_t pch;
    921  1.1.2.1     marc      int width;
    922  1.1.2.4  thorpej      bus_addr_t offset;
    923  1.1.2.1     marc      bus_size_t size;
    924  1.1.2.4  thorpej      struct pcmcia_io_handle *pcihp;
    925  1.1.2.4  thorpej      int *windowp;
    926  1.1.2.1     marc {
    927  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) pch;
    928  1.1.2.4  thorpej     bus_addr_t ioaddr = pcihp->addr + offset;
    929  1.1.2.1     marc     int reg;
    930  1.1.2.1     marc     int i, win;
    931  1.1.2.1     marc 
    932  1.1.2.4  thorpej     /* XXX Sanity check offset/size. */
    933  1.1.2.4  thorpej 
    934  1.1.2.1     marc     win = -1;
    935  1.1.2.1     marc     for (i=0; i<(sizeof(io_map_index)/sizeof(io_map_index[0])); i++) {
    936  1.1.2.1     marc 	if ((h->ioalloc & (1<<i)) == 0) {
    937  1.1.2.1     marc 	    win = i;
    938  1.1.2.1     marc 	    h->ioalloc |= (1<<i);
    939  1.1.2.1     marc 	    break;
    940  1.1.2.1     marc 	}
    941  1.1.2.1     marc     }
    942  1.1.2.1     marc 
    943  1.1.2.1     marc     if (win == -1)
    944  1.1.2.1     marc 	return(1);
    945  1.1.2.1     marc 
    946  1.1.2.4  thorpej     *windowp = win;
    947  1.1.2.1     marc 
    948  1.1.2.1     marc     /* XXX this is pretty gross */
    949  1.1.2.1     marc 
    950  1.1.2.4  thorpej     if (h->sc->iot != pcihp->iot)
    951  1.1.2.1     marc 	panic("pcic_chip_io_map iot is bogus");
    952  1.1.2.1     marc 
    953  1.1.2.1     marc     DPRINTF(("pcic_chip_io_map window %d %s port %lx+%lx\n",
    954  1.1.2.1     marc 	     win, (width == PCMCIA_WIDTH_IO8)?"io8":"io16",
    955  1.1.2.4  thorpej 	     (u_long) ioaddr, (u_long) size));
    956  1.1.2.1     marc 
    957  1.1.2.6      jtk     printf(" port 0x%lx", (u_long)ioaddr);
    958  1.1.2.6      jtk     if (size > 1)
    959  1.1.2.6      jtk 	printf("-0x%lx", (u_long)ioaddr + (u_long)size - 1);
    960  1.1.2.6      jtk 
    961  1.1.2.4  thorpej     pcic_write(h, io_map_index[win].start_lsb, ioaddr & 0xff);
    962  1.1.2.4  thorpej     pcic_write(h, io_map_index[win].start_msb, (ioaddr >> 8) & 0xff);
    963  1.1.2.1     marc 
    964  1.1.2.4  thorpej     pcic_write(h, io_map_index[win].stop_lsb, (ioaddr + size - 1) & 0xff);
    965  1.1.2.4  thorpej     pcic_write(h, io_map_index[win].stop_msb,
    966  1.1.2.4  thorpej     	       ((ioaddr + size - 1) >> 8) & 0xff);
    967  1.1.2.1     marc 
    968  1.1.2.1     marc     reg = pcic_read(h, PCIC_IOCTL);
    969  1.1.2.1     marc     reg &= ~io_map_index[win].ioctlmask;
    970  1.1.2.1     marc     if (width == PCMCIA_WIDTH_IO8)
    971  1.1.2.1     marc 	reg |= io_map_index[win].ioctl8;
    972  1.1.2.1     marc     else
    973  1.1.2.1     marc 	reg |= io_map_index[win].ioctl16;
    974  1.1.2.1     marc     pcic_write(h, PCIC_IOCTL, reg);
    975  1.1.2.1     marc 
    976  1.1.2.1     marc     reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
    977  1.1.2.1     marc     reg |= io_map_index[win].ioenable;
    978  1.1.2.1     marc     pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
    979  1.1.2.1     marc 
    980  1.1.2.1     marc     return(0);
    981  1.1.2.1     marc }
    982  1.1.2.1     marc 
    983  1.1.2.1     marc void pcic_chip_io_unmap(pch, window)
    984  1.1.2.1     marc      pcmcia_chipset_handle_t pch;
    985  1.1.2.1     marc      int window;
    986  1.1.2.1     marc {
    987  1.1.2.1     marc     struct pcic_handle *h = (struct pcic_handle *) pch;
    988  1.1.2.1     marc     int reg;
    989  1.1.2.1     marc 
    990  1.1.2.1     marc     if (window >= (sizeof(io_map_index)/sizeof(io_map_index[0])))
    991  1.1.2.1     marc 	panic("pcic_chip_io_unmap: window out of range");
    992  1.1.2.1     marc 
    993  1.1.2.1     marc     reg = pcic_read(h, PCIC_ADDRWIN_ENABLE);
    994  1.1.2.1     marc     reg &= ~io_map_index[window].ioenable;
    995  1.1.2.1     marc     pcic_write(h, PCIC_ADDRWIN_ENABLE, reg);
    996  1.1.2.1     marc 
    997  1.1.2.8     marc     h->ioalloc &= ~(1<<window);
    998  1.1.2.7  thorpej }
    999  1.1.2.7  thorpej 
   1000  1.1.2.7  thorpej void
   1001  1.1.2.7  thorpej pcic_chip_socket_enable(pch)
   1002  1.1.2.7  thorpej      pcmcia_chipset_handle_t pch;
   1003  1.1.2.7  thorpej {
   1004  1.1.2.7  thorpej }
   1005  1.1.2.7  thorpej 
   1006  1.1.2.7  thorpej void
   1007  1.1.2.7  thorpej pcic_chip_socket_disable(pch)
   1008  1.1.2.7  thorpej      pcmcia_chipset_handle_t pch;
   1009  1.1.2.7  thorpej {
   1010  1.1.2.1     marc }
   1011