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