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