Home | History | Annotate | Line # | Download | only in podulebus
podulebus.c revision 1.8
      1 /* $NetBSD: podulebus.c,v 1.8 2002/04/05 16:58:02 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.8 2002/04/05 16:58:02 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\n");
    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((*cf->cf_attach->ca_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((*cf->cf_attach->ca_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 podule_list *pod_list;
    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 				pod_list = known_podules;
    275 				while (pod_list->description) {
    276 					if (pod_list->manufacturer_id == podule->manufacturer)
    277 						break;
    278 					++pod_list;
    279 				}
    280 				if (!pod_list->description)
    281 					printf("man=%04x   : ", podule->manufacturer);
    282 				else
    283 					printf("%s : ", pod_list->description);
    284 
    285 				/* Do we know this product ? */
    286 
    287 				pod_desc = pod_list->products;
    288 				while (pod_desc->description) {
    289 					if (pod_desc->product_id == podule->product)
    290 						break;
    291 					++pod_desc;
    292 				}
    293 				if (!pod_desc->description) {
    294 					printf("prod=%04x : ", podule->product);
    295 					printf("%s\n", podule->description);
    296 				} else
    297 					printf("%s : %s\n", pod_desc->description, podule->description);
    298 			}
    299 		}
    300 	}
    301 }
    302 
    303 
    304 u_int
    305 poduleread(address, offset)
    306 	u_int address;
    307 	int offset;
    308 {
    309 
    310 	return(ReadByte(address + offset));
    311 }
    312 
    313 void
    314 podulescan(dev)
    315 	struct device *dev;
    316 {
    317 	int loop;
    318 	podule_t *podule;
    319 	u_char *address;
    320 	u_int offset = 0;
    321 
    322 	/* Loop round all the podules */
    323 
    324 	for (loop = 0; loop < MAX_PODULES; ++loop, offset += SIMPLE_PODULE_SIZE) {
    325 		podule = &podules[loop];
    326 		podule->podulenum = loop;
    327 		podule->attached = 0;
    328 		podule->slottype = SLOT_NONE;
    329 		podule->interrupt = IRQ_PODULE;
    330 		podule->read_rom = poduleread;
    331 		podule->dma_channel = -1;
    332 		podule->dma_interrupt = -1;
    333 		podule->description[0] = 0;
    334 
    335 		if (loop == 4) offset += PODULE_GAP;
    336 		address = ((u_char *)SYNC_PODULE_BASE) + offset;
    337 
    338 		if ((address[0] & 0x02) == 0x00) {
    339 			podule->fast_base = FAST_PODULE_BASE + offset;
    340 			podule->medium_base = MEDIUM_PODULE_BASE + offset;
    341 			podule->slow_base = SLOW_PODULE_BASE + offset;
    342 			podule->sync_base = SYNC_PODULE_BASE + offset;
    343 			podule->mod_base = MOD_PODULE_BASE + offset;
    344 			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
    345 		} else {
    346 			address = ((u_char *)EASI_BASE) + loop * EASI_SIZE;
    347 			if ((address[0] & 0x02) != 0x00)
    348 				continue;
    349 
    350 			podule->fast_base = 0;
    351 			podule->medium_base = 0;
    352 			podule->slow_base = 0;
    353 			podule->sync_base = 0;
    354 			podule->mod_base = 0;
    355 			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
    356 		}
    357 
    358 		/* XXX - Really needs to be linked to a DMA manager */
    359 		if (IOMD_ID == RPC600_IOMD_ID) {
    360 			switch (loop) {
    361 			case 0:
    362 				podule->dma_channel = 2;
    363 				podule->dma_interrupt = IRQ_DMACH2;
    364 				break;
    365 			case 1:
    366 				podule->dma_channel = 3;
    367 				podule->dma_interrupt = IRQ_DMACH3;
    368 				break;
    369 			}
    370 		}
    371 
    372 		/* Get information from the podule header */
    373 
    374 		podule->flags0 = address[0];
    375 		if ((podule->flags0 & 0x78) == 0) {
    376 			podule->flags1 = address[4];
    377 			podule->reserved = address[8];
    378 			podule->product = address[12] + (address[16] << 8);
    379 			podule->manufacturer = address[20] + (address[24] << 8);
    380 			podule->country = address[28];
    381 			if (podule->flags1 & PODULE_FLAGS_IS) {
    382 				podule->irq_addr = address[52] + (address[56] << 8) + (address[60] << 16);
    383 				podule->irq_addr += podule->slow_base;
    384 				podule->irq_mask = address[48];
    385 				if (podule->irq_mask == 0)
    386 					podule->irq_mask = 0x01;
    387 				podule->fiq_addr = address[36] + (address[40] << 8) + (address[44] << 16);
    388 				podule->fiq_addr += podule->slow_base;
    389 				podule->fiq_mask = address[32];
    390 				if (podule->fiq_mask == 0)
    391 					podule->fiq_mask = 0x04;
    392 			} else {
    393 				podule->irq_addr = podule->slow_base;
    394 				podule->irq_mask = 0x01;
    395 				podule->fiq_addr = podule->slow_base;
    396 				podule->fiq_mask = 0x04;
    397 			}
    398 		}
    399 
    400 		poduleexamine(podule, dev, SLOT_POD);
    401 	}
    402 }
    403 
    404 
    405 /*
    406  * void podulebusattach(struct device *parent, struct device *dev, void *aux)
    407  *
    408  * Attach podulebus.
    409  * This probes all the podules and sets up the podules array with
    410  * information found in the podule headers.
    411  * After identifing all the podules, all the children of the podulebus
    412  * are probed and attached.
    413  */
    414 
    415 void
    416 podulebusattach(parent, self, aux)
    417 	struct device *parent;
    418 	struct device *self;
    419 	void *aux;
    420 {
    421 	int loop;
    422 	struct podule_attach_args pa;
    423 #if 0
    424 	int easi_time;
    425 	int bit;
    426 #endif
    427 	unsigned int value;
    428 	char argstring[20];
    429 
    430 #if 0
    431 	easi_time = IOMD_READ_BYTE(IOMD_ECTCR);
    432 	printf(": easi timings=");
    433 	for (bit = 0x01; bit < 0x100; bit = bit << 1)
    434 		if (easi_time & bit)
    435 			printf("C");
    436 		else
    437 			printf("A");
    438 #endif
    439 	printf("\n");
    440 
    441 	/* Ok we need to map in the podulebus */
    442 
    443 	/* Map the FAST and SYNC simple podules */
    444 
    445 	pmap_map_section((vm_offset_t)pmap_kernel()->pm_pdir,
    446 	    SYNC_PODULE_BASE & 0xfff00000, SYNC_PODULE_HW_BASE & 0xfff00000,
    447 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    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_S_SIZE)
    457 		pmap_map_section((vm_offset_t)pmap_kernel()->pm_pdir,
    458 		    EASI_BASE + loop1, EASI_HW_BASE + loop1,
    459 		    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    460 	}
    461 	cpu_tlb_flushD();
    462 
    463 	/*
    464 	 * The MEDIUM and SLOW simple podules and the module space will have been
    465 	 * mapped when the IOMD and COMBO we mapped in for the RPC
    466 	 */
    467 
    468 	/* Find out what hardware is bolted on */
    469 
    470 	podulescan(self);
    471 	netslotscan(self);
    472 
    473 	/* Look for drivers to attach */
    474 
    475 	for (loop = 0; loop < MAX_PODULES+MAX_NETSLOTS; ++loop) {
    476 #if 1
    477 		/* Provide backwards compat for a while */
    478 		sprintf(argstring, "podule%d.disable", loop);
    479 		if (get_bootconf_option(boot_args, argstring,
    480 		    BOOTOPT_TYPE_BOOLEAN, &value)) {
    481 			if (value) {
    482 				if (podules[loop].slottype != SLOT_NONE)
    483 					printf("podule%d: Disabled\n", loop);
    484 				continue;
    485 			}
    486  		}
    487 #endif
    488  		sprintf(argstring, "podule%d=", loop);
    489  		if (get_bootconf_option(boot_args, argstring,
    490  		    BOOTOPT_TYPE_HEXINT, &value)) {
    491 			/* Override the ID */
    492 			podules[loop].manufacturer = value >> 16;
    493  			podules[loop].product = value & 0xffff;
    494 			/* Any old description is now wrong */
    495 			podules[loop].description[0] = 0;
    496 			if (value != 0xffff) {
    497 				printf("podule%d: ID overriden man=%04x prod=%04x\n",
    498 				    loop, podules[loop].manufacturer,
    499 				    podules[loop].product);
    500 				podules[loop].slottype = SLOT_POD;
    501 				pa.pa_podule_number = loop;
    502 				pa.pa_ih = pa.pa_podule_number;
    503 				pa.pa_podule = &podules[loop];
    504 				pa.pa_iot = &podulebus_bs_tag;
    505 				config_found_sm(self, &pa, podulebusprint,
    506 				    podulebussubmatch);
    507 				continue;
    508 			}
    509 			if (value == 0xffff) {
    510 				printf("podule%d: Disabled\n", loop);
    511 				continue;
    512 			}
    513 		}
    514 
    515 		if (podules[loop].slottype != SLOT_NONE) {
    516 			pa.pa_podule_number = loop;
    517 			pa.pa_ih = pa.pa_podule_number;
    518 			pa.pa_podule = &podules[loop];
    519 			pa.pa_iot = &podulebus_bs_tag;
    520 			config_found_sm(self, &pa, podulebusprint, podulebussubmatch);
    521 		}
    522 	}
    523 }
    524 
    525 
    526 struct cfattach podulebus_ca = {
    527 	sizeof(struct device), podulebusmatch, podulebusattach
    528 };
    529 
    530 /* Useful functions that drivers may share */
    531 
    532 /*
    533  * Match a podule structure with the specified parameters
    534  * Returns 0 if the match failed
    535  * The required_slot is not used at the moment.
    536  */
    537 
    538 int
    539 matchpodule(pa, manufacturer, product, required_slot)
    540 	struct podule_attach_args *pa;
    541 	int manufacturer;
    542 	int product;
    543 	int required_slot;
    544 {
    545 	if (pa->pa_podule->attached)
    546 		panic("podulebus: Podule already attached\n");
    547 
    548 	if (IS_PODULE(pa, manufacturer, product))
    549 		return(1);
    550 
    551 	return(0);
    552 }
    553 
    554 void *
    555 podulebus_irq_establish(ih, ipl, func, arg, ev)
    556 	podulebus_intr_handle_t ih;
    557 	int ipl;
    558 	int (*func) __P((void *));
    559 	void *arg;
    560 	struct evcnt *ev;
    561 {
    562 
    563 	/* XXX We don't actually use the evcnt supplied, just its name. */
    564 	return intr_claim(podules[ih].interrupt, ipl, ev->ev_group, func,
    565 	    arg);
    566 }
    567 
    568 /*
    569  * Generate a bus_space_tag_t with the specified address-bus shift.
    570  */
    571 void
    572 podulebus_shift_tag(tag, shift, tagp)
    573 	bus_space_tag_t tag, *tagp;
    574 	u_int shift;
    575 {
    576 
    577 	/*
    578 	 * For the podulebus, the bus tag cookie is the shift to apply
    579 	 * to registers, so duplicate the bus space tag and change the
    580 	 * cookie.
    581 	 */
    582 
    583 	/* XXX never freed, but podules are never detached anyway. */
    584         *tagp = malloc(sizeof(struct bus_space), M_DEVBUF, M_WAITOK);
    585 	**tagp = *tag;
    586 	(*tagp)->bs_cookie = (void *)shift;
    587 }
    588 
    589 int
    590 podulebus_initloader(struct podulebus_attach_args *pa)
    591 {
    592 
    593 	/* No loader support at present on arm32, so always fail. */
    594 	return -1;
    595 }
    596 
    597 int
    598 podloader_readbyte(struct podulebus_attach_args *pa, u_int addr)
    599 {
    600 
    601 	panic("podloader_readbyte");
    602 }
    603 
    604 void
    605 podloader_writebyte(struct podulebus_attach_args *pa, u_int addr, int val)
    606 {
    607 
    608 	panic("podloader_writebyte");
    609 }
    610 
    611 void
    612 podloader_reset(struct podulebus_attach_args *pa)
    613 {
    614 
    615 	panic("podloader_reset");
    616 }
    617 
    618 int
    619 podloader_callloader(struct podulebus_attach_args *pa, u_int r0, u_int r1)
    620 {
    621 
    622 	panic("podloader_callloader");
    623 }
    624 
    625 /* End of podulebus.c */
    626