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