1*c7fb772bSthorpej /* $NetBSD: oioc.c,v 1.6 2021/08/07 16:19:04 thorpej Exp $ */
2b610ccb0Srumble
3b610ccb0Srumble /*
4b610ccb0Srumble * Copyright (c) 2009 Stephen M. Rumble
5b610ccb0Srumble * All rights reserved.
6b610ccb0Srumble *
7b610ccb0Srumble * Redistribution and use in source and binary forms, with or without
8b610ccb0Srumble * modification, are permitted provided that the following conditions
9b610ccb0Srumble * are met:
10b610ccb0Srumble * 1. Redistributions of source code must retain the above copyright
11b610ccb0Srumble * notice, this list of conditions and the following disclaimer.
12b610ccb0Srumble * 2. The name of the author may not be used to endorse or promote products
13b610ccb0Srumble * derived from this software without specific prior written permission.
14b610ccb0Srumble *
15b610ccb0Srumble * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16b610ccb0Srumble * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17b610ccb0Srumble * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18b610ccb0Srumble * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19b610ccb0Srumble * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20b610ccb0Srumble * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21b610ccb0Srumble * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22b610ccb0Srumble * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23b610ccb0Srumble * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24b610ccb0Srumble * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25b610ccb0Srumble */
26b610ccb0Srumble
27b610ccb0Srumble /*
28b610ccb0Srumble * IOC1/IOC2 chips on IP4 and IP6/IP10 machines. This interfaces the SCSI
29b610ccb0Srumble * and Ethernet controllers, performs DMA for the former, and does address
30b610ccb0Srumble * space translation for the latter (maps the lance memory space to physical
31b610ccb0Srumble * pages).
32b610ccb0Srumble *
33b610ccb0Srumble * 'I/O Controller' is a sufficiently generic name that SGI created another
34b610ccb0Srumble * one for IP24, which basically stuffed a bunch of miscellany on an ASIC.
35b610ccb0Srumble * So, we'll call ourselves 'Old IOC' and hope that there wasn't an even older
36b610ccb0Srumble * one.
37b610ccb0Srumble */
38b610ccb0Srumble
39b610ccb0Srumble #include <sys/cdefs.h>
40*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: oioc.c,v 1.6 2021/08/07 16:19:04 thorpej Exp $");
41b610ccb0Srumble
42b610ccb0Srumble #include <sys/param.h>
43b610ccb0Srumble #include <sys/device.h>
44b610ccb0Srumble
45b610ccb0Srumble #include <machine/cpu.h>
46b610ccb0Srumble #include <machine/locore.h>
47b610ccb0Srumble #include <machine/autoconf.h>
48cf10107dSdyoung #include <sys/bus.h>
49b610ccb0Srumble #include <machine/machtype.h>
50b610ccb0Srumble #include <machine/sysconf.h>
51b610ccb0Srumble
52b610ccb0Srumble #include <sgimips/ioc/oiocreg.h>
53b610ccb0Srumble #include <sgimips/ioc/oiocvar.h>
54b610ccb0Srumble
55b610ccb0Srumble #include "locators.h"
56b610ccb0Srumble
57b610ccb0Srumble struct oioc_softc {
58b610ccb0Srumble int sc_burst_dma;
59b610ccb0Srumble
60b610ccb0Srumble bus_space_tag_t sc_iot;
61b610ccb0Srumble bus_space_handle_t sc_ioh;
62b610ccb0Srumble };
63b610ccb0Srumble
64cbab9cadSchs static int oioc_match(device_t, cfdata_t, void *);
65cbab9cadSchs static void oioc_attach(device_t, device_t, void *);
66b610ccb0Srumble static int oioc_print(void *, const char *);
67b610ccb0Srumble
68cbab9cadSchs CFATTACH_DECL_NEW(oioc, sizeof(struct oioc_softc),
69b610ccb0Srumble oioc_match, oioc_attach, NULL, NULL);
70b610ccb0Srumble
71b610ccb0Srumble struct oioc_device {
72b610ccb0Srumble const char *od_name;
73b610ccb0Srumble int od_irq;
74b610ccb0Srumble } oioc_devices[] = {
75b610ccb0Srumble { "oiocsc", 4 },
76b610ccb0Srumble { "le", 5 },
77b610ccb0Srumble { NULL, 0 }
78b610ccb0Srumble };
79b610ccb0Srumble
80b610ccb0Srumble static int
oioc_match(device_t parent,cfdata_t match,void * aux)81cbab9cadSchs oioc_match(device_t parent, cfdata_t match, void *aux)
82b610ccb0Srumble {
83b610ccb0Srumble
84b610ccb0Srumble switch(mach_type) {
85b610ccb0Srumble case MACH_SGI_IP4:
86b610ccb0Srumble case MACH_SGI_IP6 | MACH_SGI_IP10:
87b610ccb0Srumble return (1);
88b610ccb0Srumble }
89b610ccb0Srumble
90b610ccb0Srumble return (0);
91b610ccb0Srumble }
92b610ccb0Srumble
93b610ccb0Srumble static void
oioc_attach(device_t parent,device_t self,void * aux)94cbab9cadSchs oioc_attach(device_t parent, device_t self, void *aux)
95b610ccb0Srumble {
96cbab9cadSchs struct oioc_softc *sc = device_private(self);
97b610ccb0Srumble struct mainbus_attach_args *ma = aux;
98b610ccb0Srumble uint32_t reg1, reg2;
99b610ccb0Srumble int oiocrev, i;
100b610ccb0Srumble
101eb488f67Smacallan sc->sc_iot = normal_memt;
102eb488f67Smacallan if (bus_space_map(sc->sc_iot, ma->ma_addr, OIOC_SCSI_REGS_SIZE,
103b610ccb0Srumble BUS_SPACE_MAP_LINEAR, &sc->sc_ioh))
104b610ccb0Srumble panic("oioc_attach: could not allocate memory\n");
105b610ccb0Srumble
106b610ccb0Srumble if (platform.badaddr((void *)MIPS_PHYS_TO_KSEG1(ma->ma_addr +
107b610ccb0Srumble OIOC2_CONFIG), 4))
108b610ccb0Srumble oiocrev = 1;
109b610ccb0Srumble else
110b610ccb0Srumble oiocrev = 2;
111b610ccb0Srumble
112b610ccb0Srumble printf("\noioc0: Old SGI IOC%d\n", oiocrev);
113b610ccb0Srumble
114b610ccb0Srumble if (oiocrev == 2) {
115b610ccb0Srumble char buf[64];
116b610ccb0Srumble
117b610ccb0Srumble /* Try to enable burst mode. If we can't, we can't... */
118b610ccb0Srumble reg1 = 12 << OIOC2_CONFIG_HIWAT_SHFT;
119b610ccb0Srumble reg1 |= OIOC2_CONFIG_BURST_MASK;
120b610ccb0Srumble bus_space_write_4(sc->sc_iot, sc->sc_ioh, OIOC2_CONFIG, reg1);
121b610ccb0Srumble DELAY(1000);
122b610ccb0Srumble reg2 = bus_space_read_4(sc->sc_iot, sc->sc_ioh, OIOC2_CONFIG);
123b610ccb0Srumble if ((reg2 & (reg1 | OIOC2_CONFIG_NOSYNC_MASK)) == reg1)
124b610ccb0Srumble sc->sc_burst_dma = 1;
125b610ccb0Srumble
126b610ccb0Srumble snprintb(buf, sizeof(buf),
127b610ccb0Srumble "\177\020"
128b610ccb0Srumble "f\0\4HIWAT\0"
129b610ccb0Srumble "f\4\2ID\0"
130b610ccb0Srumble "b\6NOSYNC\0"
131b610ccb0Srumble "b\7BURST\0"
132b610ccb0Srumble "f\x8\7COUNT\0"
133b610ccb0Srumble "f\x10\6SCP\0"
134b610ccb0Srumble "f\x1c\4IOP\0\0",
135b610ccb0Srumble (u_quad_t)reg2 & 0xffffffff);
136b610ccb0Srumble printf("oioc0: %s\n", buf);
137b610ccb0Srumble }
138b610ccb0Srumble
139b610ccb0Srumble printf("oioc0: Burst DMA %ssupported\n",
140b610ccb0Srumble (sc->sc_burst_dma) ? "" : "not ");
141b610ccb0Srumble
142b610ccb0Srumble for (i = 0; oioc_devices[i].od_name != NULL; i++) {
143b610ccb0Srumble struct oioc_attach_args oa;
144b610ccb0Srumble
145b610ccb0Srumble oa.oa_name = oioc_devices[i].od_name;
146b610ccb0Srumble oa.oa_irq = oioc_devices[i].od_irq;
147b610ccb0Srumble oa.oa_burst_dma = sc->sc_burst_dma;
148eb488f67Smacallan oa.oa_st = normal_memt;
149b610ccb0Srumble oa.oa_sh = sc->sc_ioh;
150b610ccb0Srumble oa.oa_dmat = &sgimips_default_bus_dma_tag;
151*c7fb772bSthorpej config_found(self, &oa, oioc_print, CFARGS_NONE);
152b610ccb0Srumble }
153b610ccb0Srumble }
154b610ccb0Srumble
155b610ccb0Srumble static int
oioc_print(void * aux,const char * pnp)156b610ccb0Srumble oioc_print(void *aux, const char *pnp)
157b610ccb0Srumble {
158b610ccb0Srumble struct oioc_attach_args *oa = aux;
159b610ccb0Srumble
160b610ccb0Srumble if (pnp)
161b610ccb0Srumble printf("%s at %s", oa->oa_name, pnp);
162b610ccb0Srumble
163b610ccb0Srumble return (UNCONF);
164b610ccb0Srumble }
165