Home | History | Annotate | Line # | Download | only in podulebus
podulebus.c revision 1.5
      1 /* $NetBSD: podulebus.c,v 1.5 2002/02/18 13:11:07 bjh21 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 __RCSID("$NetBSD: podulebus.c,v 1.5 2002/02/18 13:11:07 bjh21 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 void map_section __P((vm_offset_t, vm_offset_t, vm_offset_t, int cacheable));
     76 u_int poduleread __P((u_int, int));
     77 int podulebusmatch(struct device *, struct cfdata *, void *);
     78 void podulebusattach(struct device *, struct device *, void *);
     79 int podulebusprint(void *, const char *);
     80 int podulebussubmatch(struct device *, struct cfdata *, void *);
     81 void podulechunkdirectory(podule_t *);
     82 void podulescan(struct device *);
     83 
     84 /*
     85  * int podulebusmatch(struct device *parent, void *match, void *aux)
     86  *
     87  * Probe for the podule bus. Currently all this does is return 1 to
     88  * indicate that the podule bus was found.
     89  */
     90 
     91 int
     92 podulebusmatch(parent, cf, aux)
     93 	struct device *parent;
     94 	struct cfdata *cf;
     95 	void *aux;
     96 {
     97 	switch (IOMD_ID) {
     98 	case RPC600_IOMD_ID:
     99 	case ARM7500_IOC_ID:
    100 	case ARM7500FE_IOC_ID:
    101 		return(1);
    102 	}
    103 	return (0);
    104 }
    105 
    106 
    107 int
    108 podulebusprint(aux, name)
    109 	void *aux;
    110 	const char *name;
    111 {
    112 	struct podule_attach_args *pa = aux;
    113 
    114 	if (name)
    115 		printf("podule at %s", name);
    116 	if (pa->pa_podule->slottype == SLOT_POD)
    117 		printf(" slot %d", pa->pa_podule_number);
    118 	else if (pa->pa_podule->slottype == SLOT_NET)
    119 		printf(" [ netslot %d ]", pa->pa_podule_number - MAX_PODULES);
    120 #ifdef DIAGNOSTIC
    121 	else
    122 		panic("Invalid slot type\n");
    123 #endif
    124 
    125 	return (UNCONF);
    126 }
    127 
    128 
    129 int
    130 podulebussubmatch(parent, cf, aux)
    131 	struct device *parent;
    132 	struct cfdata *cf;
    133 	void *aux;
    134 {
    135 	struct podule_attach_args *pa = aux;
    136 
    137 	/* Return priority 0 or 1 for wildcarded podule */
    138 
    139 	if (cf->cf_loc[PODULEBUSCF_SLOT] == PODULEBUSCF_SLOT_DEFAULT)
    140 		return((*cf->cf_attach->ca_match)(parent, cf, aux));
    141 
    142 	/* Return higher priority if we match the specific podule */
    143 
    144 	else if (cf->cf_loc[PODULEBUSCF_SLOT] == pa->pa_podule_number)
    145 		return((*cf->cf_attach->ca_match)(parent, cf, aux) * 8);
    146 
    147 	/* Fail */
    148 	return(0);
    149 }
    150 
    151 
    152 #if 0
    153 void
    154 dump_podule(podule)
    155 	podule_t *podule;
    156 {
    157 	printf("podule%d: ", podule->podulenum);
    158 	printf("flags0=%02x ", podule->flags0);
    159 	printf("flags1=%02x ", podule->flags1);
    160 	printf("reserved=%02x ", podule->reserved);
    161 	printf("product=%02x ", podule->product);
    162 	printf("manufacturer=%02x ", podule->manufacturer);
    163 	printf("country=%02x ", podule->country);
    164 	printf("irq_addr=%08x ", podule->irq_addr);
    165 	printf("irq_mask=%02x ", podule->irq_mask);
    166 	printf("fiq_addr=%08x ", podule->fiq_addr);
    167 	printf("fiq_mask=%02x ", podule->fiq_mask);
    168 	printf("fast_base=%08x ", podule->fast_base);
    169 	printf("medium_base=%08x ", podule->medium_base);
    170 	printf("slow_base=%08x ", podule->slow_base);
    171 	printf("sync_base=%08x ", podule->sync_base);
    172 	printf("mod_base=%08x ", podule->mod_base);
    173 	printf("easi_base=%08x ", podule->easi_base);
    174 	printf("attached=%d ", podule->attached);
    175 	printf("slottype=%d ", podule->slottype);
    176 	printf("podulenum=%d ", podule->podulenum);
    177 	printf("description=%s ", podule->description);
    178 	printf("\n");
    179 }
    180 #endif
    181 
    182 void
    183 podulechunkdirectory(podule)
    184 	podule_t *podule;
    185 {
    186 	u_int address;
    187 	u_int id;
    188 	u_int size;
    189 	u_int addr;
    190 	int loop;
    191 	int done_f5;
    192 
    193 	done_f5 = 0;
    194 	address = 0x40;
    195 
    196 	do {
    197 		id = podule->read_rom(podule->sync_base, address);
    198 		size = podule->read_rom(podule->sync_base, address + 4);
    199 		size |= (podule->read_rom(podule->sync_base, address + 8) << 8);
    200 		size |= (podule->read_rom(podule->sync_base, address + 12) << 16);
    201 		if (id == 0xf5) {
    202 			addr = podule->read_rom(podule->sync_base, address + 16);
    203 			addr |= (podule->read_rom(podule->sync_base, address + 20) << 8);
    204 			addr |= (podule->read_rom(podule->sync_base, address + 24) << 16);
    205 			addr |= (podule->read_rom(podule->sync_base, address + 28) << 24);
    206 			if (addr < 0x800 && done_f5 == 0) {
    207 				done_f5 = 1;
    208 				for (loop = 0; loop < size; ++loop) {
    209 					if (loop < PODULE_DESCRIPTION_LENGTH) {
    210 						podule->description[loop] =
    211 						    podule->read_rom(podule->sync_base, (addr + loop)*4);
    212 						podule->description[loop + 1] = 0;
    213 					}
    214 				}
    215 			}
    216 		}
    217 #ifdef DEBUG_CHUNK_DIR
    218 		if (id == 0xf5 || id == 0xf1 || id == 0xf2 || id == 0xf3 || id == 0xf4 || id == 0xf6) {
    219 			addr = podule->read_rom(podule->sync_base, address + 16);
    220 			addr |= (podule->read_rom(podule->sync_base, address + 20) << 8);
    221 			addr |= (podule->read_rom(podule->sync_base, address + 24) << 16);
    222 			addr |= (podule->read_rom(podule->sync_base, address + 28) << 24);
    223 			printf("<%04x.%04x.%04x.%04x>", id, address, addr, size);
    224 			if (addr < 0x800) {
    225 				for (loop = 0; loop < size; ++loop) {
    226 					printf("%c", podule->read_rom(podule->sync_base, (addr + loop)*4));
    227 				}
    228 				printf("\\n\n");
    229 			}
    230 		}
    231 #endif
    232 		address += 32;
    233 	} while (id != 0 && address < 0x800);
    234 }
    235 
    236 
    237 void
    238 poduleexamine(podule, dev, slottype)
    239 	podule_t *podule;
    240 	struct device *dev;
    241 	int slottype;
    242 {
    243 	struct podule_list *pod_list;
    244 	struct podule_description *pod_desc;
    245 
    246 	/* Test to see if the podule is present */
    247 
    248 	if ((podule->flags0 & 0x02) == 0x00) {
    249 		podule->slottype = slottype;
    250 		if (slottype == SLOT_NET)
    251 			printf("netslot%d at %s : ", podule->podulenum - MAX_PODULES,
    252 			    dev->dv_xname);
    253 		else
    254 			printf("podule%d  at %s : ", podule->podulenum,
    255 			    dev->dv_xname);
    256 
    257 		/* Is it Acorn conformant ? */
    258 
    259 		if (podule->flags0 & 0x80)
    260 			printf("Non-Acorn conformant expansion card\n");
    261 		else {
    262 			int id;
    263 
    264 			/* Is it a simple podule ? */
    265 
    266 			id = (podule->flags0 >> 3) & 0x0f;
    267 			if (id != 0)
    268 				printf("Simple expansion card <%x>\n", id);
    269 			else {
    270 				/* Scan the chunk directory if present for tags we use */
    271 				if (podule->flags1 & PODULE_FLAGS_CD)
    272 					podulechunkdirectory(podule);
    273 
    274 				/* Do we know this manufacturer ? */
    275 				pod_list = known_podules;
    276 				while (pod_list->description) {
    277 					if (pod_list->manufacturer_id == podule->manufacturer)
    278 						break;
    279 					++pod_list;
    280 				}
    281 				if (!pod_list->description)
    282 					printf("man=%04x   : ", podule->manufacturer);
    283 				else
    284 					printf("%s : ", pod_list->description);
    285 
    286 				/* Do we know this product ? */
    287 
    288 				pod_desc = pod_list->products;
    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 : ", podule->product);
    296 					printf("%s\n", podule->description);
    297 				} else
    298 					printf("%s : %s\n", pod_desc->description, podule->description);
    299 			}
    300 		}
    301 	}
    302 }
    303 
    304 
    305 u_int
    306 poduleread(address, offset)
    307 	u_int address;
    308 	int offset;
    309 {
    310 
    311 	return(ReadByte(address + offset));
    312 }
    313 
    314 void
    315 podulescan(dev)
    316 	struct device *dev;
    317 {
    318 	int loop;
    319 	podule_t *podule;
    320 	u_char *address;
    321 	u_int offset = 0;
    322 
    323 	/* Loop round all the podules */
    324 
    325 	for (loop = 0; loop < MAX_PODULES; ++loop, offset += SIMPLE_PODULE_SIZE) {
    326 		podule = &podules[loop];
    327 		podule->podulenum = loop;
    328 		podule->attached = 0;
    329 		podule->slottype = SLOT_NONE;
    330 		podule->interrupt = IRQ_PODULE;
    331 		podule->read_rom = poduleread;
    332 		podule->dma_channel = -1;
    333 		podule->dma_interrupt = -1;
    334 		podule->description[0] = 0;
    335 
    336 		if (loop == 4) offset += PODULE_GAP;
    337 		address = ((u_char *)SYNC_PODULE_BASE) + offset;
    338 
    339 		if ((address[0] & 0x02) == 0x00) {
    340 			podule->fast_base = FAST_PODULE_BASE + offset;
    341 			podule->medium_base = MEDIUM_PODULE_BASE + offset;
    342 			podule->slow_base = SLOW_PODULE_BASE + offset;
    343 			podule->sync_base = SYNC_PODULE_BASE + offset;
    344 			podule->mod_base = MOD_PODULE_BASE + offset;
    345 			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
    346 		} else {
    347 			address = ((u_char *)EASI_BASE) + loop * EASI_SIZE;
    348 			if ((address[0] & 0x02) != 0x00)
    349 				continue;
    350 
    351 			podule->fast_base = 0;
    352 			podule->medium_base = 0;
    353 			podule->slow_base = 0;
    354 			podule->sync_base = 0;
    355 			podule->mod_base = 0;
    356 			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
    357 		}
    358 
    359 		/* XXX - Really needs to be linked to a DMA manager */
    360 		if (IOMD_ID == RPC600_IOMD_ID) {
    361 			switch (loop) {
    362 			case 0:
    363 				podule->dma_channel = 2;
    364 				podule->dma_interrupt = IRQ_DMACH2;
    365 				break;
    366 			case 1:
    367 				podule->dma_channel = 3;
    368 				podule->dma_interrupt = IRQ_DMACH3;
    369 				break;
    370 			}
    371 		}
    372 
    373 		/* Get information from the podule header */
    374 
    375 		podule->flags0 = address[0];
    376 		if ((podule->flags0 & 0x78) == 0) {
    377 			podule->flags1 = address[4];
    378 			podule->reserved = address[8];
    379 			podule->product = address[12] + (address[16] << 8);
    380 			podule->manufacturer = address[20] + (address[24] << 8);
    381 			podule->country = address[28];
    382 			if (podule->flags1 & PODULE_FLAGS_IS) {
    383 				podule->irq_addr = address[52] + (address[56] << 8) + (address[60] << 16);
    384 				podule->irq_addr += podule->slow_base;
    385 				podule->irq_mask = address[48];
    386 				if (podule->irq_mask == 0)
    387 					podule->irq_mask = 0x01;
    388 				podule->fiq_addr = address[36] + (address[40] << 8) + (address[44] << 16);
    389 				podule->fiq_addr += podule->slow_base;
    390 				podule->fiq_mask = address[32];
    391 				if (podule->fiq_mask == 0)
    392 					podule->fiq_mask = 0x04;
    393 			} else {
    394 				podule->irq_addr = podule->slow_base;
    395 				podule->irq_mask = 0x01;
    396 				podule->fiq_addr = podule->slow_base;
    397 				podule->fiq_mask = 0x04;
    398 			}
    399 		}
    400 
    401 		poduleexamine(podule, dev, SLOT_POD);
    402 	}
    403 }
    404 
    405 
    406 /*
    407  * void podulebusattach(struct device *parent, struct device *dev, void *aux)
    408  *
    409  * Attach podulebus.
    410  * This probes all the podules and sets up the podules array with
    411  * information found in the podule headers.
    412  * After identifing all the podules, all the children of the podulebus
    413  * are probed and attached.
    414  */
    415 
    416 void
    417 podulebusattach(parent, self, aux)
    418 	struct device *parent;
    419 	struct device *self;
    420 	void *aux;
    421 {
    422 	int loop;
    423 	struct podule_attach_args pa;
    424 #if 0
    425 	int easi_time;
    426 	int bit;
    427 #endif
    428 	unsigned int value;
    429 	char argstring[20];
    430 
    431 #if 0
    432 	easi_time = IOMD_READ_BYTE(IOMD_ECTCR);
    433 	printf(": easi timings=");
    434 	for (bit = 0x01; bit < 0x100; bit = bit << 1)
    435 		if (easi_time & bit)
    436 			printf("C");
    437 		else
    438 			printf("A");
    439 #endif
    440 	printf("\n");
    441 
    442 	/* Ok we need to map in the podulebus */
    443 
    444 	/* Map the FAST and SYNC simple podules */
    445 
    446 	map_section((vm_offset_t)pmap_kernel()->pm_pdir,
    447 	    SYNC_PODULE_BASE & 0xfff00000, SYNC_PODULE_HW_BASE & 0xfff00000, 0);
    448 	cpu_tlb_flushD();
    449 
    450 	/* Now map the EASI space */
    451 
    452 	for (loop = 0; loop < MAX_PODULES; ++loop) {
    453 		int loop1;
    454 
    455 		for (loop1 = loop * EASI_SIZE; loop1 < ((loop + 1) * EASI_SIZE);
    456 		    loop1 += L1_SEC_SIZE)
    457 		map_section((vm_offset_t)pmap_kernel()->pm_pdir, EASI_BASE + loop1,
    458 		    EASI_HW_BASE + loop1, 0);
    459 	}
    460 	cpu_tlb_flushD();
    461 
    462 	/*
    463 	 * The MEDIUM and SLOW simple podules and the module space will have been
    464 	 * mapped when the IOMD and COMBO we mapped in for the RPC
    465 	 */
    466 
    467 	/* Find out what hardware is bolted on */
    468 
    469 	podulescan(self);
    470 	netslotscan(self);
    471 
    472 	/* Look for drivers to attach */
    473 
    474 	for (loop = 0; loop < MAX_PODULES+MAX_NETSLOTS; ++loop) {
    475 #if 1
    476 		/* Provide backwards compat for a while */
    477 		sprintf(argstring, "podule%d.disable", loop);
    478 		if (get_bootconf_option(boot_args, argstring,
    479 		    BOOTOPT_TYPE_BOOLEAN, &value)) {
    480 			if (value) {
    481 				if (podules[loop].slottype != SLOT_NONE)
    482 					printf("podule%d: Disabled\n", loop);
    483 				continue;
    484 			}
    485  		}
    486 #endif
    487  		sprintf(argstring, "podule%d=", loop);
    488  		if (get_bootconf_option(boot_args, argstring,
    489  		    BOOTOPT_TYPE_HEXINT, &value)) {
    490 			/* Override the ID */
    491 			podules[loop].manufacturer = value >> 16;
    492  			podules[loop].product = value & 0xffff;
    493 			/* Any old description is now wrong */
    494 			podules[loop].description[0] = 0;
    495 			if (value != 0xffff) {
    496 				printf("podule%d: ID overriden man=%04x prod=%04x\n",
    497 				    loop, podules[loop].manufacturer,
    498 				    podules[loop].product);
    499 				podules[loop].slottype = SLOT_POD;
    500 				pa.pa_podule_number = loop;
    501 				pa.pa_ih = pa.pa_podule_number;
    502 				pa.pa_podule = &podules[loop];
    503 				pa.pa_iot = &podulebus_bs_tag;
    504 				config_found_sm(self, &pa, podulebusprint,
    505 				    podulebussubmatch);
    506 				continue;
    507 			}
    508 			if (value == 0xffff) {
    509 				printf("podule%d: Disabled\n", loop);
    510 				continue;
    511 			}
    512 		}
    513 
    514 		if (podules[loop].slottype != SLOT_NONE) {
    515 			pa.pa_podule_number = loop;
    516 			pa.pa_ih = pa.pa_podule_number;
    517 			pa.pa_podule = &podules[loop];
    518 			pa.pa_iot = &podulebus_bs_tag;
    519 			config_found_sm(self, &pa, podulebusprint, podulebussubmatch);
    520 		}
    521 	}
    522 }
    523 
    524 
    525 struct cfattach podulebus_ca = {
    526 	sizeof(struct device), podulebusmatch, podulebusattach
    527 };
    528 
    529 /* Useful functions that drivers may share */
    530 
    531 /*
    532  * Match a podule structure with the specified parameters
    533  * Returns 0 if the match failed
    534  * The required_slot is not used at the moment.
    535  */
    536 
    537 int
    538 matchpodule(pa, manufacturer, product, required_slot)
    539 	struct podule_attach_args *pa;
    540 	int manufacturer;
    541 	int product;
    542 	int required_slot;
    543 {
    544 	if (pa->pa_podule->attached)
    545 		panic("podulebus: Podule already attached\n");
    546 
    547 	if (IS_PODULE(pa, manufacturer, product))
    548 		return(1);
    549 
    550 	return(0);
    551 }
    552 
    553 void *
    554 podulebus_irq_establish(ih, ipl, func, arg, ev)
    555 	podulebus_intr_handle_t ih;
    556 	int ipl;
    557 	int (*func) __P((void *));
    558 	void *arg;
    559 	struct evcnt *ev;
    560 {
    561 
    562 	/* XXX We don't actually use the evcnt supplied, just its name. */
    563 	return intr_claim(podules[ih].interrupt, ipl, ev->ev_group, func,
    564 	    arg);
    565 }
    566 
    567 /*
    568  * Generate a bus_space_tag_t with the specified address-bus shift.
    569  */
    570 void
    571 podulebus_shift_tag(tag, shift, tagp)
    572 	bus_space_tag_t tag, *tagp;
    573 	u_int shift;
    574 {
    575 
    576 	/*
    577 	 * For the podulebus, the bus tag cookie is the shift to apply
    578 	 * to registers, so duplicate the bus space tag and change the
    579 	 * cookie.
    580 	 */
    581 
    582 	/* XXX never freed, but podules are never detached anyway. */
    583         *tagp = malloc(sizeof(struct bus_space), M_DEVBUF, M_WAITOK);
    584 	**tagp = *tag;
    585 	(*tagp)->bs_cookie = (void *)shift;
    586 }
    587 
    588 int
    589 podulebus_initloader(struct podulebus_attach_args *pa)
    590 {
    591 
    592 	/* No loader support at present on arm32, so always fail. */
    593 	return -1;
    594 }
    595 
    596 int
    597 podloader_readbyte(struct podulebus_attach_args *pa, u_int addr)
    598 {
    599 
    600 	panic("podloader_readbyte");
    601 }
    602 
    603 void
    604 podloader_writebyte(struct podulebus_attach_args *pa, u_int addr, int val)
    605 {
    606 
    607 	panic("podloader_writebyte");
    608 }
    609 
    610 void
    611 podloader_reset(struct podulebus_attach_args *pa)
    612 {
    613 
    614 	panic("podloader_reset");
    615 }
    616 
    617 int
    618 podloader_callloader(struct podulebus_attach_args *pa, u_int r0, u_int r1)
    619 {
    620 
    621 	panic("podloader_callloader");
    622 }
    623 
    624 /* End of podulebus.c */
    625