xref: /netbsd-src/sys/arch/sgimips/hpc/hpc.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: hpc.c,v 1.73 2021/08/07 16:19:04 thorpej Exp $	*/
2c4173c40Sthorpej 
3c4173c40Sthorpej /*
4c4173c40Sthorpej  * Copyright (c) 2000 Soren S. Jorvang
5c4173c40Sthorpej  * Copyright (c) 2001 Rafal K. Boni
6be010c72Sthorpej  * Copyright (c) 2001 Jason R. Thorpe
7c4173c40Sthorpej  * All rights reserved.
8c4173c40Sthorpej  *
9c4173c40Sthorpej  * Redistribution and use in source and binary forms, with or without
10c4173c40Sthorpej  * modification, are permitted provided that the following conditions
11c4173c40Sthorpej  * are met:
12c4173c40Sthorpej  * 1. Redistributions of source code must retain the above copyright
13c4173c40Sthorpej  *    notice, this list of conditions and the following disclaimer.
14c4173c40Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
15c4173c40Sthorpej  *    notice, this list of conditions and the following disclaimer in the
16c4173c40Sthorpej  *    documentation and/or other materials provided with the distribution.
17c4173c40Sthorpej  * 3. All advertising materials mentioning features or use of this software
18c4173c40Sthorpej  *    must display the following acknowledgement:
19c4173c40Sthorpej  *          This product includes software developed for the
2007147999Skeihan  *          NetBSD Project.  See http://www.NetBSD.org/ for
21c4173c40Sthorpej  *          information about NetBSD.
22c4173c40Sthorpej  * 4. The name of the author may not be used to endorse or promote products
23c4173c40Sthorpej  *    derived from this software without specific prior written permission.
24c4173c40Sthorpej  *
25c4173c40Sthorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26c4173c40Sthorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27c4173c40Sthorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28c4173c40Sthorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29c4173c40Sthorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30c4173c40Sthorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31c4173c40Sthorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32c4173c40Sthorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33c4173c40Sthorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34c4173c40Sthorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35c4173c40Sthorpej  */
36c4173c40Sthorpej 
37ed517291Slukem #include <sys/cdefs.h>
38*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: hpc.c,v 1.73 2021/08/07 16:19:04 thorpej Exp $");
39ed517291Slukem 
40c4173c40Sthorpej #include <sys/param.h>
41c4173c40Sthorpej #include <sys/systm.h>
42d2895075Ssekiya #include <sys/kernel.h>
43c4173c40Sthorpej #include <sys/device.h>
44c4173c40Sthorpej #include <sys/reboot.h>
45d2895075Ssekiya #include <sys/callout.h>
46c4173c40Sthorpej 
47cf10107dSdyoung #include <sys/bus.h>
48c4173c40Sthorpej #include <machine/machtype.h>
491426ceedSrumble #include <machine/sysconf.h>
50c4173c40Sthorpej 
51c4173c40Sthorpej #include <sgimips/gio/gioreg.h>
52c4173c40Sthorpej #include <sgimips/gio/giovar.h>
53c4173c40Sthorpej 
54c4173c40Sthorpej #include <sgimips/hpc/hpcvar.h>
55c4173c40Sthorpej #include <sgimips/hpc/hpcreg.h>
56b91ae185Ssekiya #include <sgimips/ioc/iocreg.h>
57c4173c40Sthorpej 
58121e1e9bSrumble #include <dev/ic/smc93cx6var.h>
59121e1e9bSrumble 
60c4173c40Sthorpej #include "locators.h"
61c4173c40Sthorpej 
6215065b7eSrumble struct hpc_device {
63be010c72Sthorpej 	const char *hd_name;
64d15d0532Srumble 	bus_addr_t hd_base;
65be010c72Sthorpej 	bus_addr_t hd_devoff;
66be010c72Sthorpej 	bus_addr_t hd_dmaoff;
67be010c72Sthorpej 	int hd_irq;
68be010c72Sthorpej 	int hd_sysmask;
6915065b7eSrumble };
7015065b7eSrumble 
7115065b7eSrumble static const struct hpc_device hpc1_devices[] = {
7215065b7eSrumble 	/* probe order is important for IP20 zsc */
7315065b7eSrumble 
7415065b7eSrumble 	{ "zsc",        /* Personal Iris/Indigo serial 0/1 duart 1 */
7515065b7eSrumble 	  HPC_BASE_ADDRESS_0,
7615065b7eSrumble 	  0x0d10, 0,
7715065b7eSrumble 	  5,
7815065b7eSrumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
7915065b7eSrumble 
8015065b7eSrumble 	{ "zsc",        /* Personal Iris/Indigo kbd/ms duart 0 */
8115065b7eSrumble 	  HPC_BASE_ADDRESS_0,
8215065b7eSrumble 	  0x0d00, 0,
8315065b7eSrumble 	  5,
8415065b7eSrumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
8515065b7eSrumble 
8615065b7eSrumble 	{ "sq",		/* Personal Iris/Indigo onboard ethernet */
8715065b7eSrumble 	  HPC_BASE_ADDRESS_0,
8815065b7eSrumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
8915065b7eSrumble 	  3,
9015065b7eSrumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
9115065b7eSrumble 
9215065b7eSrumble 	{ "sq",		/* E++ GIO adapter slot 0 (Indigo) */
9315065b7eSrumble 	  HPC_BASE_ADDRESS_1,
9415065b7eSrumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
9515065b7eSrumble 	  6,
9615065b7eSrumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
9715065b7eSrumble 
9815065b7eSrumble 	{ "sq",		/* E++ GIO adapter slot 0 (Indy) */
9915065b7eSrumble 	  HPC_BASE_ADDRESS_1,
10015065b7eSrumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
10115065b7eSrumble 	  22,
10215065b7eSrumble 	  HPCDEV_IP24 },
10315065b7eSrumble 
10415065b7eSrumble 	{ "sq",		/* E++ GIO adapter slot 1 (Indigo) */
10515065b7eSrumble 	  HPC_BASE_ADDRESS_2,
10615065b7eSrumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
10715065b7eSrumble 	  6,
10815065b7eSrumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
10915065b7eSrumble 
11015065b7eSrumble 	{ "sq",		/* E++ GIO adapter slot 1 (Indy/Challenge S) */
11115065b7eSrumble 	  HPC_BASE_ADDRESS_2,
11215065b7eSrumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
11315065b7eSrumble 	  23,
11415065b7eSrumble 	  HPCDEV_IP24 },
11515065b7eSrumble 
11615065b7eSrumble 	{ "wdsc",	/* Personal Iris/Indigo onboard SCSI */
11715065b7eSrumble 	  HPC_BASE_ADDRESS_0,
11815065b7eSrumble 	  HPC1_SCSI0_DEVREGS, HPC1_SCSI0_REGS,
11915065b7eSrumble 	  2,    /* XXX 1 = IRQ_LOCAL0 + 2 */
12015065b7eSrumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
12115065b7eSrumble 
12206d4753bSrumble 	{ "wdsc",	/* GIO32 SCSI adapter slot 0 (Indigo) */
12306d4753bSrumble 	  HPC_BASE_ADDRESS_1,
12406d4753bSrumble 	  HPC1_SCSI0_DEVREGS, HPC1_SCSI0_REGS,
12506d4753bSrumble 	  6,
12606d4753bSrumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
12706d4753bSrumble 
12806d4753bSrumble 	{ "wdsc",	/* GIO32 SCSI adapter slot 0 (Indy) */
12906d4753bSrumble 	  HPC_BASE_ADDRESS_1,
13006d4753bSrumble 	  HPC1_SCSI0_DEVREGS, HPC1_SCSI0_REGS,
13106d4753bSrumble 	  22,
13206d4753bSrumble 	  HPCDEV_IP24 },
13306d4753bSrumble 
13406d4753bSrumble 	{ "wdsc",	/* GIO32 SCSI adapter slot 1 (Indigo) */
13506d4753bSrumble 	  HPC_BASE_ADDRESS_2,
13606d4753bSrumble 	  HPC1_SCSI0_DEVREGS, HPC1_SCSI0_REGS,
13706d4753bSrumble 	  6,
13806d4753bSrumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
13906d4753bSrumble 
14006d4753bSrumble 	{ "wdsc",	/* GIO32 SCSI adapter slot 1 (Indy/Challenge S) */
14106d4753bSrumble 	  HPC_BASE_ADDRESS_2,
14206d4753bSrumble 	  HPC1_SCSI0_DEVREGS, HPC1_SCSI0_REGS,
14306d4753bSrumble 	  23,
14406d4753bSrumble 	  HPCDEV_IP24 },
14506d4753bSrumble 
14615065b7eSrumble 	{ NULL,
14715065b7eSrumble 	  0,
14815065b7eSrumble 	  0, 0,
14915065b7eSrumble 	  0,
15015065b7eSrumble 	  0
15115065b7eSrumble 	}
15215065b7eSrumble };
15315065b7eSrumble 
15415065b7eSrumble static const struct hpc_device hpc3_devices[] = {
15515065b7eSrumble 	{ "zsc",	/* serial 0/1 duart 0 */
156d15d0532Srumble 	  HPC_BASE_ADDRESS_0,
157be010c72Sthorpej 	  /* XXX Magic numbers */
158801f5271Srumble 	  HPC3_PBUS_CH6_DEVREGS + IOC_SERIAL_REGS, 0,
159be010c72Sthorpej 	  29,
160be010c72Sthorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
161be010c72Sthorpej 
16215065b7eSrumble 	{ "pckbc",	/* Indigo2/Indy ps2 keyboard/mouse controller */
163d15d0532Srumble 	  HPC_BASE_ADDRESS_0,
164801f5271Srumble 	  HPC3_PBUS_CH6_DEVREGS + IOC_KB_REGS, 0,
16553acd623Ssekiya 	  28,
16653acd623Ssekiya 	  HPCDEV_IP22 | HPCDEV_IP24 },
16753acd623Ssekiya 
16815065b7eSrumble 	{ "sq",		/* Indigo2/Indy/Challenge S/Challenge M onboard enet */
169d15d0532Srumble 	  HPC_BASE_ADDRESS_0,
170801f5271Srumble 	  HPC3_ENET_DEVREGS, HPC3_ENET_REGS,
171be010c72Sthorpej 	  3,
172be010c72Sthorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
173be010c72Sthorpej 
17415065b7eSrumble 	{ "sq",		/* Challenge S IOPLUS secondary ethernet */
175d15d0532Srumble 	  HPC_BASE_ADDRESS_1,
17615065b7eSrumble 	  HPC3_ENET_DEVREGS, HPC3_ENET_REGS,
1772c7e4582Srumble 	  0,
178d15d0532Srumble 	  HPCDEV_IP24 },
179d15d0532Srumble 
18015065b7eSrumble 	{ "wdsc",	/* Indigo2/Indy/Challenge S/Challenge M onboard SCSI */
181d15d0532Srumble 	  HPC_BASE_ADDRESS_0,
182801f5271Srumble 	  HPC3_SCSI0_DEVREGS, HPC3_SCSI0_REGS,
183be010c72Sthorpej 	  1,	/* XXX 1 = IRQ_LOCAL0 + 1 */
184be010c72Sthorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
185be010c72Sthorpej 
18615065b7eSrumble 	{ "wdsc",	/* Indigo2/Challenge M secondary onboard SCSI */
187d15d0532Srumble 	  HPC_BASE_ADDRESS_0,
188801f5271Srumble 	  HPC3_SCSI1_DEVREGS, HPC3_SCSI1_REGS,
189be010c72Sthorpej 	  2,	/* XXX 2 = IRQ_LOCAL0 + 2 */
190be010c72Sthorpej 	  HPCDEV_IP22 },
191be010c72Sthorpej 
19215065b7eSrumble 	{ "haltwo",	/* Indigo2/Indy onboard audio */
193d15d0532Srumble 	  HPC_BASE_ADDRESS_0,
194801f5271Srumble 	  HPC3_PBUS_CH0_DEVREGS, HPC3_PBUS_DMAREGS,
1953111a2e6Slonewolf 	  8 + 4, /* XXX IRQ_LOCAL1 + 4 */
196c8d69e8dSlonewolf 	  HPCDEV_IP22 | HPCDEV_IP24 },
1973111a2e6Slonewolf 
19815065b7eSrumble 	{ "pi1ppc",	/* Indigo2/Indy/Challenge S/Challenge M onboard pport */
1993a97f79eSkurahone 	  HPC_BASE_ADDRESS_0,
2003a97f79eSkurahone 	  HPC3_PBUS_CH6_DEVREGS + IOC_PLP_REGS, 0,
2013a97f79eSkurahone 	  -1,
2023a97f79eSkurahone 	  HPCDEV_IP22 | HPCDEV_IP24 },
2033a97f79eSkurahone 
20448e18461Smacallan 	{ "button",	/* Indy front panel */
205251df1a4Smacallan 	  HPC_BASE_ADDRESS_0,
206251df1a4Smacallan 	  HPC3_PBUS_CH6_DEVREGS + IOC_PANEL, 0,
207251df1a4Smacallan 	  9,
208251df1a4Smacallan 	  HPCDEV_IP24 },
209251df1a4Smacallan 
210be010c72Sthorpej 	{ NULL,
211d15d0532Srumble 	  0,
212be010c72Sthorpej 	  0, 0,
213be010c72Sthorpej 	  0,
214be010c72Sthorpej 	  0
215be010c72Sthorpej 	}
216be010c72Sthorpej };
217be010c72Sthorpej 
218c4173c40Sthorpej struct hpc_softc {
2198831804fStsutsui 	device_t		sc_dev;
220c4173c40Sthorpej 
221c4173c40Sthorpej 	bus_addr_t		sc_base;
222c4173c40Sthorpej 
223c4173c40Sthorpej 	bus_space_tag_t		sc_ct;
224c4173c40Sthorpej 	bus_space_handle_t	sc_ch;
225c4173c40Sthorpej };
226c4173c40Sthorpej 
227af4ac18eSsekiya static struct hpc_values hpc1_values = {
228bc577449Ssekiya 	.revision =		1,
229bc577449Ssekiya 	.scsi0_regs =		HPC1_SCSI0_REGS,
230bc577449Ssekiya 	.scsi0_regs_size =	HPC1_SCSI0_REGS_SIZE,
231bc577449Ssekiya 	.scsi0_cbp =		HPC1_SCSI0_CBP,
232bc577449Ssekiya 	.scsi0_ndbp = 		HPC1_SCSI0_NDBP,
233bc577449Ssekiya 	.scsi0_bc =		HPC1_SCSI0_BC,
234bc577449Ssekiya 	.scsi0_ctl =		HPC1_SCSI0_CTL,
235bc577449Ssekiya 	.scsi0_gio =		HPC1_SCSI0_GIO,
236bc577449Ssekiya 	.scsi0_dev =		HPC1_SCSI0_DEV,
237bc577449Ssekiya 	.scsi0_dmacfg =		HPC1_SCSI0_DMACFG,
238bc577449Ssekiya 	.scsi0_piocfg =		HPC1_SCSI0_PIOCFG,
239ee970eecSrumble 	.scsi1_regs =		0,
240ee970eecSrumble 	.scsi1_regs_size =	0,
241ee970eecSrumble 	.scsi1_cbp =		0,
242ee970eecSrumble 	.scsi1_ndbp =		0,
243ee970eecSrumble 	.scsi1_bc =		0,
244ee970eecSrumble 	.scsi1_ctl =		0,
245ee970eecSrumble 	.scsi1_gio =		0,
246ee970eecSrumble 	.scsi1_dev =		0,
247ee970eecSrumble 	.scsi1_dmacfg =		0,
248ee970eecSrumble 	.scsi1_piocfg =		0,
249bc577449Ssekiya 	.enet_regs =		HPC1_ENET_REGS,
250bc577449Ssekiya 	.enet_regs_size =	HPC1_ENET_REGS_SIZE,
251bc577449Ssekiya 	.enet_intdelay =	HPC1_ENET_INTDELAY,
2524aa50cacSrumble 	.enet_intdelayval =	HPC1_ENET_INTDELAY_OFF,
253bc577449Ssekiya 	.enetr_cbp =		HPC1_ENETR_CBP,
254bc577449Ssekiya 	.enetr_ndbp =		HPC1_ENETR_NDBP,
255bc577449Ssekiya 	.enetr_bc =		HPC1_ENETR_BC,
256bc577449Ssekiya 	.enetr_ctl =		HPC1_ENETR_CTL,
257bc577449Ssekiya 	.enetr_ctl_active =	HPC1_ENETR_CTL_ACTIVE,
258bc577449Ssekiya 	.enetr_reset =		HPC1_ENETR_RESET,
259bc577449Ssekiya 	.enetr_dmacfg =		0,
2604aa50cacSrumble 	.enetr_piocfg =		0,
261bc577449Ssekiya 	.enetx_cbp =		HPC1_ENETX_CBP,
262bc577449Ssekiya 	.enetx_ndbp =		HPC1_ENETX_NDBP,
263bc577449Ssekiya 	.enetx_bc =		HPC1_ENETX_BC,
264bc577449Ssekiya 	.enetx_ctl =		HPC1_ENETX_CTL,
265bc577449Ssekiya 	.enetx_ctl_active =	HPC1_ENETX_CTL_ACTIVE,
2664aa50cacSrumble 	.enetx_dev =		0,
267bc577449Ssekiya 	.enetr_fifo =		HPC1_ENETR_FIFO,
268bc577449Ssekiya 	.enetr_fifo_size =	HPC1_ENETR_FIFO_SIZE,
269bc577449Ssekiya 	.enetx_fifo =		HPC1_ENETX_FIFO,
270bc577449Ssekiya 	.enetx_fifo_size =	HPC1_ENETX_FIFO_SIZE,
271bc577449Ssekiya 	.scsi0_devregs_size =	HPC1_SCSI0_DEVREGS_SIZE,
272ee970eecSrumble 	.scsi1_devregs_size =	0,
273bc577449Ssekiya 	.enet_devregs =		HPC1_ENET_DEVREGS,
274bc577449Ssekiya 	.enet_devregs_size =	HPC1_ENET_DEVREGS_SIZE,
2754aa50cacSrumble 	.pbus_fifo =		0,
2764aa50cacSrumble 	.pbus_fifo_size =	0,
2774aa50cacSrumble 	.pbus_bbram =		0,
278af4ac18eSsekiya #define MAX_SCSI_XFER   (512*1024)
279bc577449Ssekiya 	.scsi_max_xfer =	MAX_SCSI_XFER,
280bc577449Ssekiya 	.scsi_dma_segs =       (MAX_SCSI_XFER / 4096),
281bc577449Ssekiya 	.scsi_dma_segs_size =	4096,
28275aae500Srumble 	.scsi_dma_datain_cmd = (HPC1_SCSI_DMACTL_ACTIVE | HPC1_SCSI_DMACTL_DIR),
28375aae500Srumble 	.scsi_dma_dataout_cmd =	HPC1_SCSI_DMACTL_ACTIVE,
284ee970eecSrumble 	.scsi_dmactl_flush =	HPC1_SCSI_DMACTL_FLUSH,
285ee970eecSrumble 	.scsi_dmactl_active =	HPC1_SCSI_DMACTL_ACTIVE,
286ee970eecSrumble 	.scsi_dmactl_reset =	HPC1_SCSI_DMACTL_RESET
287af4ac18eSsekiya };
288af4ac18eSsekiya 
289af4ac18eSsekiya static struct hpc_values hpc3_values = {
2904edb45caSsekiya 	.revision =		3,
291801f5271Srumble 	.scsi0_regs =		HPC3_SCSI0_REGS,
292801f5271Srumble 	.scsi0_regs_size =	HPC3_SCSI0_REGS_SIZE,
293801f5271Srumble 	.scsi0_cbp =		HPC3_SCSI0_CBP,
294801f5271Srumble 	.scsi0_ndbp =		HPC3_SCSI0_NDBP,
295801f5271Srumble 	.scsi0_bc =		HPC3_SCSI0_BC,
296801f5271Srumble 	.scsi0_ctl =		HPC3_SCSI0_CTL,
297801f5271Srumble 	.scsi0_gio =		HPC3_SCSI0_GIO,
298801f5271Srumble 	.scsi0_dev =		HPC3_SCSI0_DEV,
299801f5271Srumble 	.scsi0_dmacfg =		HPC3_SCSI0_DMACFG,
300801f5271Srumble 	.scsi0_piocfg =		HPC3_SCSI0_PIOCFG,
301801f5271Srumble 	.scsi1_regs =		HPC3_SCSI1_REGS,
302801f5271Srumble 	.scsi1_regs_size =	HPC3_SCSI1_REGS_SIZE,
303801f5271Srumble 	.scsi1_cbp =		HPC3_SCSI1_CBP,
304801f5271Srumble 	.scsi1_ndbp =		HPC3_SCSI1_NDBP,
305801f5271Srumble 	.scsi1_bc =		HPC3_SCSI1_BC,
306801f5271Srumble 	.scsi1_ctl =		HPC3_SCSI1_CTL,
307801f5271Srumble 	.scsi1_gio =		HPC3_SCSI1_GIO,
308801f5271Srumble 	.scsi1_dev =		HPC3_SCSI1_DEV,
309801f5271Srumble 	.scsi1_dmacfg =		HPC3_SCSI1_DMACFG,
310801f5271Srumble 	.scsi1_piocfg =		HPC3_SCSI1_PIOCFG,
311801f5271Srumble 	.enet_regs =		HPC3_ENET_REGS,
312801f5271Srumble 	.enet_regs_size =	HPC3_ENET_REGS_SIZE,
313bc577449Ssekiya 	.enet_intdelay =	0,
314bc577449Ssekiya 	.enet_intdelayval =	0,
315801f5271Srumble 	.enetr_cbp =		HPC3_ENETR_CBP,
316801f5271Srumble 	.enetr_ndbp =		HPC3_ENETR_NDBP,
317801f5271Srumble 	.enetr_bc =		HPC3_ENETR_BC,
318801f5271Srumble 	.enetr_ctl =		HPC3_ENETR_CTL,
319801f5271Srumble 	.enetr_ctl_active =	HPC3_ENETR_CTL_ACTIVE,
320801f5271Srumble 	.enetr_reset =		HPC3_ENETR_RESET,
321801f5271Srumble 	.enetr_dmacfg =		HPC3_ENETR_DMACFG,
322801f5271Srumble 	.enetr_piocfg =		HPC3_ENETR_PIOCFG,
323801f5271Srumble 	.enetx_cbp =		HPC3_ENETX_CBP,
324801f5271Srumble 	.enetx_ndbp =		HPC3_ENETX_NDBP,
325801f5271Srumble 	.enetx_bc =		HPC3_ENETX_BC,
326801f5271Srumble 	.enetx_ctl =		HPC3_ENETX_CTL,
327801f5271Srumble 	.enetx_ctl_active =	HPC3_ENETX_CTL_ACTIVE,
328801f5271Srumble 	.enetx_dev =		HPC3_ENETX_DEV,
329801f5271Srumble 	.enetr_fifo =		HPC3_ENETR_FIFO,
330801f5271Srumble 	.enetr_fifo_size =	HPC3_ENETR_FIFO_SIZE,
331801f5271Srumble 	.enetx_fifo =		HPC3_ENETX_FIFO,
332801f5271Srumble 	.enetx_fifo_size =	HPC3_ENETX_FIFO_SIZE,
333801f5271Srumble 	.scsi0_devregs_size =	HPC3_SCSI0_DEVREGS_SIZE,
334801f5271Srumble 	.scsi1_devregs_size =	HPC3_SCSI1_DEVREGS_SIZE,
335801f5271Srumble 	.enet_devregs =		HPC3_ENET_DEVREGS,
336801f5271Srumble 	.enet_devregs_size =	HPC3_ENET_DEVREGS_SIZE,
337801f5271Srumble 	.pbus_fifo =		HPC3_PBUS_FIFO,
338801f5271Srumble 	.pbus_fifo_size =	HPC3_PBUS_FIFO_SIZE,
339801f5271Srumble 	.pbus_bbram =		HPC3_PBUS_BBRAM,
340bc577449Ssekiya 	.scsi_max_xfer =	MAX_SCSI_XFER,
341bc577449Ssekiya 	.scsi_dma_segs =       (MAX_SCSI_XFER / 8192),
342bc577449Ssekiya 	.scsi_dma_segs_size =	8192,
34375aae500Srumble 	.scsi_dma_datain_cmd =	HPC3_SCSI_DMACTL_ACTIVE,
34475aae500Srumble 	.scsi_dma_dataout_cmd =(HPC3_SCSI_DMACTL_ACTIVE | HPC3_SCSI_DMACTL_DIR),
345ee970eecSrumble 	.scsi_dmactl_flush =	HPC3_SCSI_DMACTL_FLUSH,
346ee970eecSrumble 	.scsi_dmactl_active =	HPC3_SCSI_DMACTL_ACTIVE,
347ee970eecSrumble 	.scsi_dmactl_reset =	HPC3_SCSI_DMACTL_RESET
348af4ac18eSsekiya };
349af4ac18eSsekiya 
3508831804fStsutsui static int	hpc_match(device_t, cfdata_t, void *);
3518831804fStsutsui static void	hpc_attach(device_t, device_t, void *);
3525e86516fSrumble static int	hpc_print(void *, const char *);
353c4173c40Sthorpej 
3545e86516fSrumble static int	hpc_revision(struct hpc_softc *, struct gio_attach_args *);
355d15d0532Srumble 
3568831804fStsutsui static int	hpc_submatch(device_t, cfdata_t, const int *, void *);
357be010c72Sthorpej 
358b8aa6159Srumble //static int	hpc_power_intr(void *);
359c4173c40Sthorpej 
360d2895075Ssekiya #if defined(BLINK)
36188ab7da9Sad static callout_t hpc_blink_ch;
362d2895075Ssekiya static void	hpc_blink(void *);
363d2895075Ssekiya #endif
364d2895075Ssekiya 
365121e1e9bSrumble static int	hpc_read_eeprom(int, bus_space_tag_t, bus_space_handle_t,
366121e1e9bSrumble 		    uint8_t *, size_t);
367121e1e9bSrumble 
3688831804fStsutsui CFATTACH_DECL_NEW(hpc, sizeof(struct hpc_softc),
369b96bc0d7Sthorpej     hpc_match, hpc_attach, NULL, NULL);
370c4173c40Sthorpej 
371eb488f67Smacallan static void hpc_bus_mem_init(bus_space_tag_t, void *);
372eb488f67Smacallan 
373eb488f67Smacallan static struct mips_bus_space	hpc_mbst;
374eb488f67Smacallan bus_space_tag_t	hpc_memt = NULL;
375eb488f67Smacallan 
376eb488f67Smacallan 
3775e86516fSrumble static int
hpc_match(device_t parent,cfdata_t cf,void * aux)3788831804fStsutsui hpc_match(device_t parent, cfdata_t cf, void *aux)
379c4173c40Sthorpej {
380c4173c40Sthorpej 	struct gio_attach_args* ga = aux;
381c4173c40Sthorpej 
38285716c44Srumble 	if (mach_type == MACH_SGI_IP12 || mach_type == MACH_SGI_IP20 ||
38385716c44Srumble 	    mach_type == MACH_SGI_IP22) {
384c4173c40Sthorpej 		/* Make sure it's actually there and readable */
38585716c44Srumble 		if (!platform.badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr),
386f016e292Stsutsui 		    sizeof(uint32_t)))
387c4173c40Sthorpej 			return 1;
388c4173c40Sthorpej 	}
389c4173c40Sthorpej 
39085716c44Srumble 	return 0;
39185716c44Srumble }
39285716c44Srumble 
3935e86516fSrumble static void
hpc_attach(device_t parent,device_t self,void * aux)3948831804fStsutsui hpc_attach(device_t parent, device_t self, void *aux)
395c4173c40Sthorpej {
3968831804fStsutsui 	struct hpc_softc *sc = device_private(self);
397c4173c40Sthorpej 	struct gio_attach_args* ga = aux;
398c4173c40Sthorpej 	struct hpc_attach_args ha;
399be010c72Sthorpej 	const struct hpc_device *hd;
40003e520f4Spooka 	uint32_t hpctype;
4015ecb2874Srumble 	int isonboard;
4025ecb2874Srumble 	int isioplus;
40303e520f4Spooka 	int sysmask;
404c4173c40Sthorpej 
4058831804fStsutsui 	sc->sc_dev = self;
4068831804fStsutsui 
40788ab7da9Sad #ifdef BLINK
40888ab7da9Sad 	callout_init(&hpc_blink_ch, 0);
40988ab7da9Sad #endif
41088ab7da9Sad 
411be010c72Sthorpej 	switch (mach_type) {
41203e520f4Spooka 	case MACH_SGI_IP12:
41303e520f4Spooka 		sysmask = HPCDEV_IP12;
41403e520f4Spooka 		break;
41503e520f4Spooka 
416fa349eb1Ssekiya 	case MACH_SGI_IP20:
417fa349eb1Ssekiya 		sysmask = HPCDEV_IP20;
418fa349eb1Ssekiya 		break;
419bc577449Ssekiya 
420be010c72Sthorpej 	case MACH_SGI_IP22:
421be010c72Sthorpej 		if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
422be010c72Sthorpej 			sysmask = HPCDEV_IP22;
423be010c72Sthorpej 		else
424be010c72Sthorpej 			sysmask = HPCDEV_IP24;
425be010c72Sthorpej 		break;
426be010c72Sthorpej 
427be010c72Sthorpej 	default:
428bc577449Ssekiya 		panic("hpc_attach: can't handle HPC on an IP%d", mach_type);
429be010c72Sthorpej 	};
430be010c72Sthorpej 
431d15d0532Srumble 	if ((hpctype = hpc_revision(sc, ga)) == 0)
432d15d0532Srumble 		panic("hpc_attach: could not identify HPC revision\n");
43352063657Ssekiya 
43452063657Ssekiya 	/* force big-endian mode */
435d15d0532Srumble 	if (hpctype == 15)
436d15d0532Srumble 		*(uint32_t *)MIPS_PHYS_TO_KSEG1(ga->ga_addr+HPC1_BIGENDIAN) = 0;
437bc577449Ssekiya 
4385ecb2874Srumble 	/*
4395ecb2874Srumble 	 * All machines have only one HPC on the mainboard itself. ''Extra''
4405ecb2874Srumble 	 * HPCs require bus arbiter and other magic to run happily.
4415ecb2874Srumble 	 */
4425ecb2874Srumble 	isonboard = (ga->ga_addr == HPC_BASE_ADDRESS_0);
4435ecb2874Srumble 	isioplus = (ga->ga_addr == HPC_BASE_ADDRESS_1 && hpctype == 3 &&
4445ecb2874Srumble 	    sysmask == HPCDEV_IP24);
4455ecb2874Srumble 
4465ecb2874Srumble 	printf(": SGI HPC%d%s (%s)\n", (hpctype ==  3) ? 3 : 1,
4475ecb2874Srumble 	    (hpctype == 15) ? ".5" : "", (isonboard) ? "onboard" :
4485ecb2874Srumble 	    (isioplus) ? "IOPLUS mezzanine" : "GIO slot");
4495ecb2874Srumble 
4502c7e4582Srumble 	/*
4512c7e4582Srumble 	 * Configure the bus arbiter appropriately.
4522c7e4582Srumble 	 *
4532c7e4582Srumble 	 * In the case of Challenge S, we must tell the IOPLUS board which
4542c7e4582Srumble 	 * DMA channel to use (we steal it from one of the slots). SGI permits
4552c7e4582Srumble 	 * an HPC1.5 in slot 1, in which case IOPLUS must use EXP0, or any
4562c7e4582Srumble 	 * other DMA-capable board in slot 0, which leaves us to use EXP1. Of
4572c7e4582Srumble 	 * course, this means that only one GIO board may use DMA.
4582c7e4582Srumble 	 *
4592c7e4582Srumble 	 * Note that this never happens on Indigo2.
4602c7e4582Srumble 	 */
4612c7e4582Srumble 	if (isioplus) {
4622c7e4582Srumble 		int arb_slot;
4632c7e4582Srumble 
4642c7e4582Srumble 		if (platform.badaddr(
4652c7e4582Srumble 		    (void *)MIPS_PHYS_TO_KSEG1(HPC_BASE_ADDRESS_2), 4))
4662c7e4582Srumble 			arb_slot = GIO_SLOT_EXP1;
4672c7e4582Srumble 		else
4682c7e4582Srumble 			arb_slot = GIO_SLOT_EXP0;
4692c7e4582Srumble 
4702c7e4582Srumble 		if (gio_arb_config(arb_slot, GIO_ARB_LB | GIO_ARB_MST |
4712c7e4582Srumble 		    GIO_ARB_64BIT | GIO_ARB_HPC2_64BIT)) {
4722c7e4582Srumble 			printf("%s: failed to configure GIO bus arbiter\n",
4738831804fStsutsui 			    device_xname(sc->sc_dev));
4742c7e4582Srumble 			return;
4752c7e4582Srumble 		}
4762c7e4582Srumble 
4778831804fStsutsui 		printf("%s: using EXP%d's DMA channel\n",
4788831804fStsutsui 		    device_xname(sc->sc_dev),
4792c7e4582Srumble 		    (arb_slot == GIO_SLOT_EXP0) ? 0 : 1);
4802c7e4582Srumble 
4812c7e4582Srumble 		bus_space_write_4(ga->ga_iot, ga->ga_ioh,
4822c7e4582Srumble 		    HPC3_PBUS_CFGPIO_REGS, 0x0003ffff);
4832c7e4582Srumble 
4842c7e4582Srumble 		if (arb_slot == GIO_SLOT_EXP0)
4852c7e4582Srumble 			bus_space_write_4(ga->ga_iot, ga->ga_ioh,
4862c7e4582Srumble 			    HPC3_PBUS_CH0_DEVREGS, 0x20202020);
4872c7e4582Srumble 		else
4882c7e4582Srumble 			bus_space_write_4(ga->ga_iot, ga->ga_ioh,
4892c7e4582Srumble 			    HPC3_PBUS_CH0_DEVREGS, 0x30303030);
4902c7e4582Srumble 	} else if (!isonboard) {
4915ecb2874Srumble 		int arb_slot;
4925ecb2874Srumble 
4935ecb2874Srumble 		arb_slot = (ga->ga_addr == HPC_BASE_ADDRESS_1) ?
4945ecb2874Srumble 		    GIO_SLOT_EXP0 : GIO_SLOT_EXP1;
4955ecb2874Srumble 
4965ecb2874Srumble 		if (gio_arb_config(arb_slot, GIO_ARB_RT | GIO_ARB_MST)) {
4975ecb2874Srumble 			printf("%s: failed to configure GIO bus arbiter\n",
4988831804fStsutsui 			    device_xname(sc->sc_dev));
4995ecb2874Srumble 			return;
5005ecb2874Srumble 		}
5015ecb2874Srumble 	}
502c4173c40Sthorpej 
503eb488f67Smacallan 	hpc_bus_mem_init(&hpc_mbst, NULL);
504eb488f67Smacallan 	hpc_memt = &hpc_mbst;
505eb488f67Smacallan 
506eb488f67Smacallan 	sc->sc_ct = normal_memt;
507c4173c40Sthorpej 	sc->sc_ch = ga->ga_ioh;
508c4173c40Sthorpej 
509c4173c40Sthorpej 	sc->sc_base = ga->ga_addr;
510be010c72Sthorpej 
511eb488f67Smacallan 	hpc_read_eeprom(hpctype, normal_memt,
512f17c59deSrumble 	    MIPS_PHYS_TO_KSEG1(sc->sc_base), ha.hpc_eeprom,
513f17c59deSrumble 	    sizeof(ha.hpc_eeprom));
514f17c59deSrumble 
51515065b7eSrumble 	hd = (hpctype == 3) ? hpc3_devices : hpc1_devices;
51615065b7eSrumble 	for (; hd->hd_name != NULL; hd++) {
517d15d0532Srumble 		if (!(hd->hd_sysmask & sysmask) || hd->hd_base != sc->sc_base)
51852f4b049Srafal 			continue;
51952f4b049Srafal 
520be010c72Sthorpej 		ha.ha_name = hd->hd_name;
521be010c72Sthorpej 		ha.ha_devoff = hd->hd_devoff;
522be010c72Sthorpej 		ha.ha_dmaoff = hd->hd_dmaoff;
523be010c72Sthorpej 		ha.ha_irq = hd->hd_irq;
524be010c72Sthorpej 
525be010c72Sthorpej 		/* XXX This is disgusting. */
526eb488f67Smacallan 		ha.ha_st = normal_memt;
527a1a8a2a5Smacallan 		if (bus_space_map(normal_memt, sc->sc_base, 0,
528a1a8a2a5Smacallan 		    BUS_SPACE_MAP_LINEAR, &ha.ha_sh) != 0)
529a1a8a2a5Smacallan 		    	continue;
530be010c72Sthorpej 		ha.ha_dmat = &sgimips_default_bus_dma_tag;
531af4ac18eSsekiya 		if (hpctype == 3)
532af4ac18eSsekiya 			ha.hpc_regs = &hpc3_values;
533af4ac18eSsekiya 		else
534af4ac18eSsekiya 			ha.hpc_regs = &hpc1_values;
535bc577449Ssekiya 		ha.hpc_regs->revision = hpctype;
536be010c72Sthorpej 
5371c8d0954Srumble 		/* XXXgross! avoid complaining in E++ and GIO32 SCSI cases */
5381c8d0954Srumble 		if (hpctype != 3 && sc->sc_base != HPC_BASE_ADDRESS_0) {
5392685996bSthorpej 			config_found(self, &ha, NULL,
540*c7fb772bSthorpej 			    CFARGS(.submatch = hpc_submatch));
5411c8d0954Srumble 		} else {
5422685996bSthorpej 			config_found(self, &ha, hpc_print,
543*c7fb772bSthorpej 			    CFARGS(.submatch = hpc_submatch));
5441c8d0954Srumble 		}
545be010c72Sthorpej 	}
546c4173c40Sthorpej 
547d2895075Ssekiya #if defined(BLINK)
548817b0a57Spooka 	if (mach_type == MACH_SGI_IP12 || mach_type == MACH_SGI_IP20)
549d2895075Ssekiya 		hpc_blink(sc);
550d2895075Ssekiya #endif
551c4173c40Sthorpej }
552c4173c40Sthorpej 
553b8f12e02Srumble /*
554b8f12e02Srumble  * HPC revision detection isn't as simple as it should be. Devices probe
555b8f12e02Srumble  * differently depending on their slots, but luckily there is only one
556b8f12e02Srumble  * instance in which we have to decide the major revision (HPC1 vs HPC3).
557b8f12e02Srumble  *
558b8f12e02Srumble  * The HPC is found in the following configurations:
559b8f12e02Srumble  *	o Personal Iris 4D/3x:
560b8f12e02Srumble  *		One on-board HPC1 or HPC1.5.
561b8f12e02Srumble  *
562b8f12e02Srumble  *	o Indigo R3k/R4k:
563b8f12e02Srumble  * 		One on-board HPC1 or HPC1.5.
564b8f12e02Srumble  * 		Up to two additional HPC1.5's in GIO slots 0 and 1.
565b8f12e02Srumble  *
566b8f12e02Srumble  *	o Indy:
567b8f12e02Srumble  * 		One on-board HPC3.
568b8f12e02Srumble  *		Up to two additional HPC1.5's in GIO slots 0 and 1.
569b8f12e02Srumble  *
570b8f12e02Srumble  *	o Challenge S
571b8f12e02Srumble  * 		One on-board HPC3.
572b8f12e02Srumble  * 		Up to one additional HPC3 on the IOPLUS board (if installed).
573b8f12e02Srumble  *		Up to one additional HPC1.5 in slot 1 of the IOPLUS board.
574b8f12e02Srumble  *
575b8f12e02Srumble  *	o Indigo2, Challenge M
576b8f12e02Srumble  *		One on-board HPC3.
577b8f12e02Srumble  *
578b8f12e02Srumble  * All we really have to worry about is the IP22 case.
579b8f12e02Srumble  */
5805e86516fSrumble static int
hpc_revision(struct hpc_softc * sc,struct gio_attach_args * ga)581d15d0532Srumble hpc_revision(struct hpc_softc *sc, struct gio_attach_args *ga)
582d15d0532Srumble {
583d15d0532Srumble 
584b8f12e02Srumble 	/* No hardware ever supported the last hpc base address. */
585b8f12e02Srumble 	if (ga->ga_addr == HPC_BASE_ADDRESS_3)
586d15d0532Srumble 		return (0);
587d15d0532Srumble 
588b8f12e02Srumble 	if (mach_type == MACH_SGI_IP12 || mach_type == MACH_SGI_IP20) {
589f016e292Stsutsui 		uint32_t reg;
590d15d0532Srumble 
5911426ceedSrumble 		if (!platform.badaddr((void *)MIPS_PHYS_TO_KSEG1(ga->ga_addr +
592d15d0532Srumble 		    HPC1_BIGENDIAN), 4)) {
593d15d0532Srumble 			reg = *(uint32_t *)MIPS_PHYS_TO_KSEG1(ga->ga_addr +
594d15d0532Srumble 			    HPC1_BIGENDIAN);
595d15d0532Srumble 
596d15d0532Srumble 			if (((reg >> HPC1_REVSHIFT) & HPC1_REVMASK) ==
597d15d0532Srumble 			    HPC1_REV15)
598b8f12e02Srumble 				return (15);
599d15d0532Srumble 			else
600b8f12e02Srumble 				return (1);
601d15d0532Srumble 		}
602d15d0532Srumble 
603b8f12e02Srumble 		return (1);
604b8f12e02Srumble 	}
605b8f12e02Srumble 
606b8f12e02Srumble 	/*
607b8f12e02Srumble 	 * If IP22, probe slot 0 to determine if HPC1.5 or HPC3. Slot 1 must
608b8f12e02Srumble 	 * be HPC1.5.
609b8f12e02Srumble 	 */
610b8f12e02Srumble 	if (mach_type == MACH_SGI_IP22) {
611b8f12e02Srumble 		if (ga->ga_addr == HPC_BASE_ADDRESS_0)
612b8f12e02Srumble 			return (3);
613b8f12e02Srumble 
614b8f12e02Srumble 		if (ga->ga_addr == HPC_BASE_ADDRESS_2)
615b8f12e02Srumble 			return (15);
616b8f12e02Srumble 
617b8f12e02Srumble 		/*
618b8f12e02Srumble 		 * Probe for it. We use one of the PBUS registers. Note
619b469bdebSrumble 		 * that this probe succeeds with my E++ adapter in slot 1
620b469bdebSrumble 		 * (bad), but it appears to always do the right thing in
621b469bdebSrumble 		 * slot 0 (good!) and we're only worried about that one
622b469bdebSrumble 		 * anyhow.
623b8f12e02Srumble 		 */
6241426ceedSrumble 		if (platform.badaddr((void *)MIPS_PHYS_TO_KSEG1(ga->ga_addr +
625b8f12e02Srumble 		    HPC3_PBUS_CH7_BP), 4))
626b8f12e02Srumble 			return (15);
627b8f12e02Srumble 		else
628b8f12e02Srumble 			return (3);
629b8f12e02Srumble 	}
630b8f12e02Srumble 
631b8f12e02Srumble 	return (0);
632d15d0532Srumble }
633d15d0532Srumble 
6345e86516fSrumble static int
hpc_submatch(device_t parent,cfdata_t cf,const int * ldesc,void * aux)635cbab9cadSchs hpc_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
636c4173c40Sthorpej {
637c4173c40Sthorpej 	struct hpc_attach_args *ha = aux;
638c4173c40Sthorpej 
639be010c72Sthorpej 	if (cf->cf_loc[HPCCF_OFFSET] != HPCCF_OFFSET_DEFAULT &&
64073f78d5eSthorpej 	    (bus_addr_t) cf->cf_loc[HPCCF_OFFSET] != ha->ha_devoff)
641be010c72Sthorpej 		return (0);
642c4173c40Sthorpej 
6436c88de3bSthorpej 	return (config_match(parent, cf, aux));
644c4173c40Sthorpej }
645c4173c40Sthorpej 
6465e86516fSrumble static int
hpc_print(void * aux,const char * pnp)647be010c72Sthorpej hpc_print(void *aux, const char *pnp)
648c4173c40Sthorpej {
649be010c72Sthorpej 	struct hpc_attach_args *ha = aux;
650c4173c40Sthorpej 
651be010c72Sthorpej 	if (pnp)
652be010c72Sthorpej 		printf("%s at %s", ha->ha_name, pnp);
653c4173c40Sthorpej 
654290a34a0Smatt 	printf(" offset %#" PRIxVADDR, (vaddr_t)ha->ha_devoff);
6550ac0d0d4Swdk 
656be010c72Sthorpej 	return (UNCONF);
657c4173c40Sthorpej }
658c4173c40Sthorpej 
659d2895075Ssekiya #if defined(BLINK)
660d2895075Ssekiya static void
hpc_blink(void * arg)6618831804fStsutsui hpc_blink(void *arg)
662d2895075Ssekiya {
6638831804fStsutsui 	struct hpc_softc *sc = arg;
664d2895075Ssekiya 	register int	s;
665d2895075Ssekiya 	int	value;
666d2895075Ssekiya 
667d2895075Ssekiya 	s = splhigh();
668d2895075Ssekiya 
669e42e4bd9Srumble 	value = *(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(HPC_BASE_ADDRESS_0 +
670e42e4bd9Srumble 	    HPC1_AUX_REGS);
671d2895075Ssekiya 	value ^= HPC1_AUX_CONSLED;
672f016e292Stsutsui 	*(volatile uint8_t *)MIPS_PHYS_TO_KSEG1(HPC_BASE_ADDRESS_0 +
673e42e4bd9Srumble 	    HPC1_AUX_REGS) = value;
674d2895075Ssekiya 	splx(s);
675d2895075Ssekiya 
676d2895075Ssekiya 	/*
677d2895075Ssekiya 	 * Blink rate is:
678d2895075Ssekiya 	 *      full cycle every second if completely idle (loadav = 0)
679d2895075Ssekiya 	 *      full cycle every 2 seconds if loadav = 1
680d2895075Ssekiya 	 *      full cycle every 3 seconds if loadav = 2
681d2895075Ssekiya 	 * etc.
682d2895075Ssekiya 	 */
683d2895075Ssekiya 	s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
684d2895075Ssekiya 	callout_reset(&hpc_blink_ch, s, hpc_blink, sc);
685d2895075Ssekiya }
686d2895075Ssekiya #endif
687d2895075Ssekiya 
688121e1e9bSrumble /*
689121e1e9bSrumble  * Read the eeprom associated with one of the HPC's.
690121e1e9bSrumble  *
691121e1e9bSrumble  * NB: An eeprom is not always present, but the HPC should be able to
692121e1e9bSrumble  *     handle this gracefully. Any consumers should validate the data to
693121e1e9bSrumble  *     ensure it's reasonable.
694121e1e9bSrumble  */
695121e1e9bSrumble static int
hpc_read_eeprom(int hpctype,bus_space_tag_t t,bus_space_handle_t h,uint8_t * buf,size_t len)696121e1e9bSrumble hpc_read_eeprom(int hpctype, bus_space_tag_t t, bus_space_handle_t h,
697121e1e9bSrumble     uint8_t *buf, size_t len)
698121e1e9bSrumble {
699121e1e9bSrumble 	struct seeprom_descriptor sd;
700121e1e9bSrumble 	bus_space_handle_t bsh;
701121e1e9bSrumble 	bus_space_tag_t tag;
702121e1e9bSrumble 	bus_size_t offset;
703121e1e9bSrumble 
704121e1e9bSrumble 	if (!len || len & 0x1)
705121e1e9bSrumble 		return (1);
706121e1e9bSrumble 
707e42e4bd9Srumble 	offset = (hpctype == 3) ? HPC3_EEPROM_DATA : HPC1_AUX_REGS;
708121e1e9bSrumble 
709eb488f67Smacallan 	tag = normal_memt;
710121e1e9bSrumble 	if (bus_space_subregion(t, h, offset, 1, &bsh) != 0)
711121e1e9bSrumble 		return (1);
712121e1e9bSrumble 
713121e1e9bSrumble 	sd.sd_chip = C56_66;
714121e1e9bSrumble 	sd.sd_tag = tag;
715121e1e9bSrumble 	sd.sd_bsh = bsh;
716121e1e9bSrumble 	sd.sd_regsize = 1;
717121e1e9bSrumble 	sd.sd_control_offset = 0;
718121e1e9bSrumble 	sd.sd_status_offset = 0;
719121e1e9bSrumble 	sd.sd_dataout_offset = 0;
720121e1e9bSrumble 	sd.sd_DI = 0x10;	/* EEPROM -> CPU */
721121e1e9bSrumble 	sd.sd_DO = 0x08;	/* CPU -> EEPROM */
722121e1e9bSrumble 	sd.sd_CK = 0x04;
723121e1e9bSrumble 	sd.sd_CS = 0x02;
724121e1e9bSrumble 	sd.sd_MS = 0;
725121e1e9bSrumble 	sd.sd_RDY = 0;
726121e1e9bSrumble 
727121e1e9bSrumble 	if (read_seeprom(&sd, (uint16_t *)buf, 0, len / 2) != 1)
728121e1e9bSrumble 		return (1);
729121e1e9bSrumble 
730121e1e9bSrumble 	bus_space_unmap(t, bsh, 1);
731121e1e9bSrumble 
732121e1e9bSrumble 	return (0);
733121e1e9bSrumble }
734eb488f67Smacallan 
735eb488f67Smacallan #define CHIP	   		hpc
736eb488f67Smacallan #define	CHIP_MEM		/* defined */
737eb488f67Smacallan #define CHIP_ALIGN_STRIDE	2
738eb488f67Smacallan #define CHIP_ACCESS_SIZE	4
739eb488f67Smacallan #define	CHIP_W1_BUS_START(v)	0x00000000UL
740eb488f67Smacallan #define CHIP_W1_BUS_END(v)	0xffffffffUL
741eb488f67Smacallan #define	CHIP_W1_SYS_START(v)	0x00000000UL
742eb488f67Smacallan #define	CHIP_W1_SYS_END(v)	0xffffffffUL
743eb488f67Smacallan 
744eb488f67Smacallan #include <mips/mips/bus_space_alignstride_chipdep.c>
745