1/*	$NetBSD: netslot.c,v 1.12 2023/12/20 06:13:59 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, "$NetBSD: netslot.c,v 1.12 2023/12/20 06:13:59 thorpej Exp $");
39
40#include <sys/systm.h>
41#include <sys/kernel.h>
42#include <sys/conf.h>
43#include <sys/device.h>
44#include <uvm/uvm_extern.h>
45#include <machine/io.h>
46#include <machine/intr.h>
47#include <machine/bootconfig.h>
48#include <arm/iomd/iomdreg.h>
49#include <arm/iomd/iomdvar.h>
50#include <dev/podulebus/podulebus.h>
51#include <dev/podulebus/podules.h>
52
53#define WriteByte(a, b) \
54    *((volatile unsigned char *)(a)) = (b)
55#define ReadByte(a) \
56    (*((volatile unsigned char *)(a)))
57
58u_int netslotread(u_int, int);
59
60u_int
61netslotread(u_int address, int offset)
62{
63	static int netslotoffset = -1;
64
65	offset = offset >> 2;
66	if (netslotoffset == -1 || offset < netslotoffset) {
67		WriteByte(address, 0);
68		netslotoffset = 0;
69	}
70	while (netslotoffset < offset) {
71		(void)ReadByte(address);
72		++netslotoffset;
73	}
74	++netslotoffset;
75	return(ReadByte(address));
76}
77
78void
79netslotscan(device_t 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
148void
149netslot_ea(uint8_t *buffer)
150{
151	/* Build station address from machine ID */
152	buffer[0] = 0x00;
153	buffer[1] = 0x00;
154	buffer[2] = 0xa4;
155	buffer[3] = bootconfig.machine_id[2] + 0x10;
156	buffer[4] = bootconfig.machine_id[1];
157	buffer[5] = bootconfig.machine_id[0];
158}
159