Home | History | Annotate | Line # | Download | only in podulebus
podulebus.c revision 1.13
      1 /* $NetBSD: podulebus.c,v 1.13 2002/10/02 02:23:52 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1994-1996 Mark Brinicombe.
      5  * Copyright (c) 1994 Brini.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by Brini.
     19  * 4. The name of the company nor the name of the author may be used to
     20  *    endorse or promote products derived from this software without specific
     21  *    prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
     24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  * RiscBSD kernel project
     36  *
     37  * podulebus.c
     38  *
     39  * Podule probe and configuration routines
     40  *
     41  * Created      : 07/11/94
     42  */
     43 
     44 #include <sys/param.h>
     45 
     46 __KERNEL_RCSID(0, "$NetBSD: podulebus.c,v 1.13 2002/10/02 02:23:52 thorpej Exp $");
     47 
     48 #include <sys/systm.h>
     49 #include <sys/kernel.h>
     50 #include <sys/conf.h>
     51 #include <sys/malloc.h>
     52 #include <sys/device.h>
     53 #include <uvm/uvm_extern.h>
     54 #include <machine/io.h>
     55 #include <arm/arm32/katelib.h>
     56 #include <machine/intr.h>
     57 #include <machine/bootconfig.h>
     58 #include <machine/pmap.h>
     59 #include <arm/iomd/iomdreg.h>
     60 #include <arm/iomd/iomdvar.h>
     61 #include <acorn32/podulebus/podulebus.h>
     62 #include <dev/podulebus/podules.h>
     63 #include <dev/podulebus/podule_data.h>
     64 
     65 #include "locators.h"
     66 
     67 /* Array of podule structures, one per possible podule */
     68 
     69 podule_t podules[MAX_PODULES + MAX_NETSLOTS];
     70 
     71 extern struct bus_space podulebus_bs_tag;
     72 
     73 /* Declare prototypes */
     74 
     75 u_int poduleread __P((u_int, int));
     76 int podulebusmatch(struct device *, struct cfdata *, void *);
     77 void podulebusattach(struct device *, struct device *, void *);
     78 int podulebusprint(void *, const char *);
     79 int podulebussubmatch(struct device *, struct cfdata *, void *);
     80 void podulechunkdirectory(podule_t *);
     81 void podulescan(struct device *);
     82 
     83 /*
     84  * int podulebusmatch(struct device *parent, void *match, void *aux)
     85  *
     86  * Probe for the podule bus. Currently all this does is return 1 to
     87  * indicate that the podule bus was found.
     88  */
     89 
     90 int
     91 podulebusmatch(parent, cf, aux)
     92 	struct device *parent;
     93 	struct cfdata *cf;
     94 	void *aux;
     95 {
     96 	switch (IOMD_ID) {
     97 	case RPC600_IOMD_ID:
     98 	case ARM7500_IOC_ID:
     99 	case ARM7500FE_IOC_ID:
    100 		return(1);
    101 	}
    102 	return (0);
    103 }
    104 
    105 
    106 int
    107 podulebusprint(aux, name)
    108 	void *aux;
    109 	const char *name;
    110 {
    111 	struct podule_attach_args *pa = aux;
    112 
    113 	if (name)
    114 		printf("podule at %s", name);
    115 	if (pa->pa_podule->slottype == SLOT_POD)
    116 		printf(" slot %d", pa->pa_podule_number);
    117 	else if (pa->pa_podule->slottype == SLOT_NET)
    118 		printf(" [ netslot %d ]", pa->pa_podule_number - MAX_PODULES);
    119 #ifdef DIAGNOSTIC
    120 	else
    121 		panic("Invalid slot type");
    122 #endif
    123 
    124 	return (UNCONF);
    125 }
    126 
    127 
    128 int
    129 podulebussubmatch(parent, cf, aux)
    130 	struct device *parent;
    131 	struct cfdata *cf;
    132 	void *aux;
    133 {
    134 	struct podule_attach_args *pa = aux;
    135 
    136 	/* Return priority 0 or 1 for wildcarded podule */
    137 
    138 	if (cf->cf_loc[PODULEBUSCF_SLOT] == PODULEBUSCF_SLOT_DEFAULT)
    139 		return(config_match(parent, cf, aux));
    140 
    141 	/* Return higher priority if we match the specific podule */
    142 
    143 	else if (cf->cf_loc[PODULEBUSCF_SLOT] == pa->pa_podule_number)
    144 		return(config_match(parent, cf, aux) * 8);
    145 
    146 	/* Fail */
    147 	return(0);
    148 }
    149 
    150 
    151 #if 0
    152 void
    153 dump_podule(podule)
    154 	podule_t *podule;
    155 {
    156 	printf("podule%d: ", podule->podulenum);
    157 	printf("flags0=%02x ", podule->flags0);
    158 	printf("flags1=%02x ", podule->flags1);
    159 	printf("reserved=%02x ", podule->reserved);
    160 	printf("product=%02x ", podule->product);
    161 	printf("manufacturer=%02x ", podule->manufacturer);
    162 	printf("country=%02x ", podule->country);
    163 	printf("irq_addr=%08x ", podule->irq_addr);
    164 	printf("irq_mask=%02x ", podule->irq_mask);
    165 	printf("fiq_addr=%08x ", podule->fiq_addr);
    166 	printf("fiq_mask=%02x ", podule->fiq_mask);
    167 	printf("fast_base=%08x ", podule->fast_base);
    168 	printf("medium_base=%08x ", podule->medium_base);
    169 	printf("slow_base=%08x ", podule->slow_base);
    170 	printf("sync_base=%08x ", podule->sync_base);
    171 	printf("mod_base=%08x ", podule->mod_base);
    172 	printf("easi_base=%08x ", podule->easi_base);
    173 	printf("attached=%d ", podule->attached);
    174 	printf("slottype=%d ", podule->slottype);
    175 	printf("podulenum=%d ", podule->podulenum);
    176 	printf("description=%s ", podule->description);
    177 	printf("\n");
    178 }
    179 #endif
    180 
    181 void
    182 podulechunkdirectory(podule)
    183 	podule_t *podule;
    184 {
    185 	u_int address;
    186 	u_int id;
    187 	u_int size;
    188 	u_int addr;
    189 	int loop;
    190 	int done_f5;
    191 
    192 	done_f5 = 0;
    193 	address = 0x40;
    194 
    195 	do {
    196 		id = podule->read_rom(podule->sync_base, address);
    197 		size = podule->read_rom(podule->sync_base, address + 4);
    198 		size |= (podule->read_rom(podule->sync_base, address + 8) << 8);
    199 		size |= (podule->read_rom(podule->sync_base, address + 12) << 16);
    200 		if (id == 0xf5) {
    201 			addr = podule->read_rom(podule->sync_base, address + 16);
    202 			addr |= (podule->read_rom(podule->sync_base, address + 20) << 8);
    203 			addr |= (podule->read_rom(podule->sync_base, address + 24) << 16);
    204 			addr |= (podule->read_rom(podule->sync_base, address + 28) << 24);
    205 			if (addr < 0x800 && done_f5 == 0) {
    206 				done_f5 = 1;
    207 				for (loop = 0; loop < size; ++loop) {
    208 					if (loop < PODULE_DESCRIPTION_LENGTH) {
    209 						podule->description[loop] =
    210 						    podule->read_rom(podule->sync_base, (addr + loop)*4);
    211 						podule->description[loop + 1] = 0;
    212 					}
    213 				}
    214 			}
    215 		}
    216 #ifdef DEBUG_CHUNK_DIR
    217 		if (id == 0xf5 || id == 0xf1 || id == 0xf2 || id == 0xf3 || id == 0xf4 || id == 0xf6) {
    218 			addr = podule->read_rom(podule->sync_base, address + 16);
    219 			addr |= (podule->read_rom(podule->sync_base, address + 20) << 8);
    220 			addr |= (podule->read_rom(podule->sync_base, address + 24) << 16);
    221 			addr |= (podule->read_rom(podule->sync_base, address + 28) << 24);
    222 			printf("<%04x.%04x.%04x.%04x>", id, address, addr, size);
    223 			if (addr < 0x800) {
    224 				for (loop = 0; loop < size; ++loop) {
    225 					printf("%c", podule->read_rom(podule->sync_base, (addr + loop)*4));
    226 				}
    227 				printf("\\n\n");
    228 			}
    229 		}
    230 #endif
    231 		address += 32;
    232 	} while (id != 0 && address < 0x800);
    233 }
    234 
    235 
    236 void
    237 poduleexamine(podule, dev, slottype)
    238 	podule_t *podule;
    239 	struct device *dev;
    240 	int slottype;
    241 {
    242 	struct manufacturer_description *man_desc;
    243 	struct podule_description *pod_desc;
    244 
    245 	/* Test to see if the podule is present */
    246 
    247 	if ((podule->flags0 & 0x02) == 0x00) {
    248 		podule->slottype = slottype;
    249 		if (slottype == SLOT_NET)
    250 			printf("netslot%d at %s : ", podule->podulenum - MAX_PODULES,
    251 			    dev->dv_xname);
    252 		else
    253 			printf("podule%d  at %s : ", podule->podulenum,
    254 			    dev->dv_xname);
    255 
    256 		/* Is it Acorn conformant ? */
    257 
    258 		if (podule->flags0 & 0x80)
    259 			printf("Non-Acorn conformant expansion card\n");
    260 		else {
    261 			int id;
    262 
    263 			/* Is it a simple podule ? */
    264 
    265 			id = (podule->flags0 >> 3) & 0x0f;
    266 			if (id != 0)
    267 				printf("Simple expansion card <%x>\n", id);
    268 			else {
    269 				/* Scan the chunk directory if present for tags we use */
    270 				if (podule->flags1 & PODULE_FLAGS_CD)
    271 					podulechunkdirectory(podule);
    272 
    273 				/* Do we know this manufacturer ? */
    274 				man_desc = known_manufacturers;
    275 				while (man_desc->description) {
    276 					if (man_desc->manufacturer_id ==
    277 					    podule->manufacturer)
    278 						break;
    279 					++man_desc;
    280 				}
    281 				if (!man_desc->description)
    282 					printf("man=%04x   : ", podule->manufacturer);
    283 				else
    284 					printf("%s : ", man_desc->description);
    285 
    286 				/* Do we know this product ? */
    287 
    288 				pod_desc = known_podules;
    289 				while (pod_desc->description) {
    290 					if (pod_desc->product_id == podule->product)
    291 						break;
    292 					++pod_desc;
    293 				}
    294 				if (!pod_desc->description)
    295 					printf("prod=%04x : ",
    296 					    podule->product);
    297 				else
    298 					printf("%s : ", pod_desc->description);
    299 				printf("%s\n", podule->description);
    300 			}
    301 		}
    302 	}
    303 }
    304 
    305 
    306 u_int
    307 poduleread(address, offset)
    308 	u_int address;
    309 	int offset;
    310 {
    311 
    312 	return(ReadByte(address + offset));
    313 }
    314 
    315 void
    316 podulescan(dev)
    317 	struct device *dev;
    318 {
    319 	int loop;
    320 	podule_t *podule;
    321 	u_char *address;
    322 	u_int offset = 0;
    323 
    324 	/* Loop round all the podules */
    325 
    326 	for (loop = 0; loop < MAX_PODULES; ++loop, offset += SIMPLE_PODULE_SIZE) {
    327 		podule = &podules[loop];
    328 		podule->podulenum = loop;
    329 		podule->attached = 0;
    330 		podule->slottype = SLOT_NONE;
    331 		podule->interrupt = IRQ_PODULE;
    332 		podule->read_rom = poduleread;
    333 		podule->dma_channel = -1;
    334 		podule->dma_interrupt = -1;
    335 		podule->description[0] = 0;
    336 
    337 		if (loop == 4) offset += PODULE_GAP;
    338 		address = ((u_char *)SYNC_PODULE_BASE) + offset;
    339 
    340 		if ((address[0] & 0x02) == 0x00) {
    341 			podule->fast_base = FAST_PODULE_BASE + offset;
    342 			podule->medium_base = MEDIUM_PODULE_BASE + offset;
    343 			podule->slow_base = SLOW_PODULE_BASE + offset;
    344 			podule->sync_base = SYNC_PODULE_BASE + offset;
    345 			podule->mod_base = MOD_PODULE_BASE + offset;
    346 			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
    347 		} else {
    348 			address = ((u_char *)EASI_BASE) + loop * EASI_SIZE;
    349 			if ((address[0] & 0x02) != 0x00)
    350 				continue;
    351 
    352 			podule->fast_base = 0;
    353 			podule->medium_base = 0;
    354 			podule->slow_base = 0;
    355 			podule->sync_base = 0;
    356 			podule->mod_base = 0;
    357 			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
    358 		}
    359 
    360 		/* XXX - Really needs to be linked to a DMA manager */
    361 		if (IOMD_ID == RPC600_IOMD_ID) {
    362 			switch (loop) {
    363 			case 0:
    364 				podule->dma_channel = 2;
    365 				podule->dma_interrupt = IRQ_DMACH2;
    366 				break;
    367 			case 1:
    368 				podule->dma_channel = 3;
    369 				podule->dma_interrupt = IRQ_DMACH3;
    370 				break;
    371 			}
    372 		}
    373 
    374 		/* Get information from the podule header */
    375 
    376 		podule->flags0 = address[0];
    377 		if ((podule->flags0 & 0x78) == 0) {
    378 			podule->flags1 = address[4];
    379 			podule->reserved = address[8];
    380 			podule->product = address[12] + (address[16] << 8);
    381 			podule->manufacturer = address[20] + (address[24] << 8);
    382 			podule->country = address[28];
    383 			if (podule->flags1 & PODULE_FLAGS_IS) {
    384 				podule->irq_addr = address[52] + (address[56] << 8) + (address[60] << 16);
    385 				podule->irq_addr += podule->slow_base;
    386 				podule->irq_mask = address[48];
    387 				if (podule->irq_mask == 0)
    388 					podule->irq_mask = 0x01;
    389 				podule->fiq_addr = address[36] + (address[40] << 8) + (address[44] << 16);
    390 				podule->fiq_addr += podule->slow_base;
    391 				podule->fiq_mask = address[32];
    392 				if (podule->fiq_mask == 0)
    393 					podule->fiq_mask = 0x04;
    394 			} else {
    395 				podule->irq_addr = podule->slow_base;
    396 				podule->irq_mask = 0x01;
    397 				podule->fiq_addr = podule->slow_base;
    398 				podule->fiq_mask = 0x04;
    399 			}
    400 		}
    401 
    402 		poduleexamine(podule, dev, SLOT_POD);
    403 	}
    404 }
    405 
    406 
    407 /*
    408  * void podulebusattach(struct device *parent, struct device *dev, void *aux)
    409  *
    410  * Attach podulebus.
    411  * This probes all the podules and sets up the podules array with
    412  * information found in the podule headers.
    413  * After identifing all the podules, all the children of the podulebus
    414  * are probed and attached.
    415  */
    416 
    417 void
    418 podulebusattach(parent, self, aux)
    419 	struct device *parent;
    420 	struct device *self;
    421 	void *aux;
    422 {
    423 	int loop;
    424 	struct podule_attach_args pa;
    425 #if 0
    426 	int easi_time;
    427 	int bit;
    428 #endif
    429 	unsigned int value;
    430 	char argstring[20];
    431 
    432 #if 0
    433 	easi_time = IOMD_READ_BYTE(IOMD_ECTCR);
    434 	printf(": easi timings=");
    435 	for (bit = 0x01; bit < 0x100; bit = bit << 1)
    436 		if (easi_time & bit)
    437 			printf("C");
    438 		else
    439 			printf("A");
    440 #endif
    441 	printf("\n");
    442 
    443 	/* Ok we need to map in the podulebus */
    444 
    445 	/* Map the FAST and SYNC simple podules */
    446 
    447 	pmap_map_section((vm_offset_t)pmap_kernel()->pm_pdir,
    448 	    SYNC_PODULE_BASE & 0xfff00000, SYNC_PODULE_HW_BASE & 0xfff00000,
    449 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    450 	cpu_tlb_flushD();
    451 
    452 	/* Now map the EASI space */
    453 
    454 	for (loop = 0; loop < MAX_PODULES; ++loop) {
    455 		int loop1;
    456 
    457 		for (loop1 = loop * EASI_SIZE; loop1 < ((loop + 1) * EASI_SIZE);
    458 		    loop1 += L1_S_SIZE)
    459 		pmap_map_section((vm_offset_t)pmap_kernel()->pm_pdir,
    460 		    EASI_BASE + loop1, EASI_HW_BASE + loop1,
    461 		    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    462 	}
    463 	cpu_tlb_flushD();
    464 
    465 	/*
    466 	 * The MEDIUM and SLOW simple podules and the module space will have been
    467 	 * mapped when the IOMD and COMBO we mapped in for the RPC
    468 	 */
    469 
    470 	/* Find out what hardware is bolted on */
    471 
    472 	podulescan(self);
    473 	netslotscan(self);
    474 
    475 	/* Look for drivers to attach */
    476 
    477 	for (loop = 0; loop < MAX_PODULES+MAX_NETSLOTS; ++loop) {
    478 #if 1
    479 		/* Provide backwards compat for a while */
    480 		sprintf(argstring, "podule%d.disable", loop);
    481 		if (get_bootconf_option(boot_args, argstring,
    482 		    BOOTOPT_TYPE_BOOLEAN, &value)) {
    483 			if (value) {
    484 				if (podules[loop].slottype != SLOT_NONE)
    485 					printf("podule%d: Disabled\n", loop);
    486 				continue;
    487 			}
    488  		}
    489 #endif
    490  		sprintf(argstring, "podule%d=", loop);
    491  		if (get_bootconf_option(boot_args, argstring,
    492  		    BOOTOPT_TYPE_HEXINT, &value)) {
    493 			/* Override the ID */
    494 			podules[loop].manufacturer = value >> 16;
    495  			podules[loop].product = value & 0xffff;
    496 			/* Any old description is now wrong */
    497 			podules[loop].description[0] = 0;
    498 			if (value != 0xffff) {
    499 				printf("podule%d: ID overriden man=%04x prod=%04x\n",
    500 				    loop, podules[loop].manufacturer,
    501 				    podules[loop].product);
    502 				podules[loop].slottype = SLOT_POD;
    503 				pa.pa_podule_number = loop;
    504 				pa.pa_ih = pa.pa_podule_number;
    505 				pa.pa_podule = &podules[loop];
    506 				pa.pa_iot = &podulebus_bs_tag;
    507 				config_found_sm(self, &pa, podulebusprint,
    508 				    podulebussubmatch);
    509 				continue;
    510 			}
    511 			if (value == 0xffff) {
    512 				printf("podule%d: Disabled\n", loop);
    513 				continue;
    514 			}
    515 		}
    516 
    517 		if (podules[loop].slottype != SLOT_NONE) {
    518 			pa.pa_podule_number = loop;
    519 			pa.pa_ih = pa.pa_podule_number;
    520 			pa.pa_podule = &podules[loop];
    521 			pa.pa_iot = &podulebus_bs_tag;
    522 			config_found_sm(self, &pa, podulebusprint, podulebussubmatch);
    523 		}
    524 	}
    525 }
    526 
    527 
    528 CFATTACH_DECL(podulebus, sizeof(struct podulebus_softc),
    529 	podulebusmatch, podulebusattach, NULL, NULL);
    530 
    531 /* Useful functions that drivers may share */
    532 
    533 /*
    534  * Match a podule structure with the specified parameters
    535  * Returns 0 if the match failed
    536  * The required_slot is not used at the moment.
    537  */
    538 
    539 int
    540 matchpodule(pa, manufacturer, product, required_slot)
    541 	struct podule_attach_args *pa;
    542 	int manufacturer;
    543 	int product;
    544 	int required_slot;
    545 {
    546 	if (pa->pa_podule->attached)
    547 		panic("podulebus: Podule already attached");
    548 
    549 	if (IS_PODULE(pa, manufacturer, product))
    550 		return(1);
    551 
    552 	return(0);
    553 }
    554 
    555 void *
    556 podulebus_irq_establish(ih, ipl, func, arg, ev)
    557 	podulebus_intr_handle_t ih;
    558 	int ipl;
    559 	int (*func) __P((void *));
    560 	void *arg;
    561 	struct evcnt *ev;
    562 {
    563 
    564 	/* XXX We don't actually use the evcnt supplied, just its name. */
    565 	return intr_claim(podules[ih].interrupt, ipl, ev->ev_group, func,
    566 	    arg);
    567 }
    568 
    569 /*
    570  * Generate a bus_space_tag_t with the specified address-bus shift.
    571  */
    572 void
    573 podulebus_shift_tag(tag, shift, tagp)
    574 	bus_space_tag_t tag, *tagp;
    575 	u_int shift;
    576 {
    577 
    578 	/*
    579 	 * For the podulebus, the bus tag cookie is the shift to apply
    580 	 * to registers, so duplicate the bus space tag and change the
    581 	 * cookie.
    582 	 */
    583 
    584 	/* XXX never freed, but podules are never detached anyway. */
    585         *tagp = malloc(sizeof(struct bus_space), M_DEVBUF, M_WAITOK);
    586 	**tagp = *tag;
    587 	(*tagp)->bs_cookie = (void *)shift;
    588 }
    589 
    590 int
    591 podulebus_initloader(struct podulebus_attach_args *pa)
    592 {
    593 
    594 	/* No loader support at present on arm32, so always fail. */
    595 	return -1;
    596 }
    597 
    598 int
    599 podloader_readbyte(struct podulebus_attach_args *pa, u_int addr)
    600 {
    601 
    602 	panic("podloader_readbyte");
    603 }
    604 
    605 void
    606 podloader_writebyte(struct podulebus_attach_args *pa, u_int addr, int val)
    607 {
    608 
    609 	panic("podloader_writebyte");
    610 }
    611 
    612 void
    613 podloader_reset(struct podulebus_attach_args *pa)
    614 {
    615 
    616 	panic("podloader_reset");
    617 }
    618 
    619 int
    620 podloader_callloader(struct podulebus_attach_args *pa, u_int r0, u_int r1)
    621 {
    622 
    623 	panic("podloader_callloader");
    624 }
    625 
    626 /* End of podulebus.c */
    627