Home | History | Annotate | Line # | Download | only in podulebus
      1  1.34    andvar /* $NetBSD: podulebus.c,v 1.34 2022/05/30 09:56:02 andvar 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.5     bjh21 
     46  1.34    andvar __KERNEL_RCSID(0, "$NetBSD: podulebus.c,v 1.34 2022/05/30 09:56:02 andvar Exp $");
     47   1.5     bjh21 
     48   1.1   reinoud #include <sys/systm.h>
     49   1.1   reinoud #include <sys/kernel.h>
     50   1.1   reinoud #include <sys/conf.h>
     51  1.30   thorpej #include <sys/kmem.h>
     52   1.1   reinoud #include <sys/device.h>
     53   1.1   reinoud #include <uvm/uvm_extern.h>
     54   1.1   reinoud #include <machine/io.h>
     55   1.4   thorpej #include <machine/intr.h>
     56   1.1   reinoud #include <machine/bootconfig.h>
     57   1.1   reinoud #include <machine/pmap.h>
     58   1.1   reinoud #include <arm/iomd/iomdreg.h>
     59   1.1   reinoud #include <arm/iomd/iomdvar.h>
     60   1.1   reinoud #include <acorn32/podulebus/podulebus.h>
     61   1.1   reinoud #include <dev/podulebus/podules.h>
     62   1.1   reinoud #include <dev/podulebus/podule_data.h>
     63   1.1   reinoud 
     64   1.1   reinoud #include "locators.h"
     65   1.1   reinoud 
     66  1.29     skrll #define WriteByte(a, b) \
     67  1.29     skrll     *((volatile unsigned char *)(a)) = (b)
     68  1.29     skrll #define ReadByte(a) \
     69  1.29     skrll     (*((volatile unsigned char *)(a)))
     70  1.29     skrll 
     71   1.1   reinoud /* Array of podule structures, one per possible podule */
     72   1.1   reinoud 
     73   1.1   reinoud podule_t podules[MAX_PODULES + MAX_NETSLOTS];
     74   1.1   reinoud 
     75   1.1   reinoud extern struct bus_space podulebus_bs_tag;
     76   1.1   reinoud 
     77   1.1   reinoud /* Declare prototypes */
     78   1.1   reinoud 
     79  1.21       dsl u_int poduleread(u_int, int);
     80  1.26      matt int podulebusmatch(device_t, cfdata_t, void *);
     81  1.26      matt void podulebusattach(device_t, device_t, void *);
     82   1.5     bjh21 int podulebusprint(void *, const char *);
     83  1.26      matt int podulebussubmatch(device_t, cfdata_t, const int *, void *);
     84   1.5     bjh21 void podulechunkdirectory(podule_t *);
     85  1.26      matt void podulescan(device_t);
     86   1.1   reinoud 
     87   1.1   reinoud /*
     88  1.26      matt  * int podulebusmatch(device_t parent, void *match, void *aux)
     89   1.1   reinoud  *
     90   1.1   reinoud  * Probe for the podule bus. Currently all this does is return 1 to
     91   1.1   reinoud  * indicate that the podule bus was found.
     92   1.1   reinoud  */
     93   1.1   reinoud 
     94   1.1   reinoud int
     95  1.26      matt podulebusmatch(device_t parent, cfdata_t cf, void *aux)
     96   1.1   reinoud {
     97   1.1   reinoud 	switch (IOMD_ID) {
     98   1.1   reinoud 	case RPC600_IOMD_ID:
     99   1.1   reinoud 	case ARM7500_IOC_ID:
    100   1.1   reinoud 	case ARM7500FE_IOC_ID:
    101   1.1   reinoud 		return(1);
    102   1.1   reinoud 	}
    103   1.1   reinoud 	return (0);
    104   1.1   reinoud }
    105   1.1   reinoud 
    106   1.1   reinoud 
    107   1.1   reinoud int
    108  1.22       dsl podulebusprint(void *aux, const char *name)
    109   1.1   reinoud {
    110   1.1   reinoud 	struct podule_attach_args *pa = aux;
    111   1.1   reinoud 
    112   1.1   reinoud 	if (name)
    113  1.15   thorpej 		aprint_normal("podule at %s", name);
    114   1.1   reinoud 	if (pa->pa_podule->slottype == SLOT_POD)
    115  1.15   thorpej 		aprint_normal(" slot %d", pa->pa_podule_number);
    116   1.1   reinoud 	else if (pa->pa_podule->slottype == SLOT_NET)
    117  1.15   thorpej 		aprint_normal(" [ netslot %d ]",
    118  1.15   thorpej 		    pa->pa_podule_number - MAX_PODULES);
    119   1.1   reinoud #ifdef DIAGNOSTIC
    120   1.1   reinoud 	else
    121  1.11    provos 		panic("Invalid slot type");
    122   1.1   reinoud #endif
    123   1.1   reinoud 
    124   1.1   reinoud 	return (UNCONF);
    125   1.1   reinoud }
    126   1.1   reinoud 
    127   1.1   reinoud 
    128   1.1   reinoud int
    129  1.26      matt podulebussubmatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    130   1.1   reinoud {
    131   1.1   reinoud 	struct podule_attach_args *pa = aux;
    132   1.1   reinoud 
    133   1.1   reinoud 	/* Return priority 0 or 1 for wildcarded podule */
    134   1.1   reinoud 
    135   1.1   reinoud 	if (cf->cf_loc[PODULEBUSCF_SLOT] == PODULEBUSCF_SLOT_DEFAULT)
    136  1.10   thorpej 		return(config_match(parent, cf, aux));
    137   1.1   reinoud 
    138   1.1   reinoud 	/* Return higher priority if we match the specific podule */
    139   1.1   reinoud 
    140   1.1   reinoud 	else if (cf->cf_loc[PODULEBUSCF_SLOT] == pa->pa_podule_number)
    141  1.10   thorpej 		return(config_match(parent, cf, aux) * 8);
    142   1.1   reinoud 
    143   1.1   reinoud 	/* Fail */
    144   1.1   reinoud 	return(0);
    145   1.1   reinoud }
    146   1.1   reinoud 
    147   1.1   reinoud 
    148   1.1   reinoud #if 0
    149   1.1   reinoud void
    150  1.22       dsl dump_podule(podule_t *podule)
    151   1.1   reinoud {
    152   1.1   reinoud 	printf("podule%d: ", podule->podulenum);
    153   1.1   reinoud 	printf("flags0=%02x ", podule->flags0);
    154   1.1   reinoud 	printf("flags1=%02x ", podule->flags1);
    155   1.1   reinoud 	printf("reserved=%02x ", podule->reserved);
    156   1.1   reinoud 	printf("product=%02x ", podule->product);
    157   1.1   reinoud 	printf("manufacturer=%02x ", podule->manufacturer);
    158   1.1   reinoud 	printf("country=%02x ", podule->country);
    159   1.1   reinoud 	printf("irq_addr=%08x ", podule->irq_addr);
    160   1.1   reinoud 	printf("irq_mask=%02x ", podule->irq_mask);
    161   1.1   reinoud 	printf("fiq_addr=%08x ", podule->fiq_addr);
    162   1.1   reinoud 	printf("fiq_mask=%02x ", podule->fiq_mask);
    163   1.1   reinoud 	printf("fast_base=%08x ", podule->fast_base);
    164   1.1   reinoud 	printf("medium_base=%08x ", podule->medium_base);
    165   1.1   reinoud 	printf("slow_base=%08x ", podule->slow_base);
    166   1.1   reinoud 	printf("sync_base=%08x ", podule->sync_base);
    167   1.1   reinoud 	printf("mod_base=%08x ", podule->mod_base);
    168   1.1   reinoud 	printf("easi_base=%08x ", podule->easi_base);
    169   1.1   reinoud 	printf("attached=%d ", podule->attached);
    170   1.1   reinoud 	printf("slottype=%d ", podule->slottype);
    171   1.1   reinoud 	printf("podulenum=%d ", podule->podulenum);
    172   1.1   reinoud 	printf("description=%s ", podule->description);
    173   1.1   reinoud 	printf("\n");
    174   1.1   reinoud }
    175   1.1   reinoud #endif
    176   1.1   reinoud 
    177   1.1   reinoud void
    178  1.22       dsl podulechunkdirectory(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.26      matt poduleexamine(podule_t *podule, device_t dev, int slottype)
    233   1.1   reinoud {
    234   1.9     bjh21 	struct manufacturer_description *man_desc;
    235   1.1   reinoud 	struct podule_description *pod_desc;
    236   1.1   reinoud 
    237   1.1   reinoud 	/* Test to see if the podule is present */
    238   1.1   reinoud 
    239   1.1   reinoud 	if ((podule->flags0 & 0x02) == 0x00) {
    240   1.1   reinoud 		podule->slottype = slottype;
    241   1.1   reinoud 		if (slottype == SLOT_NET)
    242   1.1   reinoud 			printf("netslot%d at %s : ", podule->podulenum - MAX_PODULES,
    243  1.25    cegger 			    device_xname(dev));
    244   1.1   reinoud 		else
    245   1.1   reinoud 			printf("podule%d  at %s : ", podule->podulenum,
    246  1.25    cegger 			    device_xname(dev));
    247   1.1   reinoud 
    248   1.1   reinoud 		/* Is it Acorn conformant ? */
    249   1.1   reinoud 
    250   1.1   reinoud 		if (podule->flags0 & 0x80)
    251   1.1   reinoud 			printf("Non-Acorn conformant expansion card\n");
    252   1.1   reinoud 		else {
    253   1.1   reinoud 			int id;
    254   1.1   reinoud 
    255   1.1   reinoud 			/* Is it a simple podule ? */
    256   1.1   reinoud 
    257   1.1   reinoud 			id = (podule->flags0 >> 3) & 0x0f;
    258   1.1   reinoud 			if (id != 0)
    259   1.1   reinoud 				printf("Simple expansion card <%x>\n", id);
    260   1.1   reinoud 			else {
    261   1.1   reinoud 				/* Scan the chunk directory if present for tags we use */
    262   1.1   reinoud 				if (podule->flags1 & PODULE_FLAGS_CD)
    263   1.1   reinoud 					podulechunkdirectory(podule);
    264   1.1   reinoud 
    265   1.1   reinoud 				/* Do we know this manufacturer ? */
    266   1.9     bjh21 				man_desc = known_manufacturers;
    267   1.9     bjh21 				while (man_desc->description) {
    268   1.9     bjh21 					if (man_desc->manufacturer_id ==
    269   1.9     bjh21 					    podule->manufacturer)
    270   1.1   reinoud 						break;
    271   1.9     bjh21 					++man_desc;
    272   1.1   reinoud 				}
    273   1.9     bjh21 				if (!man_desc->description)
    274   1.1   reinoud 					printf("man=%04x   : ", podule->manufacturer);
    275   1.1   reinoud 				else
    276   1.9     bjh21 					printf("%s : ", man_desc->description);
    277   1.1   reinoud 
    278   1.1   reinoud 				/* Do we know this product ? */
    279   1.1   reinoud 
    280   1.9     bjh21 				pod_desc = known_podules;
    281   1.1   reinoud 				while (pod_desc->description) {
    282   1.1   reinoud 					if (pod_desc->product_id == podule->product)
    283   1.1   reinoud 						break;
    284   1.1   reinoud 					++pod_desc;
    285   1.1   reinoud 				}
    286   1.9     bjh21 				if (!pod_desc->description)
    287   1.9     bjh21 					printf("prod=%04x : ",
    288   1.9     bjh21 					    podule->product);
    289   1.9     bjh21 				else
    290   1.9     bjh21 					printf("%s : ", pod_desc->description);
    291   1.9     bjh21 				printf("%s\n", podule->description);
    292   1.1   reinoud 			}
    293   1.1   reinoud 		}
    294   1.1   reinoud 	}
    295   1.1   reinoud }
    296   1.1   reinoud 
    297   1.1   reinoud 
    298   1.1   reinoud u_int
    299  1.22       dsl poduleread(u_int address, int offset)
    300   1.1   reinoud {
    301   1.1   reinoud 
    302   1.1   reinoud 	return(ReadByte(address + offset));
    303   1.1   reinoud }
    304   1.1   reinoud 
    305   1.1   reinoud void
    306  1.26      matt podulescan(device_t dev)
    307   1.1   reinoud {
    308   1.1   reinoud 	int loop;
    309   1.1   reinoud 	podule_t *podule;
    310   1.1   reinoud 	u_char *address;
    311   1.1   reinoud 	u_int offset = 0;
    312   1.1   reinoud 
    313   1.1   reinoud 	/* Loop round all the podules */
    314   1.1   reinoud 
    315   1.1   reinoud 	for (loop = 0; loop < MAX_PODULES; ++loop, offset += SIMPLE_PODULE_SIZE) {
    316   1.1   reinoud 		podule = &podules[loop];
    317   1.1   reinoud 		podule->podulenum = loop;
    318   1.1   reinoud 		podule->attached = 0;
    319   1.1   reinoud 		podule->slottype = SLOT_NONE;
    320   1.1   reinoud 		podule->interrupt = IRQ_PODULE;
    321   1.1   reinoud 		podule->read_rom = poduleread;
    322   1.1   reinoud 		podule->dma_channel = -1;
    323   1.1   reinoud 		podule->dma_interrupt = -1;
    324   1.1   reinoud 		podule->description[0] = 0;
    325   1.1   reinoud 
    326   1.1   reinoud 		if (loop == 4) offset += PODULE_GAP;
    327   1.1   reinoud 		address = ((u_char *)SYNC_PODULE_BASE) + offset;
    328   1.1   reinoud 
    329   1.1   reinoud 		if ((address[0] & 0x02) == 0x00) {
    330   1.1   reinoud 			podule->fast_base = FAST_PODULE_BASE + offset;
    331   1.1   reinoud 			podule->medium_base = MEDIUM_PODULE_BASE + offset;
    332   1.1   reinoud 			podule->slow_base = SLOW_PODULE_BASE + offset;
    333   1.1   reinoud 			podule->sync_base = SYNC_PODULE_BASE + offset;
    334   1.1   reinoud 			podule->mod_base = MOD_PODULE_BASE + offset;
    335   1.1   reinoud 			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
    336   1.1   reinoud 		} else {
    337   1.1   reinoud 			address = ((u_char *)EASI_BASE) + loop * EASI_SIZE;
    338   1.1   reinoud 			if ((address[0] & 0x02) != 0x00)
    339   1.1   reinoud 				continue;
    340   1.1   reinoud 
    341   1.1   reinoud 			podule->fast_base = 0;
    342   1.1   reinoud 			podule->medium_base = 0;
    343   1.1   reinoud 			podule->slow_base = 0;
    344   1.1   reinoud 			podule->sync_base = 0;
    345   1.1   reinoud 			podule->mod_base = 0;
    346   1.1   reinoud 			podule->easi_base = EASI_BASE + loop * EASI_SIZE;
    347   1.1   reinoud 		}
    348   1.1   reinoud 
    349   1.1   reinoud 		/* XXX - Really needs to be linked to a DMA manager */
    350   1.1   reinoud 		if (IOMD_ID == RPC600_IOMD_ID) {
    351   1.1   reinoud 			switch (loop) {
    352   1.1   reinoud 			case 0:
    353   1.1   reinoud 				podule->dma_channel = 2;
    354   1.1   reinoud 				podule->dma_interrupt = IRQ_DMACH2;
    355   1.1   reinoud 				break;
    356   1.1   reinoud 			case 1:
    357   1.1   reinoud 				podule->dma_channel = 3;
    358   1.1   reinoud 				podule->dma_interrupt = IRQ_DMACH3;
    359   1.1   reinoud 				break;
    360   1.1   reinoud 			}
    361   1.1   reinoud 		}
    362   1.1   reinoud 
    363   1.1   reinoud 		/* Get information from the podule header */
    364   1.1   reinoud 
    365   1.1   reinoud 		podule->flags0 = address[0];
    366   1.1   reinoud 		if ((podule->flags0 & 0x78) == 0) {
    367   1.1   reinoud 			podule->flags1 = address[4];
    368   1.1   reinoud 			podule->reserved = address[8];
    369   1.1   reinoud 			podule->product = address[12] + (address[16] << 8);
    370   1.1   reinoud 			podule->manufacturer = address[20] + (address[24] << 8);
    371   1.1   reinoud 			podule->country = address[28];
    372   1.1   reinoud 			if (podule->flags1 & PODULE_FLAGS_IS) {
    373   1.1   reinoud 				podule->irq_addr = address[52] + (address[56] << 8) + (address[60] << 16);
    374   1.1   reinoud 				podule->irq_addr += podule->slow_base;
    375   1.1   reinoud 				podule->irq_mask = address[48];
    376   1.1   reinoud 				if (podule->irq_mask == 0)
    377   1.1   reinoud 					podule->irq_mask = 0x01;
    378   1.1   reinoud 				podule->fiq_addr = address[36] + (address[40] << 8) + (address[44] << 16);
    379   1.1   reinoud 				podule->fiq_addr += podule->slow_base;
    380   1.1   reinoud 				podule->fiq_mask = address[32];
    381   1.1   reinoud 				if (podule->fiq_mask == 0)
    382   1.1   reinoud 					podule->fiq_mask = 0x04;
    383   1.1   reinoud 			} else {
    384   1.1   reinoud 				podule->irq_addr = podule->slow_base;
    385   1.1   reinoud 				podule->irq_mask = 0x01;
    386   1.1   reinoud 				podule->fiq_addr = podule->slow_base;
    387   1.1   reinoud 				podule->fiq_mask = 0x04;
    388   1.1   reinoud 			}
    389   1.1   reinoud 		}
    390   1.1   reinoud 
    391   1.1   reinoud 		poduleexamine(podule, dev, SLOT_POD);
    392   1.1   reinoud 	}
    393   1.1   reinoud }
    394   1.1   reinoud 
    395   1.1   reinoud 
    396   1.1   reinoud /*
    397  1.26      matt  * void podulebusattach(device_t parent, device_t dev, void *aux)
    398   1.1   reinoud  *
    399   1.1   reinoud  * Attach podulebus.
    400   1.1   reinoud  * This probes all the podules and sets up the podules array with
    401   1.1   reinoud  * information found in the podule headers.
    402  1.34    andvar  * After identifying all the podules, all the children of the podulebus
    403   1.1   reinoud  * are probed and attached.
    404   1.1   reinoud  */
    405   1.1   reinoud 
    406   1.1   reinoud void
    407  1.26      matt podulebusattach(device_t parent, device_t self, void *aux)
    408   1.1   reinoud {
    409   1.1   reinoud 	int loop;
    410   1.1   reinoud 	struct podule_attach_args pa;
    411   1.1   reinoud #if 0
    412   1.1   reinoud 	int easi_time;
    413   1.1   reinoud 	int bit;
    414   1.1   reinoud #endif
    415   1.1   reinoud 	unsigned int value;
    416   1.1   reinoud 	char argstring[20];
    417   1.1   reinoud 
    418   1.1   reinoud #if 0
    419   1.1   reinoud 	easi_time = IOMD_READ_BYTE(IOMD_ECTCR);
    420   1.1   reinoud 	printf(": easi timings=");
    421   1.1   reinoud 	for (bit = 0x01; bit < 0x100; bit = bit << 1)
    422   1.1   reinoud 		if (easi_time & bit)
    423   1.1   reinoud 			printf("C");
    424   1.1   reinoud 		else
    425   1.1   reinoud 			printf("A");
    426   1.1   reinoud #endif
    427   1.1   reinoud 	printf("\n");
    428   1.1   reinoud 
    429  1.16     chris 
    430  1.17   thorpej #if 0 /* XXXJRT */
    431   1.1   reinoud 	/* Ok we need to map in the podulebus */
    432  1.16     chris 	/* with the new pmap mappings have to be done when the L1 tables
    433  1.16     chris 	 * are built during initarm
    434  1.16     chris 	 */
    435   1.1   reinoud 	/* Map the FAST and SYNC simple podules */
    436  1.28      matt 	pmap_map_section((vaddr_t)pmap_kernel()->pm_pdir,
    437   1.6   thorpej 	    SYNC_PODULE_BASE & 0xfff00000, SYNC_PODULE_HW_BASE & 0xfff00000,
    438   1.6   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    439   1.1   reinoud 	cpu_tlb_flushD();
    440   1.1   reinoud 	/* Now map the EASI space */
    441   1.1   reinoud 
    442   1.1   reinoud 	for (loop = 0; loop < MAX_PODULES; ++loop) {
    443   1.1   reinoud 		int loop1;
    444   1.1   reinoud 
    445   1.1   reinoud 		for (loop1 = loop * EASI_SIZE; loop1 < ((loop + 1) * EASI_SIZE);
    446   1.8   thorpej 		    loop1 += L1_S_SIZE)
    447  1.28      matt 		pmap_map_section((vaddr_t)pmap_kernel()->pm_pdir,
    448   1.6   thorpej 		    EASI_BASE + loop1, EASI_HW_BASE + loop1,
    449   1.6   thorpej 		    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    450   1.1   reinoud 	}
    451   1.1   reinoud 	cpu_tlb_flushD();
    452  1.16     chris #endif
    453   1.1   reinoud 	/*
    454   1.1   reinoud 	 * The MEDIUM and SLOW simple podules and the module space will have been
    455   1.1   reinoud 	 * mapped when the IOMD and COMBO we mapped in for the RPC
    456   1.1   reinoud 	 */
    457   1.1   reinoud 
    458   1.1   reinoud 	/* Find out what hardware is bolted on */
    459   1.1   reinoud 
    460   1.1   reinoud 	podulescan(self);
    461   1.1   reinoud 	netslotscan(self);
    462   1.1   reinoud 
    463   1.1   reinoud 	/* Look for drivers to attach */
    464   1.1   reinoud 
    465   1.1   reinoud 	for (loop = 0; loop < MAX_PODULES+MAX_NETSLOTS; ++loop) {
    466   1.1   reinoud #if 1
    467   1.1   reinoud 		/* Provide backwards compat for a while */
    468  1.27  christos 		snprintf(argstring, sizeof(argstring), "podule%d.disable", loop);
    469   1.1   reinoud 		if (get_bootconf_option(boot_args, argstring,
    470   1.1   reinoud 		    BOOTOPT_TYPE_BOOLEAN, &value)) {
    471   1.1   reinoud 			if (value) {
    472   1.1   reinoud 				if (podules[loop].slottype != SLOT_NONE)
    473   1.1   reinoud 					printf("podule%d: Disabled\n", loop);
    474   1.1   reinoud 				continue;
    475   1.1   reinoud 			}
    476   1.1   reinoud  		}
    477   1.1   reinoud #endif
    478  1.27  christos  		snprintf(argstring, sizeof(argstring), "podule%d=", loop);
    479   1.1   reinoud  		if (get_bootconf_option(boot_args, argstring,
    480   1.1   reinoud  		    BOOTOPT_TYPE_HEXINT, &value)) {
    481   1.1   reinoud 			/* Override the ID */
    482   1.1   reinoud 			podules[loop].manufacturer = value >> 16;
    483   1.1   reinoud  			podules[loop].product = value & 0xffff;
    484   1.1   reinoud 			/* Any old description is now wrong */
    485   1.1   reinoud 			podules[loop].description[0] = 0;
    486   1.1   reinoud 			if (value != 0xffff) {
    487  1.33    andvar 				printf("podule%d: ID overridden man=%04x prod=%04x\n",
    488   1.1   reinoud 				    loop, podules[loop].manufacturer,
    489   1.1   reinoud 				    podules[loop].product);
    490   1.1   reinoud 				podules[loop].slottype = SLOT_POD;
    491   1.1   reinoud 				pa.pa_podule_number = loop;
    492   1.1   reinoud 				pa.pa_ih = pa.pa_podule_number;
    493   1.1   reinoud 				pa.pa_podule = &podules[loop];
    494   1.1   reinoud 				pa.pa_iot = &podulebus_bs_tag;
    495  1.31   thorpej 				config_found(self, &pa, podulebusprint,
    496  1.32   thorpej 				    CFARGS(.submatch = podulebussubmatch));
    497   1.1   reinoud 				continue;
    498   1.1   reinoud 			}
    499   1.1   reinoud 			if (value == 0xffff) {
    500   1.1   reinoud 				printf("podule%d: Disabled\n", loop);
    501   1.1   reinoud 				continue;
    502   1.1   reinoud 			}
    503   1.1   reinoud 		}
    504   1.1   reinoud 
    505   1.1   reinoud 		if (podules[loop].slottype != SLOT_NONE) {
    506   1.1   reinoud 			pa.pa_podule_number = loop;
    507   1.1   reinoud 			pa.pa_ih = pa.pa_podule_number;
    508   1.1   reinoud 			pa.pa_podule = &podules[loop];
    509   1.1   reinoud 			pa.pa_iot = &podulebus_bs_tag;
    510  1.31   thorpej 			config_found(self, &pa, podulebusprint,
    511  1.32   thorpej 			    CFARGS(.submatch = podulebussubmatch));
    512   1.1   reinoud 		}
    513   1.1   reinoud 	}
    514   1.1   reinoud }
    515   1.1   reinoud 
    516   1.1   reinoud 
    517  1.26      matt CFATTACH_DECL_NEW(podulebus, 0,
    518  1.13   thorpej 	podulebusmatch, podulebusattach, NULL, NULL);
    519   1.1   reinoud 
    520   1.1   reinoud /* Useful functions that drivers may share */
    521   1.1   reinoud 
    522   1.1   reinoud /*
    523   1.1   reinoud  * Match a podule structure with the specified parameters
    524   1.1   reinoud  * Returns 0 if the match failed
    525   1.1   reinoud  * The required_slot is not used at the moment.
    526   1.1   reinoud  */
    527   1.1   reinoud 
    528   1.1   reinoud int
    529  1.22       dsl matchpodule(struct podule_attach_args *pa, int manufacturer, int product, int required_slot)
    530   1.1   reinoud {
    531   1.1   reinoud 	if (pa->pa_podule->attached)
    532  1.11    provos 		panic("podulebus: Podule already attached");
    533   1.1   reinoud 
    534   1.1   reinoud 	if (IS_PODULE(pa, manufacturer, product))
    535   1.1   reinoud 		return(1);
    536   1.1   reinoud 
    537   1.1   reinoud 	return(0);
    538   1.1   reinoud }
    539   1.1   reinoud 
    540   1.1   reinoud void *
    541  1.24    cegger podulebus_irq_establish(podulebus_intr_handle_t ih,
    542  1.24    cegger 	int ipl, int (*func)(void *), void *arg, struct evcnt *ev)
    543   1.1   reinoud {
    544   1.1   reinoud 
    545   1.1   reinoud 	/* XXX We don't actually use the evcnt supplied, just its name. */
    546   1.1   reinoud 	return intr_claim(podules[ih].interrupt, ipl, ev->ev_group, func,
    547   1.1   reinoud 	    arg);
    548   1.1   reinoud }
    549   1.1   reinoud 
    550   1.1   reinoud /*
    551   1.1   reinoud  * Generate a bus_space_tag_t with the specified address-bus shift.
    552   1.1   reinoud  */
    553   1.1   reinoud void
    554  1.23       dsl podulebus_shift_tag(bus_space_tag_t tag, u_int shift, bus_space_tag_t *tagp)
    555   1.1   reinoud {
    556   1.1   reinoud 
    557   1.1   reinoud 	/*
    558   1.1   reinoud 	 * For the podulebus, the bus tag cookie is the shift to apply
    559   1.1   reinoud 	 * to registers, so duplicate the bus space tag and change the
    560   1.1   reinoud 	 * cookie.
    561   1.1   reinoud 	 */
    562   1.1   reinoud 
    563   1.1   reinoud 	/* XXX never freed, but podules are never detached anyway. */
    564  1.30   thorpej         *tagp = kmem_alloc(sizeof(struct bus_space), KM_SLEEP);
    565   1.1   reinoud 	**tagp = *tag;
    566   1.1   reinoud 	(*tagp)->bs_cookie = (void *)shift;
    567   1.1   reinoud }
    568   1.1   reinoud 
    569   1.1   reinoud int
    570   1.1   reinoud podulebus_initloader(struct podulebus_attach_args *pa)
    571   1.1   reinoud {
    572   1.1   reinoud 
    573   1.1   reinoud 	/* No loader support at present on arm32, so always fail. */
    574   1.1   reinoud 	return -1;
    575   1.1   reinoud }
    576   1.1   reinoud 
    577   1.1   reinoud int
    578   1.1   reinoud podloader_readbyte(struct podulebus_attach_args *pa, u_int addr)
    579   1.1   reinoud {
    580   1.1   reinoud 
    581   1.1   reinoud 	panic("podloader_readbyte");
    582   1.1   reinoud }
    583   1.1   reinoud 
    584   1.1   reinoud void
    585   1.1   reinoud podloader_writebyte(struct podulebus_attach_args *pa, u_int addr, int val)
    586   1.1   reinoud {
    587   1.1   reinoud 
    588   1.1   reinoud 	panic("podloader_writebyte");
    589   1.1   reinoud }
    590   1.1   reinoud 
    591   1.1   reinoud void
    592   1.1   reinoud podloader_reset(struct podulebus_attach_args *pa)
    593   1.1   reinoud {
    594   1.1   reinoud 
    595   1.1   reinoud 	panic("podloader_reset");
    596   1.1   reinoud }
    597   1.1   reinoud 
    598   1.1   reinoud int
    599   1.1   reinoud podloader_callloader(struct podulebus_attach_args *pa, u_int r0, u_int r1)
    600   1.1   reinoud {
    601   1.1   reinoud 
    602   1.1   reinoud 	panic("podloader_callloader");
    603   1.1   reinoud }
    604   1.1   reinoud 
    605   1.1   reinoud /* End of podulebus.c */
    606