xref: /freebsd/sys/powerpc/powermac/uninorth.c (revision 5b56413d04e608379c9a306373554a8e4d321bc0)
160727d8bSWarner Losh /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
371e3c308SPedro F. Giffuni  *
498f8e6c0SBenno Rice  * Copyright (C) 2002 Benno Rice.
598f8e6c0SBenno Rice  * All rights reserved.
698f8e6c0SBenno Rice  *
798f8e6c0SBenno Rice  * Redistribution and use in source and binary forms, with or without
898f8e6c0SBenno Rice  * modification, are permitted provided that the following conditions
998f8e6c0SBenno Rice  * are met:
1098f8e6c0SBenno Rice  * 1. Redistributions of source code must retain the above copyright
1198f8e6c0SBenno Rice  *    notice, this list of conditions and the following disclaimer.
1298f8e6c0SBenno Rice  * 2. Redistributions in binary form must reproduce the above copyright
1398f8e6c0SBenno Rice  *    notice, this list of conditions and the following disclaimer in the
1498f8e6c0SBenno Rice  *    documentation and/or other materials provided with the distribution.
1598f8e6c0SBenno Rice  *
1698f8e6c0SBenno Rice  * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
1798f8e6c0SBenno Rice  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1898f8e6c0SBenno Rice  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1998f8e6c0SBenno Rice  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2098f8e6c0SBenno Rice  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2198f8e6c0SBenno Rice  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2298f8e6c0SBenno Rice  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2398f8e6c0SBenno Rice  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2498f8e6c0SBenno Rice  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2598f8e6c0SBenno Rice  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2698f8e6c0SBenno Rice  */
2798f8e6c0SBenno Rice 
2898f8e6c0SBenno Rice #include <sys/param.h>
2998f8e6c0SBenno Rice #include <sys/systm.h>
3040cdee9dSPeter Grehan #include <sys/module.h>
3198f8e6c0SBenno Rice #include <sys/bus.h>
3298f8e6c0SBenno Rice #include <sys/conf.h>
3398f8e6c0SBenno Rice #include <sys/kernel.h>
3498f8e6c0SBenno Rice 
3598f8e6c0SBenno Rice #include <dev/ofw/openfirm.h>
3698f8e6c0SBenno Rice #include <dev/ofw/ofw_pci.h>
3751d163d3SNathan Whitehorn #include <dev/ofw/ofw_bus.h>
3894b4a038SNathan Whitehorn #include <dev/ofw/ofw_bus_subr.h>
3998f8e6c0SBenno Rice 
4098f8e6c0SBenno Rice #include <dev/pci/pcivar.h>
4198f8e6c0SBenno Rice #include <dev/pci/pcireg.h>
4298f8e6c0SBenno Rice 
4398f8e6c0SBenno Rice #include <machine/bus.h>
44ca2c1931SNathan Whitehorn #include <machine/intr_machdep.h>
4598f8e6c0SBenno Rice #include <machine/md_var.h>
46de2fa7b8SMarcel Moolenaar #include <machine/pio.h>
4798f8e6c0SBenno Rice #include <machine/resource.h>
4898f8e6c0SBenno Rice 
4998f8e6c0SBenno Rice #include <sys/rman.h>
5098f8e6c0SBenno Rice 
5198f8e6c0SBenno Rice #include <powerpc/powermac/uninorthvar.h>
5298f8e6c0SBenno Rice 
5398f8e6c0SBenno Rice #include <vm/vm.h>
5498f8e6c0SBenno Rice #include <vm/pmap.h>
5598f8e6c0SBenno Rice 
56ca2c1931SNathan Whitehorn /*
57ca2c1931SNathan Whitehorn  * Driver for the Uninorth chip itself.
58ca2c1931SNathan Whitehorn  */
5998f8e6c0SBenno Rice 
60ca2c1931SNathan Whitehorn static MALLOC_DEFINE(M_UNIN, "unin", "unin device information");
6198f8e6c0SBenno Rice 
6298f8e6c0SBenno Rice /*
6398f8e6c0SBenno Rice  * Device interface.
6498f8e6c0SBenno Rice  */
65ca2c1931SNathan Whitehorn 
66ca2c1931SNathan Whitehorn static int  unin_chip_probe(device_t);
67ca2c1931SNathan Whitehorn static int  unin_chip_attach(device_t);
6898f8e6c0SBenno Rice 
6998f8e6c0SBenno Rice /*
7098f8e6c0SBenno Rice  * Bus interface.
7198f8e6c0SBenno Rice  */
72ca2c1931SNathan Whitehorn static int  unin_chip_print_child(device_t dev, device_t child);
73ca2c1931SNathan Whitehorn static void unin_chip_probe_nomatch(device_t, device_t);
74af081ec6SJohn Baldwin static struct rman *unin_chip_get_rman(device_t, int, u_int);
75ca2c1931SNathan Whitehorn static struct resource *unin_chip_alloc_resource(device_t, device_t, int, int *,
762dd1bdf1SJustin Hibbits 						 rman_res_t, rman_res_t,
772dd1bdf1SJustin Hibbits 						 rman_res_t, u_int);
78fef01f04SJohn Baldwin static int  unin_chip_adjust_resource(device_t, device_t,
79af081ec6SJohn Baldwin 				      struct resource *, rman_res_t,
80af081ec6SJohn Baldwin 				      rman_res_t);
812baed46eSJohn Baldwin static int  unin_chip_activate_resource(device_t, device_t,
82ca2c1931SNathan Whitehorn 					struct resource *);
832baed46eSJohn Baldwin static int  unin_chip_deactivate_resource(device_t, device_t,
84ca2c1931SNathan Whitehorn 					  struct resource *);
85d77f2092SJohn Baldwin static int  unin_chip_map_resource(device_t, device_t, struct resource *,
86af081ec6SJohn Baldwin 				   struct resource_map_request *,
87af081ec6SJohn Baldwin 				   struct resource_map *);
88d77f2092SJohn Baldwin static int  unin_chip_unmap_resource(device_t, device_t, struct resource *,
89af081ec6SJohn Baldwin 				     struct resource_map *);
909dbf5b0eSJohn Baldwin static int  unin_chip_release_resource(device_t, device_t, struct resource *);
91ca2c1931SNathan Whitehorn static struct resource_list *unin_chip_get_resource_list (device_t, device_t);
9298f8e6c0SBenno Rice 
9398f8e6c0SBenno Rice /*
9451d163d3SNathan Whitehorn  * OFW Bus interface
9551d163d3SNathan Whitehorn  */
9651d163d3SNathan Whitehorn 
97ca2c1931SNathan Whitehorn static ofw_bus_get_devinfo_t unin_chip_get_devinfo;
9851d163d3SNathan Whitehorn 
9951d163d3SNathan Whitehorn /*
100ca2c1931SNathan Whitehorn  * Local routines
10198f8e6c0SBenno Rice  */
102ca2c1931SNathan Whitehorn 
103ca2c1931SNathan Whitehorn static void		unin_enable_gmac(device_t dev);
104ca2c1931SNathan Whitehorn static void		unin_enable_mpic(device_t dev);
10598f8e6c0SBenno Rice 
10698f8e6c0SBenno Rice /*
10798f8e6c0SBenno Rice  * Driver methods.
10898f8e6c0SBenno Rice  */
109ca2c1931SNathan Whitehorn static device_method_t unin_chip_methods[] = {
11098f8e6c0SBenno Rice 	/* Device interface */
111ca2c1931SNathan Whitehorn 	DEVMETHOD(device_probe,         unin_chip_probe),
112ca2c1931SNathan Whitehorn 	DEVMETHOD(device_attach,        unin_chip_attach),
11398f8e6c0SBenno Rice 
11498f8e6c0SBenno Rice 	/* Bus interface */
115ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_print_child,      unin_chip_print_child),
116ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_probe_nomatch,    unin_chip_probe_nomatch),
11798f8e6c0SBenno Rice 	DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
11898f8e6c0SBenno Rice 	DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
11998f8e6c0SBenno Rice 
120af081ec6SJohn Baldwin 	DEVMETHOD(bus_get_rman,		unin_chip_get_rman),
121ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_alloc_resource,   unin_chip_alloc_resource),
122af081ec6SJohn Baldwin 	DEVMETHOD(bus_adjust_resource,	unin_chip_adjust_resource),
123ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_release_resource, unin_chip_release_resource),
124ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_activate_resource, unin_chip_activate_resource),
125ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_deactivate_resource, unin_chip_deactivate_resource),
126af081ec6SJohn Baldwin 	DEVMETHOD(bus_map_resource,	unin_chip_map_resource),
127af081ec6SJohn Baldwin 	DEVMETHOD(bus_unmap_resource,	unin_chip_unmap_resource),
128ca2c1931SNathan Whitehorn 	DEVMETHOD(bus_get_resource_list, unin_chip_get_resource_list),
12998f8e6c0SBenno Rice 
130ddfc9c4cSWarner Losh 	DEVMETHOD(bus_child_pnpinfo,	ofw_bus_gen_child_pnpinfo),
1314fe8025dSNathan Whitehorn 
13251d163d3SNathan Whitehorn         /* ofw_bus interface */
133ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_devinfo,	unin_chip_get_devinfo),
134ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_compat,	ofw_bus_gen_get_compat),
135ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_model,	ofw_bus_gen_get_model),
136ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_name,	ofw_bus_gen_get_name),
137ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_node,	ofw_bus_gen_get_node),
138ca2c1931SNathan Whitehorn 	DEVMETHOD(ofw_bus_get_type,	ofw_bus_gen_get_type),
13998f8e6c0SBenno Rice 	{ 0, 0 }
14098f8e6c0SBenno Rice };
14198f8e6c0SBenno Rice 
142ca2c1931SNathan Whitehorn static driver_t	unin_chip_driver = {
143ca2c1931SNathan Whitehorn 	"unin",
144ca2c1931SNathan Whitehorn 	unin_chip_methods,
145ca2c1931SNathan Whitehorn 	sizeof(struct unin_chip_softc)
14698f8e6c0SBenno Rice };
14798f8e6c0SBenno Rice 
1484702d987SJustin Hibbits /*
1494702d987SJustin Hibbits  * Assume there is only one unin chip in a PowerMac, so that pmu.c functions can
1504702d987SJustin Hibbits  * suspend the chip after the whole rest of the device tree is suspended, not
1514702d987SJustin Hibbits  * earlier.
1524702d987SJustin Hibbits  */
1534702d987SJustin Hibbits static device_t		unin_chip;
1544702d987SJustin Hibbits 
155992ae60bSJohn Baldwin EARLY_DRIVER_MODULE(unin, ofwbus, unin_chip_driver, 0, 0, BUS_PASS_BUS);
15698f8e6c0SBenno Rice 
15751d163d3SNathan Whitehorn /*
158ca2c1931SNathan Whitehorn  * Add an interrupt to the dev's resource list if present
15951d163d3SNathan Whitehorn  */
160ca2c1931SNathan Whitehorn static void
161ca2c1931SNathan Whitehorn unin_chip_add_intr(phandle_t devnode, struct unin_chip_devinfo *dinfo)
162ca2c1931SNathan Whitehorn {
163eaef5f0aSNathan Whitehorn 	phandle_t iparent;
164ca2c1931SNathan Whitehorn 	int	*intr;
165ca2c1931SNathan Whitehorn 	int	i, nintr;
166ca2c1931SNathan Whitehorn 	int 	icells;
16751d163d3SNathan Whitehorn 
168ca2c1931SNathan Whitehorn 	if (dinfo->udi_ninterrupts >= 6) {
169ca2c1931SNathan Whitehorn 		printf("unin: device has more than 6 interrupts\n");
170ca2c1931SNathan Whitehorn 		return;
17151d163d3SNathan Whitehorn 	}
17298f8e6c0SBenno Rice 
173217d17bcSOleksandr Tymoshenko 	nintr = OF_getprop_alloc_multi(devnode, "interrupts", sizeof(*intr),
174ca2c1931SNathan Whitehorn 		(void **)&intr);
175ca2c1931SNathan Whitehorn 	if (nintr == -1) {
176217d17bcSOleksandr Tymoshenko 		nintr = OF_getprop_alloc_multi(devnode, "AAPL,interrupts",
177ca2c1931SNathan Whitehorn 			sizeof(*intr), (void **)&intr);
178ca2c1931SNathan Whitehorn 		if (nintr == -1)
179ca2c1931SNathan Whitehorn 			return;
180ca2c1931SNathan Whitehorn 	}
181ca2c1931SNathan Whitehorn 
182ca2c1931SNathan Whitehorn 	if (intr[0] == -1)
183ca2c1931SNathan Whitehorn 		return;
184ca2c1931SNathan Whitehorn 
185ca2c1931SNathan Whitehorn 	if (OF_getprop(devnode, "interrupt-parent", &iparent, sizeof(iparent))
186ca2c1931SNathan Whitehorn 	    <= 0)
187ca2c1931SNathan Whitehorn 		panic("Interrupt but no interrupt parent!\n");
188ca2c1931SNathan Whitehorn 
189ca2c1931SNathan Whitehorn 	if (OF_searchprop(iparent, "#interrupt-cells", &icells, sizeof(icells))
190ca2c1931SNathan Whitehorn 	    <= 0)
191ca2c1931SNathan Whitehorn 		icells = 1;
192ca2c1931SNathan Whitehorn 
193ca2c1931SNathan Whitehorn 	for (i = 0; i < nintr; i+=icells) {
194607ebaafSMarcel Moolenaar 		u_int irq = MAP_IRQ(iparent, intr[i]);
195607ebaafSMarcel Moolenaar 
196ca2c1931SNathan Whitehorn 		resource_list_add(&dinfo->udi_resources, SYS_RES_IRQ,
197607ebaafSMarcel Moolenaar 		    dinfo->udi_ninterrupts, irq, irq, 1);
198ca2c1931SNathan Whitehorn 
199eaef5f0aSNathan Whitehorn 		if (icells > 1) {
200607ebaafSMarcel Moolenaar 			powerpc_config_intr(irq,
201eaef5f0aSNathan Whitehorn 			    (intr[i+1] & 1) ? INTR_TRIGGER_LEVEL :
202a7a32004SNathan Whitehorn 			    INTR_TRIGGER_EDGE, INTR_POLARITY_LOW);
203eaef5f0aSNathan Whitehorn 		}
204eaef5f0aSNathan Whitehorn 
205607ebaafSMarcel Moolenaar 		dinfo->udi_interrupts[dinfo->udi_ninterrupts] = irq;
206ca2c1931SNathan Whitehorn 		dinfo->udi_ninterrupts++;
207ca2c1931SNathan Whitehorn 	}
208ca2c1931SNathan Whitehorn }
209ca2c1931SNathan Whitehorn 
210ca2c1931SNathan Whitehorn static void
211ca2c1931SNathan Whitehorn unin_chip_add_reg(phandle_t devnode, struct unin_chip_devinfo *dinfo)
212ca2c1931SNathan Whitehorn {
213ca2c1931SNathan Whitehorn 	struct	unin_chip_reg *reg;
214ca2c1931SNathan Whitehorn 	int	i, nreg;
215ca2c1931SNathan Whitehorn 
216217d17bcSOleksandr Tymoshenko 	nreg = OF_getprop_alloc_multi(devnode, "reg", sizeof(*reg), (void **)&reg);
217ca2c1931SNathan Whitehorn 	if (nreg == -1)
218ca2c1931SNathan Whitehorn 		return;
219ca2c1931SNathan Whitehorn 
220ca2c1931SNathan Whitehorn 	for (i = 0; i < nreg; i++) {
221ca2c1931SNathan Whitehorn 		resource_list_add(&dinfo->udi_resources, SYS_RES_MEMORY, i,
222ca2c1931SNathan Whitehorn 				  reg[i].mr_base,
223ca2c1931SNathan Whitehorn 				  reg[i].mr_base + reg[i].mr_size,
224ca2c1931SNathan Whitehorn 				  reg[i].mr_size);
225ca2c1931SNathan Whitehorn 	}
226ca2c1931SNathan Whitehorn }
227ca2c1931SNathan Whitehorn 
228ca2c1931SNathan Whitehorn static void
2294702d987SJustin Hibbits unin_update_reg(device_t dev, uint32_t regoff, uint32_t set, uint32_t clr)
230ca2c1931SNathan Whitehorn {
2314702d987SJustin Hibbits 	volatile u_int *reg;
232ca2c1931SNathan Whitehorn 	struct unin_chip_softc *sc;
233ca2c1931SNathan Whitehorn 	u_int32_t tmpl;
234ca2c1931SNathan Whitehorn 
235ca2c1931SNathan Whitehorn 	sc = device_get_softc(dev);
2364702d987SJustin Hibbits 	reg = (void *)(sc->sc_addr + regoff);
2374702d987SJustin Hibbits 	tmpl = inl(reg);
2384702d987SJustin Hibbits 	tmpl &= ~clr;
2394702d987SJustin Hibbits 	tmpl |= set;
2404702d987SJustin Hibbits 	outl(reg, tmpl);
2414702d987SJustin Hibbits }
2424702d987SJustin Hibbits 
2434702d987SJustin Hibbits static void
2444702d987SJustin Hibbits unin_enable_gmac(device_t dev)
2454702d987SJustin Hibbits {
2464702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_CLOCKCNTL, UNIN_CLOCKCNTL_GMAC, 0);
247ca2c1931SNathan Whitehorn }
248ca2c1931SNathan Whitehorn 
249ca2c1931SNathan Whitehorn static void
250ca2c1931SNathan Whitehorn unin_enable_mpic(device_t dev)
251ca2c1931SNathan Whitehorn {
2524702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_TOGGLE_REG, UNIN_MPIC_RESET | UNIN_MPIC_OUTPUT_ENABLE, 0);
253ca2c1931SNathan Whitehorn }
254ca2c1931SNathan Whitehorn 
255ca2c1931SNathan Whitehorn static int
256ca2c1931SNathan Whitehorn unin_chip_probe(device_t dev)
257ca2c1931SNathan Whitehorn {
258ca2c1931SNathan Whitehorn 	const char	*name;
259ca2c1931SNathan Whitehorn 
260ca2c1931SNathan Whitehorn 	name = ofw_bus_get_name(dev);
261ca2c1931SNathan Whitehorn 
262ca2c1931SNathan Whitehorn 	if (name == NULL)
26398f8e6c0SBenno Rice 		return (ENXIO);
26498f8e6c0SBenno Rice 
265ca2c1931SNathan Whitehorn 	if (strcmp(name, "uni-n") != 0 && strcmp(name, "u3") != 0
266ca2c1931SNathan Whitehorn 	    && strcmp(name, "u4") != 0)
26798f8e6c0SBenno Rice 		return (ENXIO);
268ca2c1931SNathan Whitehorn 
269ca2c1931SNathan Whitehorn 	device_set_desc(dev, "Apple UniNorth System Controller");
270ca2c1931SNathan Whitehorn 	return (0);
27198f8e6c0SBenno Rice }
27298f8e6c0SBenno Rice 
273ca2c1931SNathan Whitehorn static int
274ca2c1931SNathan Whitehorn unin_chip_attach(device_t dev)
275ca2c1931SNathan Whitehorn {
276ca2c1931SNathan Whitehorn 	struct unin_chip_softc *sc;
277ca2c1931SNathan Whitehorn 	struct unin_chip_devinfo *dinfo;
278ca2c1931SNathan Whitehorn 	phandle_t  root;
279ca2c1931SNathan Whitehorn 	phandle_t  child;
28043cbf1a6SAndreas Tobler 	phandle_t  iparent;
281ca2c1931SNathan Whitehorn 	device_t   cdev;
2824ee63553SNathan Whitehorn 	cell_t     acells, scells;
283ca2c1931SNathan Whitehorn 	char compat[32];
28443cbf1a6SAndreas Tobler 	char name[32];
28543cbf1a6SAndreas Tobler 	u_int irq, reg[3];
286ca2c1931SNathan Whitehorn 	int error, i = 0;
287ca2c1931SNathan Whitehorn 
288ca2c1931SNathan Whitehorn 	sc = device_get_softc(dev);
289ca2c1931SNathan Whitehorn 	root = ofw_bus_get_node(dev);
290ca2c1931SNathan Whitehorn 
291ca2c1931SNathan Whitehorn 	if (OF_getprop(root, "reg", reg, sizeof(reg)) < 8)
29298f8e6c0SBenno Rice 		return (ENXIO);
293ca2c1931SNathan Whitehorn 
2944ee63553SNathan Whitehorn 	acells = scells = 1;
2954ee63553SNathan Whitehorn 	OF_getprop(OF_parent(root), "#address-cells", &acells, sizeof(acells));
2964ee63553SNathan Whitehorn 	OF_getprop(OF_parent(root), "#size-cells", &scells, sizeof(scells));
297ca2c1931SNathan Whitehorn 
2984ee63553SNathan Whitehorn 	i = 0;
2994ee63553SNathan Whitehorn 	sc->sc_physaddr = reg[i++];
3004ee63553SNathan Whitehorn 	if (acells == 2) {
3014ee63553SNathan Whitehorn 		sc->sc_physaddr <<= 32;
3024ee63553SNathan Whitehorn 		sc->sc_physaddr |= reg[i++];
3034ee63553SNathan Whitehorn 	}
3044ee63553SNathan Whitehorn 	sc->sc_size = reg[i++];
3054ee63553SNathan Whitehorn 	if (scells == 2) {
3064ee63553SNathan Whitehorn 		sc->sc_size <<= 32;
3074ee63553SNathan Whitehorn 		sc->sc_size |= reg[i++];
3084ee63553SNathan Whitehorn 	}
309ca2c1931SNathan Whitehorn 
31098f8e6c0SBenno Rice 	sc->sc_mem_rman.rm_type = RMAN_ARRAY;
311ca2c1931SNathan Whitehorn 	sc->sc_mem_rman.rm_descr = "UniNorth Device Memory";
312ca2c1931SNathan Whitehorn 
313bda386dbSKevin Lo 	error = rman_init(&sc->sc_mem_rman);
314ca2c1931SNathan Whitehorn 
315bda386dbSKevin Lo 	if (error) {
316bda386dbSKevin Lo 		device_printf(dev, "rman_init() failed. error = %d\n", error);
317bda386dbSKevin Lo 		return (error);
31898f8e6c0SBenno Rice 	}
319ca2c1931SNathan Whitehorn 
320ca2c1931SNathan Whitehorn 	error = rman_manage_region(&sc->sc_mem_rman, sc->sc_physaddr,
321ca2c1931SNathan Whitehorn 				   sc->sc_physaddr + sc->sc_size - 1);
322bda386dbSKevin Lo 	if (error) {
32398f8e6c0SBenno Rice 		device_printf(dev,
324ca2c1931SNathan Whitehorn 			      "rman_manage_region() failed. error = %d\n",
325ca2c1931SNathan Whitehorn 			      error);
326bda386dbSKevin Lo 		return (error);
32798f8e6c0SBenno Rice 	}
32898f8e6c0SBenno Rice 
3294702d987SJustin Hibbits 	if (unin_chip == NULL)
3304702d987SJustin Hibbits 		unin_chip = dev;
3314702d987SJustin Hibbits 
332d48bbef3SPeter Grehan         /*
333ca2c1931SNathan Whitehorn 	 * Iterate through the sub-devices
334d48bbef3SPeter Grehan 	 */
335ca2c1931SNathan Whitehorn 	for (child = OF_child(root); child != 0; child = OF_peer(child)) {
336ca2c1931SNathan Whitehorn 		dinfo = malloc(sizeof(*dinfo), M_UNIN, M_WAITOK | M_ZERO);
337ca2c1931SNathan Whitehorn 		if (ofw_bus_gen_setup_devinfo(&dinfo->udi_obdinfo, child)
338ca2c1931SNathan Whitehorn 		    != 0)
339ca2c1931SNathan Whitehorn 		{
340ca2c1931SNathan Whitehorn 			free(dinfo, M_UNIN);
341ca2c1931SNathan Whitehorn 			continue;
342ca2c1931SNathan Whitehorn 		}
343d48bbef3SPeter Grehan 
344ca2c1931SNathan Whitehorn 		resource_list_init(&dinfo->udi_resources);
345ca2c1931SNathan Whitehorn 		dinfo->udi_ninterrupts = 0;
346ca2c1931SNathan Whitehorn 		unin_chip_add_intr(child, dinfo);
347ca2c1931SNathan Whitehorn 
34843cbf1a6SAndreas Tobler 		/*
34943cbf1a6SAndreas Tobler 		 * Some Apple machines do have a bug in OF, they miss
35043cbf1a6SAndreas Tobler 		 * the interrupt entries on the U3 I2C node. That means they
35143cbf1a6SAndreas Tobler 		 * do not have an entry with number of interrupts nor the
35243cbf1a6SAndreas Tobler 		 * entry of the interrupt parent handle.
35343cbf1a6SAndreas Tobler 		 * We define an interrupt and hardwire it to the /u3/mpic
35443cbf1a6SAndreas Tobler 		 * handle.
35543cbf1a6SAndreas Tobler 		 */
35643cbf1a6SAndreas Tobler 
35743cbf1a6SAndreas Tobler 		if (OF_getprop(child, "name", name, sizeof(name)) <= 0)
35843cbf1a6SAndreas Tobler 			device_printf(dev, "device has no name!\n");
35943cbf1a6SAndreas Tobler 		if (dinfo->udi_ninterrupts == 0 &&
36043cbf1a6SAndreas Tobler 		    (strcmp(name, "i2c-bus") == 0 ||
36143cbf1a6SAndreas Tobler 		     strcmp(name, "i2c")  == 0)) {
36243cbf1a6SAndreas Tobler 			if (OF_getprop(child, "interrupt-parent", &iparent,
36343cbf1a6SAndreas Tobler 				       sizeof(iparent)) <= 0) {
36443cbf1a6SAndreas Tobler 				iparent = OF_finddevice("/u3/mpic");
36543cbf1a6SAndreas Tobler 				device_printf(dev, "Set /u3/mpic as iparent!\n");
36643cbf1a6SAndreas Tobler 			}
36743cbf1a6SAndreas Tobler 			/* Add an interrupt number 0 to the parent. */
36843cbf1a6SAndreas Tobler 			irq = MAP_IRQ(iparent, 0);
36943cbf1a6SAndreas Tobler 			resource_list_add(&dinfo->udi_resources, SYS_RES_IRQ,
37043cbf1a6SAndreas Tobler 					  dinfo->udi_ninterrupts, irq, irq, 1);
37143cbf1a6SAndreas Tobler 			dinfo->udi_interrupts[dinfo->udi_ninterrupts] = irq;
37243cbf1a6SAndreas Tobler 			dinfo->udi_ninterrupts++;
37343cbf1a6SAndreas Tobler 		}
37443cbf1a6SAndreas Tobler 
375ca2c1931SNathan Whitehorn 		unin_chip_add_reg(child, dinfo);
376ca2c1931SNathan Whitehorn 
377*5b56413dSWarner Losh 		cdev = device_add_child(dev, NULL, DEVICE_UNIT_ANY);
378ca2c1931SNathan Whitehorn 		if (cdev == NULL) {
379ca2c1931SNathan Whitehorn 			device_printf(dev, "<%s>: device_add_child failed\n",
380ca2c1931SNathan Whitehorn 				      dinfo->udi_obdinfo.obd_name);
381ca2c1931SNathan Whitehorn 			resource_list_free(&dinfo->udi_resources);
382ca2c1931SNathan Whitehorn 			ofw_bus_gen_destroy_devinfo(&dinfo->udi_obdinfo);
383ca2c1931SNathan Whitehorn 			free(dinfo, M_UNIN);
384ca2c1931SNathan Whitehorn 			continue;
385ca2c1931SNathan Whitehorn 		}
386ca2c1931SNathan Whitehorn 
387ca2c1931SNathan Whitehorn 		device_set_ivars(cdev, dinfo);
388ca2c1931SNathan Whitehorn 	}
389ca2c1931SNathan Whitehorn 
390ca2c1931SNathan Whitehorn 	/*
391ca2c1931SNathan Whitehorn 	 * Only map the first page, since that is where the registers
392ca2c1931SNathan Whitehorn 	 * of interest lie.
393ca2c1931SNathan Whitehorn 	 */
394ca2c1931SNathan Whitehorn 	sc->sc_addr = (vm_offset_t)pmap_mapdev(sc->sc_physaddr, PAGE_SIZE);
395ca2c1931SNathan Whitehorn 
396ca2c1931SNathan Whitehorn 	sc->sc_version = *(u_int *)sc->sc_addr;
397ca2c1931SNathan Whitehorn 	device_printf(dev, "Version %d\n", sc->sc_version);
398ca2c1931SNathan Whitehorn 
399ca2c1931SNathan Whitehorn 	/*
400ca2c1931SNathan Whitehorn 	 * Enable the GMAC Ethernet cell and the integrated OpenPIC
401ca2c1931SNathan Whitehorn 	 * if Open Firmware says they are used.
402ca2c1931SNathan Whitehorn 	 */
403ca2c1931SNathan Whitehorn 	for (child = OF_child(root); child; child = OF_peer(child)) {
404d48bbef3SPeter Grehan 		memset(compat, 0, sizeof(compat));
405d48bbef3SPeter Grehan 		OF_getprop(child, "compatible", compat, sizeof(compat));
406ca2c1931SNathan Whitehorn 		if (strcmp(compat, "gmac") == 0)
407ca2c1931SNathan Whitehorn 			unin_enable_gmac(dev);
408ca2c1931SNathan Whitehorn 		if (strcmp(compat, "chrp,open-pic") == 0)
409ca2c1931SNathan Whitehorn 			unin_enable_mpic(dev);
410d48bbef3SPeter Grehan 	}
411d48bbef3SPeter Grehan 
412ca2c1931SNathan Whitehorn 	/*
413ca2c1931SNathan Whitehorn 	 * GMAC lives under the PCI bus, so just check if enet is gmac.
414ca2c1931SNathan Whitehorn 	 */
415ca2c1931SNathan Whitehorn 	child = OF_finddevice("enet");
416ca2c1931SNathan Whitehorn 	memset(compat, 0, sizeof(compat));
417ca2c1931SNathan Whitehorn 	OF_getprop(child, "compatible", compat, sizeof(compat));
418ca2c1931SNathan Whitehorn 	if (strcmp(compat, "gmac") == 0)
419ca2c1931SNathan Whitehorn 		unin_enable_gmac(dev);
42094b4a038SNathan Whitehorn 
42198f8e6c0SBenno Rice 	return (bus_generic_attach(dev));
42298f8e6c0SBenno Rice }
42398f8e6c0SBenno Rice 
42498f8e6c0SBenno Rice static int
425ca2c1931SNathan Whitehorn unin_chip_print_child(device_t dev, device_t child)
42698f8e6c0SBenno Rice {
427ca2c1931SNathan Whitehorn         struct unin_chip_devinfo *dinfo;
428ca2c1931SNathan Whitehorn         struct resource_list *rl;
429ca2c1931SNathan Whitehorn         int retval = 0;
43098f8e6c0SBenno Rice 
431ca2c1931SNathan Whitehorn         dinfo = device_get_ivars(child);
432ca2c1931SNathan Whitehorn         rl = &dinfo->udi_resources;
43398f8e6c0SBenno Rice 
434ca2c1931SNathan Whitehorn         retval += bus_print_child_header(dev, child);
43598f8e6c0SBenno Rice 
436f8fd3fb5SJustin Hibbits         retval += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#jx");
437f8fd3fb5SJustin Hibbits         retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%jd");
43898f8e6c0SBenno Rice 
439ca2c1931SNathan Whitehorn         retval += bus_print_child_footer(dev, child);
44098f8e6c0SBenno Rice 
441ca2c1931SNathan Whitehorn         return (retval);
44298f8e6c0SBenno Rice }
44398f8e6c0SBenno Rice 
44498f8e6c0SBenno Rice static void
445ca2c1931SNathan Whitehorn unin_chip_probe_nomatch(device_t dev, device_t child)
44698f8e6c0SBenno Rice {
447ca2c1931SNathan Whitehorn         struct unin_chip_devinfo *dinfo;
448ca2c1931SNathan Whitehorn         struct resource_list *rl;
449ca2c1931SNathan Whitehorn 	const char *type;
45098f8e6c0SBenno Rice 
451ca2c1931SNathan Whitehorn 	if (bootverbose) {
452ca2c1931SNathan Whitehorn 		dinfo = device_get_ivars(child);
453ca2c1931SNathan Whitehorn 		rl = &dinfo->udi_resources;
45498f8e6c0SBenno Rice 
455ca2c1931SNathan Whitehorn 		if ((type = ofw_bus_get_type(child)) == NULL)
456ca2c1931SNathan Whitehorn 			type = "(unknown)";
457ca2c1931SNathan Whitehorn 		device_printf(dev, "<%s, %s>", type, ofw_bus_get_name(child));
458f8fd3fb5SJustin Hibbits 		resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#jx");
459f8fd3fb5SJustin Hibbits 		resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%jd");
460ca2c1931SNathan Whitehorn 		printf(" (no driver attached)\n");
46198f8e6c0SBenno Rice 	}
46298f8e6c0SBenno Rice }
46398f8e6c0SBenno Rice 
464af081ec6SJohn Baldwin static struct rman *
465af081ec6SJohn Baldwin unin_chip_get_rman(device_t bus, int type, u_int flags)
466af081ec6SJohn Baldwin {
467af081ec6SJohn Baldwin 	struct		unin_chip_softc *sc;
468af081ec6SJohn Baldwin 
469af081ec6SJohn Baldwin 	sc = device_get_softc(bus);
470af081ec6SJohn Baldwin 	switch (type) {
471af081ec6SJohn Baldwin 	case SYS_RES_MEMORY:
472af081ec6SJohn Baldwin 	case SYS_RES_IOPORT:
473af081ec6SJohn Baldwin 		return (&sc->sc_mem_rman);
474af081ec6SJohn Baldwin 	default:
475af081ec6SJohn Baldwin 		return (NULL);
476af081ec6SJohn Baldwin 	}
477af081ec6SJohn Baldwin }
478af081ec6SJohn Baldwin 
47998f8e6c0SBenno Rice static struct resource *
480ca2c1931SNathan Whitehorn unin_chip_alloc_resource(device_t bus, device_t child, int type, int *rid,
4812dd1bdf1SJustin Hibbits 			 rman_res_t start, rman_res_t end, rman_res_t count,
4822dd1bdf1SJustin Hibbits 			 u_int flags)
48398f8e6c0SBenno Rice {
484af081ec6SJohn Baldwin 	rman_res_t	adjstart, adjend, adjcount;
485ca2c1931SNathan Whitehorn 	struct		unin_chip_devinfo *dinfo;
486ca2c1931SNathan Whitehorn 	struct		resource_list_entry *rle;
487ca2c1931SNathan Whitehorn 
488ca2c1931SNathan Whitehorn 	dinfo = device_get_ivars(child);
48998f8e6c0SBenno Rice 
49098f8e6c0SBenno Rice 	switch (type) {
49198f8e6c0SBenno Rice 	case SYS_RES_MEMORY:
492ca2c1931SNathan Whitehorn 	case SYS_RES_IOPORT:
493ca2c1931SNathan Whitehorn 		rle = resource_list_find(&dinfo->udi_resources, SYS_RES_MEMORY,
494ca2c1931SNathan Whitehorn 					 *rid);
495ca2c1931SNathan Whitehorn 		if (rle == NULL) {
496ca2c1931SNathan Whitehorn 			device_printf(bus, "no rle for %s memory %d\n",
497ca2c1931SNathan Whitehorn 				      device_get_nameunit(child), *rid);
498ca2c1931SNathan Whitehorn 			return (NULL);
499ca2c1931SNathan Whitehorn 		}
500ca2c1931SNathan Whitehorn 
501ca2c1931SNathan Whitehorn 		rle->end = rle->end - 1; /* Hack? */
502ca2c1931SNathan Whitehorn 
503ca2c1931SNathan Whitehorn 		if (start < rle->start)
504ca2c1931SNathan Whitehorn 			adjstart = rle->start;
505ca2c1931SNathan Whitehorn 		else if (start > rle->end)
506ca2c1931SNathan Whitehorn 			adjstart = rle->end;
507ca2c1931SNathan Whitehorn 		else
508ca2c1931SNathan Whitehorn 			adjstart = start;
509ca2c1931SNathan Whitehorn 
510ca2c1931SNathan Whitehorn 		if (end < rle->start)
511ca2c1931SNathan Whitehorn 			adjend = rle->start;
512ca2c1931SNathan Whitehorn 		else if (end > rle->end)
513ca2c1931SNathan Whitehorn 			adjend = rle->end;
514ca2c1931SNathan Whitehorn 		else
515ca2c1931SNathan Whitehorn 			adjend = end;
516ca2c1931SNathan Whitehorn 
517ca2c1931SNathan Whitehorn 		adjcount = adjend - adjstart;
518ca2c1931SNathan Whitehorn 
519af081ec6SJohn Baldwin 		return (bus_generic_rman_alloc_resource(bus, child,
520af081ec6SJohn Baldwin 		    SYS_RES_MEMORY, rid, adjstart, adjend, adjcount, flags));
52198f8e6c0SBenno Rice 	case SYS_RES_IRQ:
522ca2c1931SNathan Whitehorn 		/* Check for passthrough from subattachments. */
523ca2c1931SNathan Whitehorn 		if (device_get_parent(child) != bus)
524ca2c1931SNathan Whitehorn 			return BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
525ca2c1931SNathan Whitehorn 						  type, rid, start, end, count,
526ca2c1931SNathan Whitehorn 						  flags);
527de2fa7b8SMarcel Moolenaar 
528ca2c1931SNathan Whitehorn 		rle = resource_list_find(&dinfo->udi_resources, SYS_RES_IRQ,
529ca2c1931SNathan Whitehorn 		    *rid);
530ca2c1931SNathan Whitehorn 		if (rle == NULL) {
531ca2c1931SNathan Whitehorn 			if (dinfo->udi_ninterrupts >= 6) {
532ca2c1931SNathan Whitehorn 				device_printf(bus,
533ca2c1931SNathan Whitehorn 					      "%s has more than 6 interrupts\n",
534ca2c1931SNathan Whitehorn 					      device_get_nameunit(child));
535ca2c1931SNathan Whitehorn 				return (NULL);
536ca2c1931SNathan Whitehorn 			}
537ca2c1931SNathan Whitehorn 			resource_list_add(&dinfo->udi_resources, SYS_RES_IRQ,
538ca2c1931SNathan Whitehorn 					  dinfo->udi_ninterrupts, start, start,
539ca2c1931SNathan Whitehorn 					  1);
540ca2c1931SNathan Whitehorn 
541ca2c1931SNathan Whitehorn 			dinfo->udi_interrupts[dinfo->udi_ninterrupts] = start;
542ca2c1931SNathan Whitehorn 			dinfo->udi_ninterrupts++;
543ca2c1931SNathan Whitehorn 		}
544ca2c1931SNathan Whitehorn 
545ca2c1931SNathan Whitehorn 		return (resource_list_alloc(&dinfo->udi_resources, bus, child,
546ca2c1931SNathan Whitehorn 					    type, rid, start, end, count,
547ca2c1931SNathan Whitehorn 					    flags));
54898f8e6c0SBenno Rice 	default:
54998f8e6c0SBenno Rice 		device_printf(bus, "unknown resource request from %s\n",
55098f8e6c0SBenno Rice 			      device_get_nameunit(child));
55198f8e6c0SBenno Rice 		return (NULL);
55298f8e6c0SBenno Rice 	}
55398f8e6c0SBenno Rice }
55498f8e6c0SBenno Rice 
555af081ec6SJohn Baldwin static int
556fef01f04SJohn Baldwin unin_chip_adjust_resource(device_t bus, device_t child, struct resource *r,
557fef01f04SJohn Baldwin     rman_res_t start, rman_res_t end)
558af081ec6SJohn Baldwin {
559fef01f04SJohn Baldwin 	switch (rman_get_type(r)) {
560af081ec6SJohn Baldwin 	case SYS_RES_IOPORT:
561af081ec6SJohn Baldwin 	case SYS_RES_MEMORY:
562fef01f04SJohn Baldwin 		return (bus_generic_rman_adjust_resource(bus, child, r, start,
563af081ec6SJohn Baldwin 		    end));
564fef01f04SJohn Baldwin 	case SYS_RES_IRQ:
565fef01f04SJohn Baldwin 		return (bus_generic_adjust_resource(bus, child, r, start, end));
566af081ec6SJohn Baldwin 	default:
567af081ec6SJohn Baldwin 		return (EINVAL);
56898f8e6c0SBenno Rice 	}
56998f8e6c0SBenno Rice }
57098f8e6c0SBenno Rice 
57198f8e6c0SBenno Rice static int
5729dbf5b0eSJohn Baldwin unin_chip_release_resource(device_t bus, device_t child, struct resource *res)
57398f8e6c0SBenno Rice {
5749dbf5b0eSJohn Baldwin 	switch (rman_get_type(res)) {
575af081ec6SJohn Baldwin 	case SYS_RES_IOPORT:
576af081ec6SJohn Baldwin 	case SYS_RES_MEMORY:
5779dbf5b0eSJohn Baldwin 		return (bus_generic_rman_release_resource(bus, child, res));
578af081ec6SJohn Baldwin 	case SYS_RES_IRQ:
5799dbf5b0eSJohn Baldwin 		return (bus_generic_rl_release_resource(bus, child, res));
580af081ec6SJohn Baldwin 	default:
581af081ec6SJohn Baldwin 		return (EINVAL);
582ca2c1931SNathan Whitehorn 	}
583ca2c1931SNathan Whitehorn }
584ca2c1931SNathan Whitehorn 
585ca2c1931SNathan Whitehorn static int
5862baed46eSJohn Baldwin unin_chip_activate_resource(device_t bus, device_t child, struct resource *res)
587ca2c1931SNathan Whitehorn {
5882baed46eSJohn Baldwin 	switch (rman_get_type(res)) {
589af081ec6SJohn Baldwin 	case SYS_RES_IOPORT:
590af081ec6SJohn Baldwin 	case SYS_RES_MEMORY:
5912baed46eSJohn Baldwin 		return (bus_generic_rman_activate_resource(bus, child, res));
592af081ec6SJohn Baldwin 	case SYS_RES_IRQ:
5932baed46eSJohn Baldwin 		return (bus_generic_activate_resource(bus, child, res));
594af081ec6SJohn Baldwin 	default:
595af081ec6SJohn Baldwin 		return (EINVAL);
59698f8e6c0SBenno Rice 	}
59798f8e6c0SBenno Rice }
59898f8e6c0SBenno Rice 
59998f8e6c0SBenno Rice static int
6002baed46eSJohn Baldwin unin_chip_deactivate_resource(device_t bus, device_t child,
601ca2c1931SNathan Whitehorn 			      struct resource *res)
60298f8e6c0SBenno Rice {
6032baed46eSJohn Baldwin 	switch (rman_get_type(res)) {
604af081ec6SJohn Baldwin 	case SYS_RES_IOPORT:
605af081ec6SJohn Baldwin 	case SYS_RES_MEMORY:
6062baed46eSJohn Baldwin 		return (bus_generic_rman_deactivate_resource(bus, child, res));
607af081ec6SJohn Baldwin 	case SYS_RES_IRQ:
6082baed46eSJohn Baldwin 		return (bus_generic_deactivate_resource(bus, child, res));
609af081ec6SJohn Baldwin 	default:
610af081ec6SJohn Baldwin 		return (EINVAL);
611af081ec6SJohn Baldwin 	}
612af081ec6SJohn Baldwin }
613af081ec6SJohn Baldwin 
614af081ec6SJohn Baldwin static int
615d77f2092SJohn Baldwin unin_chip_map_resource(device_t bus, device_t child, struct resource *r,
616d77f2092SJohn Baldwin     struct resource_map_request *argsp, struct resource_map *map)
617af081ec6SJohn Baldwin {
618af081ec6SJohn Baldwin 	struct resource_map_request args;
619af081ec6SJohn Baldwin 	rman_res_t length, start;
620af081ec6SJohn Baldwin 	int error;
621af081ec6SJohn Baldwin 
622af081ec6SJohn Baldwin 	/* Resources must be active to be mapped. */
623af081ec6SJohn Baldwin 	if (!(rman_get_flags(r) & RF_ACTIVE))
624af081ec6SJohn Baldwin 		return (ENXIO);
625af081ec6SJohn Baldwin 
626af081ec6SJohn Baldwin 	/* Mappings are only supported on I/O and memory resources. */
627d77f2092SJohn Baldwin 	switch (rman_get_type(r)) {
628af081ec6SJohn Baldwin 	case SYS_RES_IOPORT:
629af081ec6SJohn Baldwin 	case SYS_RES_MEMORY:
630af081ec6SJohn Baldwin 		break;
631af081ec6SJohn Baldwin 	default:
632af081ec6SJohn Baldwin 		return (EINVAL);
633af081ec6SJohn Baldwin 	}
634af081ec6SJohn Baldwin 
635af081ec6SJohn Baldwin 	resource_init_map_request(&args);
636af081ec6SJohn Baldwin 	error = resource_validate_map_request(r, argsp, &args, &start, &length);
637af081ec6SJohn Baldwin 	if (error)
638af081ec6SJohn Baldwin 		return (error);
639af081ec6SJohn Baldwin 
640af081ec6SJohn Baldwin 	if (bootverbose)
641af081ec6SJohn Baldwin 		printf("nexus mapdev: start %jx, len %jd\n",
642af081ec6SJohn Baldwin 		    (uintmax_t)start, (uintmax_t)length);
643af081ec6SJohn Baldwin 
644af081ec6SJohn Baldwin 	map->r_vaddr = pmap_mapdev_attr(start, length, args.memattr);
645af081ec6SJohn Baldwin 	if (map->r_vaddr == NULL)
646af081ec6SJohn Baldwin 		return (ENOMEM);
647af081ec6SJohn Baldwin 	map->r_bustag = &bs_be_tag;
648af081ec6SJohn Baldwin 	map->r_size = length;
649af081ec6SJohn Baldwin 	map->r_bushandle = (bus_space_handle_t)map->r_vaddr;
650af081ec6SJohn Baldwin 	return (0);
651af081ec6SJohn Baldwin }
652af081ec6SJohn Baldwin 
653af081ec6SJohn Baldwin static int
654d77f2092SJohn Baldwin unin_chip_unmap_resource(device_t bus, device_t child, struct resource *r,
655d77f2092SJohn Baldwin     struct resource_map *map)
656af081ec6SJohn Baldwin {
65798f8e6c0SBenno Rice 	/*
658ca2c1931SNathan Whitehorn 	 * If this is a memory resource, unmap it.
65998f8e6c0SBenno Rice 	 */
660d77f2092SJohn Baldwin 	switch (rman_get_type(r)) {
661af081ec6SJohn Baldwin 	case SYS_RES_IOPORT:
662af081ec6SJohn Baldwin 	case SYS_RES_MEMORY:
663af081ec6SJohn Baldwin 		pmap_unmapdev(map->r_vaddr, map->r_size);
664af081ec6SJohn Baldwin 		break;
665af081ec6SJohn Baldwin 	default:
666af081ec6SJohn Baldwin 		return (EINVAL);
66798f8e6c0SBenno Rice 	}
668af081ec6SJohn Baldwin 	return (0);
66998f8e6c0SBenno Rice }
67098f8e6c0SBenno Rice 
671ca2c1931SNathan Whitehorn static struct resource_list *
672ca2c1931SNathan Whitehorn unin_chip_get_resource_list (device_t dev, device_t child)
67351d163d3SNathan Whitehorn {
674ca2c1931SNathan Whitehorn 	struct unin_chip_devinfo *dinfo;
67551d163d3SNathan Whitehorn 
676ca2c1931SNathan Whitehorn 	dinfo = device_get_ivars(child);
677ca2c1931SNathan Whitehorn 	return (&dinfo->udi_resources);
67851d163d3SNathan Whitehorn }
67951d163d3SNathan Whitehorn 
680ca2c1931SNathan Whitehorn static const struct ofw_bus_devinfo *
681ca2c1931SNathan Whitehorn unin_chip_get_devinfo(device_t dev, device_t child)
68298f8e6c0SBenno Rice {
683ca2c1931SNathan Whitehorn 	struct unin_chip_devinfo *dinfo;
68498f8e6c0SBenno Rice 
685ca2c1931SNathan Whitehorn 	dinfo = device_get_ivars(child);
686ca2c1931SNathan Whitehorn 	return (&dinfo->udi_obdinfo);
68798f8e6c0SBenno Rice }
68898f8e6c0SBenno Rice 
6894702d987SJustin Hibbits int
6904702d987SJustin Hibbits unin_chip_wake(device_t dev)
6914702d987SJustin Hibbits {
6924702d987SJustin Hibbits 
6934702d987SJustin Hibbits 	if (dev == NULL)
6944702d987SJustin Hibbits 		dev = unin_chip;
6954702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_PWR_MGMT, UNIN_PWR_NORMAL, UNIN_PWR_MASK);
6964702d987SJustin Hibbits 	DELAY(10);
6974702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_HWINIT_STATE, UNIN_RUNNING, 0);
6984702d987SJustin Hibbits 	DELAY(100);
6994702d987SJustin Hibbits 
7004702d987SJustin Hibbits 	return (0);
7014702d987SJustin Hibbits }
7024702d987SJustin Hibbits 
7034702d987SJustin Hibbits int
7044702d987SJustin Hibbits unin_chip_sleep(device_t dev, int idle)
7054702d987SJustin Hibbits {
7064702d987SJustin Hibbits 	if (dev == NULL)
7074702d987SJustin Hibbits 		dev = unin_chip;
7084702d987SJustin Hibbits 
7094702d987SJustin Hibbits 	unin_update_reg(dev, UNIN_HWINIT_STATE, UNIN_SLEEPING, 0);
7104702d987SJustin Hibbits 	DELAY(10);
7114702d987SJustin Hibbits 	if (idle)
7124702d987SJustin Hibbits 		unin_update_reg(dev, UNIN_PWR_MGMT, UNIN_PWR_IDLE2, UNIN_PWR_MASK);
7134702d987SJustin Hibbits 	else
7144702d987SJustin Hibbits 		unin_update_reg(dev, UNIN_PWR_MGMT, UNIN_PWR_SLEEP, UNIN_PWR_MASK);
7154702d987SJustin Hibbits 	DELAY(10);
7164702d987SJustin Hibbits 
7174702d987SJustin Hibbits 	return (0);
7184702d987SJustin Hibbits }
719