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