Home | History | Annotate | Line # | Download | only in podulebus
netslot.c revision 1.2
      1 /*	$NetBSD: netslot.c,v 1.2 2001/11/22 18:34:33 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 
     36 #include <sys/param.h>
     37 
     38 __KERNEL_RCSID(1, "$Id: netslot.c,v 1.2 2001/11/22 18:34:33 thorpej Exp $");
     39 
     40 #include <sys/systm.h>
     41 #include <sys/kernel.h>
     42 #include <sys/conf.h>
     43 #include <sys/malloc.h>
     44 #include <sys/device.h>
     45 #include <uvm/uvm_extern.h>
     46 #include <machine/io.h>
     47 #include <arm/arm32/katelib.h>
     48 #include <machine/irqhandler.h>
     49 #include <machine/bootconfig.h>
     50 #include <machine/pte.h>
     51 #include <machine/pmap.h>
     52 #include <arm/iomd/iomdreg.h>
     53 #include <arm/iomd/iomdvar.h>
     54 #include <dev/podulebus/podulebus.h>
     55 #include <dev/podulebus/podules.h>
     56 
     57 u_int netslotread __P((u_int, int));
     58 
     59 u_int
     60 netslotread(address, offset)
     61 	u_int address;
     62 	int offset;
     63 {
     64 	static int netslotoffset = -1;
     65 
     66 	offset = offset >> 2;
     67 	if (netslotoffset == -1 || offset < netslotoffset) {
     68 		WriteByte(address, 0);
     69 		netslotoffset = 0;
     70 	}
     71 	while (netslotoffset < offset) {
     72 		(void)ReadByte(address);
     73 		++netslotoffset;
     74 	}
     75 	++netslotoffset;
     76 	return(ReadByte(address));
     77 }
     78 
     79 void
     80 netslotscan(dev)
     81 	struct device *dev;
     82 {
     83 	podule_t *podule;
     84 	volatile u_char *address;
     85 
     86 	/* Only one netslot atm */
     87 
     88 	/* Reset the address counter */
     89 
     90 	WriteByte(NETSLOT_BASE, 0x00);
     91 
     92 	address = (u_char *)NETSLOT_BASE;
     93 
     94 	podule = &podules[MAX_PODULES];
     95 
     96 	podule->fast_base = NETSLOT_BASE;
     97 	podule->medium_base = NETSLOT_BASE;
     98 	podule->slow_base = NETSLOT_BASE;
     99 	podule->sync_base = NETSLOT_BASE;
    100 	podule->mod_base = NETSLOT_BASE;
    101 	podule->easi_base = 0;
    102 	podule->attached = 0;
    103 	podule->slottype = SLOT_NONE;
    104 	podule->podulenum = MAX_PODULES;
    105 	podule->interrupt = IRQ_NETSLOT;
    106 	podule->read_rom = netslotread;
    107 	podule->dma_channel = -1;
    108 	podule->dma_interrupt = -1;
    109 	podule->description[0] = 0;
    110 
    111 	/* XXX - Really needs to be linked to a DMA manager */
    112 	if (IOMD_ID == RPC600_IOMD_ID)
    113 		podule->dma_channel = 0;
    114 
    115 	/* Get information from the podule header */
    116 
    117 	podule->flags0 = *address;
    118 	podule->flags1 = *address;
    119 	podule->reserved = *address;
    120 	podule->product = *address;
    121 	podule->product += (*address << 8);
    122 	podule->manufacturer = *address;
    123 	podule->manufacturer += (*address << 8);
    124 	podule->country = *address;
    125 	if (podule->flags1 & PODULE_FLAGS_IS) {
    126 		podule->irq_mask = *address;
    127 		podule->irq_addr = *address;
    128 		podule->irq_addr += (*address << 8);
    129 		podule->irq_addr += (*address << 16);
    130 		podule->irq_addr += podule->slow_base;
    131 		if (podule->irq_mask == 0)
    132 			podule->irq_mask = 0x01;
    133 		podule->fiq_mask = *address;
    134 		podule->fiq_addr = *address;
    135 		podule->fiq_addr += (*address << 8);
    136 		podule->fiq_addr += (*address << 16);
    137 		podule->fiq_addr += podule->slow_base;
    138 		if (podule->fiq_mask == 0)
    139 			podule->fiq_mask = 0x04;
    140 	} else {
    141 		podule->irq_addr = podule->slow_base;
    142 		podule->irq_mask = 0x01;
    143 		podule->fiq_addr = podule->slow_base;
    144 		podule->fiq_mask = 0x04;
    145 	}
    146 
    147 	poduleexamine(podule, dev, SLOT_NET);
    148 }
    149 
    150 void
    151 netslot_ea(buffer)
    152 	u_int8_t *buffer;
    153 {
    154 	/* Build station address from machine ID */
    155 	buffer[0] = 0x00;
    156 	buffer[1] = 0x00;
    157 	buffer[2] = 0xa4;
    158 	buffer[3] = bootconfig.machine_id[2] + 0x10;
    159 	buffer[4] = bootconfig.machine_id[1];
    160 	buffer[5] = bootconfig.machine_id[0];
    161 }
    162