fhc.c revision 190114
1111072Sjake/*- 2111072Sjake * Copyright (c) 2003 Jake Burkholder. 3167308Smarius * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org> 4111072Sjake * All rights reserved. 5111072Sjake * 6111072Sjake * Redistribution and use in source and binary forms, with or without 7111072Sjake * modification, are permitted provided that the following conditions 8111072Sjake * are met: 9111072Sjake * 1. Redistributions of source code must retain the above copyright 10111072Sjake * notice, this list of conditions and the following disclaimer. 11111072Sjake * 2. Redistributions in binary form must reproduce the above copyright 12111072Sjake * notice, this list of conditions and the following disclaimer in the 13111072Sjake * documentation and/or other materials provided with the distribution. 14111072Sjake * 15111072Sjake * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16111072Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17111072Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18111072Sjake * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19111072Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20111072Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21111072Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22111072Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23111072Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24111072Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25111072Sjake * SUCH DAMAGE. 26111072Sjake */ 27111072Sjake 28143129Smarius#include <sys/cdefs.h> 29143129Smarius__FBSDID("$FreeBSD: head/sys/sparc64/fhc/fhc.c 190114 2009-03-19 21:14:45Z marius $"); 30143129Smarius 31111072Sjake#include <sys/param.h> 32111072Sjake#include <sys/systm.h> 33111072Sjake#include <sys/bus.h> 34111072Sjake#include <sys/kernel.h> 35111072Sjake#include <sys/malloc.h> 36167308Smarius#include <sys/module.h> 37111123Sjake#include <sys/pcpu.h> 38111072Sjake 39143826Smarius#include <dev/led/led.h> 40133589Smarius#include <dev/ofw/ofw_bus.h> 41152684Smarius#include <dev/ofw/ofw_bus_subr.h> 42111072Sjake#include <dev/ofw/openfirm.h> 43111072Sjake 44111072Sjake#include <machine/bus.h> 45111072Sjake#include <machine/bus_common.h> 46111072Sjake#include <machine/resource.h> 47111072Sjake 48111072Sjake#include <sys/rman.h> 49111072Sjake 50111072Sjake#include <sparc64/fhc/fhcreg.h> 51111072Sjake#include <sparc64/sbus/ofw_sbus.h> 52111072Sjake 53111072Sjakestruct fhc_devinfo { 54152684Smarius struct ofw_bus_devinfo fdi_obdinfo; 55111072Sjake struct resource_list fdi_rl; 56111072Sjake}; 57111072Sjake 58167308Smariusstruct fhc_softc { 59172066Smarius struct resource *sc_memres[FHC_NREG]; 60167308Smarius int sc_nrange; 61167308Smarius struct sbus_ranges *sc_ranges; 62167308Smarius int sc_ign; 63167308Smarius struct cdev *sc_led_dev; 64167308Smarius}; 65167308Smarius 66167308Smariusstatic device_probe_t fhc_probe; 67167308Smariusstatic device_attach_t fhc_attach; 68167308Smariusstatic bus_print_child_t fhc_print_child; 69167308Smariusstatic bus_probe_nomatch_t fhc_probe_nomatch; 70167308Smariusstatic bus_setup_intr_t fhc_setup_intr; 71167308Smariusstatic bus_alloc_resource_t fhc_alloc_resource; 72167308Smariusstatic bus_get_resource_list_t fhc_get_resource_list; 73167308Smariusstatic ofw_bus_get_devinfo_t fhc_get_devinfo; 74167308Smarius 75172066Smariusstatic void fhc_intr_enable(void *); 76172066Smariusstatic void fhc_intr_disable(void *); 77178443Smariusstatic void fhc_intr_assign(void *); 78178443Smariusstatic void fhc_intr_clear(void *); 79143826Smariusstatic void fhc_led_func(void *, int); 80152684Smariusstatic int fhc_print_res(struct fhc_devinfo *); 81111123Sjake 82167308Smariusstatic device_method_t fhc_methods[] = { 83167308Smarius /* Device interface */ 84167308Smarius DEVMETHOD(device_probe, fhc_probe), 85167308Smarius DEVMETHOD(device_attach, fhc_attach), 86167308Smarius DEVMETHOD(device_shutdown, bus_generic_shutdown), 87167308Smarius DEVMETHOD(device_suspend, bus_generic_suspend), 88167308Smarius DEVMETHOD(device_resume, bus_generic_resume), 89167308Smarius 90167308Smarius /* Bus interface */ 91167308Smarius DEVMETHOD(bus_print_child, fhc_print_child), 92167308Smarius DEVMETHOD(bus_probe_nomatch, fhc_probe_nomatch), 93167308Smarius DEVMETHOD(bus_alloc_resource, fhc_alloc_resource), 94167308Smarius DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 95167308Smarius DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 96190098Smarius DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource), 97190098Smarius DEVMETHOD(bus_setup_intr, fhc_setup_intr), 98190098Smarius DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 99190098Smarius DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 100167308Smarius DEVMETHOD(bus_get_resource_list, fhc_get_resource_list), 101190114Smarius DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str), 102167308Smarius 103167308Smarius /* ofw_bus interface */ 104167308Smarius DEVMETHOD(ofw_bus_get_devinfo, fhc_get_devinfo), 105167308Smarius DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), 106167308Smarius DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), 107167308Smarius DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name), 108167308Smarius DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), 109167308Smarius DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), 110167308Smarius 111190098Smarius KOBJMETHOD_END 112167308Smarius}; 113167308Smarius 114167308Smariusstatic driver_t fhc_driver = { 115167308Smarius "fhc", 116167308Smarius fhc_methods, 117167308Smarius sizeof(struct fhc_softc), 118167308Smarius}; 119167308Smarius 120167308Smariusstatic devclass_t fhc_devclass; 121167308Smarius 122167308SmariusDRIVER_MODULE(fhc, central, fhc_driver, fhc_devclass, 0, 0); 123167308SmariusDRIVER_MODULE(fhc, nexus, fhc_driver, fhc_devclass, 0, 0); 124182070SmariusMODULE_DEPEND(fhc, central, 1, 1, 1); 125182070SmariusMODULE_VERSION(fhc, 1); 126167308Smarius 127172066Smariusstatic const struct intr_controller fhc_ic = { 128172066Smarius fhc_intr_enable, 129172066Smarius fhc_intr_disable, 130178443Smarius fhc_intr_assign, 131178443Smarius fhc_intr_clear 132172066Smarius}; 133172066Smarius 134172066Smariusstruct fhc_icarg { 135172066Smarius struct fhc_softc *fica_sc; 136172066Smarius struct resource *fica_memres; 137172066Smarius}; 138172066Smarius 139167308Smariusstatic int 140111072Sjakefhc_probe(device_t dev) 141111072Sjake{ 142111072Sjake 143167308Smarius if (strcmp(ofw_bus_get_name(dev), "fhc") == 0) { 144167308Smarius device_set_desc(dev, "fhc"); 145167308Smarius return (0); 146167308Smarius } 147167308Smarius return (ENXIO); 148111072Sjake} 149111072Sjake 150167308Smariusstatic int 151111072Sjakefhc_attach(device_t dev) 152111072Sjake{ 153143826Smarius char ledname[sizeof("boardXX")]; 154111072Sjake struct fhc_devinfo *fdi; 155172066Smarius struct fhc_icarg *fica; 156172066Smarius struct fhc_softc *sc; 157111072Sjake struct sbus_regs *reg; 158111072Sjake phandle_t child; 159111072Sjake phandle_t node; 160111072Sjake device_t cdev; 161167308Smarius uint32_t board; 162111123Sjake uint32_t ctrl; 163143142Smarius uint32_t *intr; 164143142Smarius uint32_t iv; 165111072Sjake char *name; 166172066Smarius int central; 167167308Smarius int error; 168167308Smarius int i; 169190098Smarius int j; 170111072Sjake 171111072Sjake sc = device_get_softc(dev); 172167308Smarius node = ofw_bus_get_node(dev); 173111072Sjake 174172066Smarius central = 0; 175167308Smarius if (strcmp(device_get_name(device_get_parent(dev)), "central") == 0) 176172066Smarius central = 1; 177167308Smarius 178167308Smarius for (i = 0; i < FHC_NREG; i++) { 179190098Smarius j = i; 180167308Smarius sc->sc_memres[i] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 181190098Smarius &j, RF_ACTIVE); 182167308Smarius if (sc->sc_memres[i] == NULL) { 183167308Smarius device_printf(dev, "cannot allocate resource %d\n", i); 184167308Smarius error = ENXIO; 185167308Smarius goto fail_memres; 186167308Smarius } 187167308Smarius } 188167308Smarius 189172066Smarius if (central != 0) { 190172066Smarius board = bus_read_4(sc->sc_memres[FHC_INTERNAL], FHC_BSR); 191172066Smarius board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe); 192167308Smarius } else { 193172066Smarius if (OF_getprop(node, "board#", &board, sizeof(board)) == -1) { 194167308Smarius device_printf(dev, "cannot get board number\n"); 195167308Smarius error = ENXIO; 196167308Smarius goto fail_memres; 197167308Smarius } 198167308Smarius } 199167308Smarius 200172066Smarius device_printf(dev, "board %d, ", board); 201143129Smarius if (OF_getprop_alloc(node, "board-model", 1, (void **)&name) != -1) { 202143826Smarius printf("model %s\n", name); 203143129Smarius free(name, M_OFWPROP); 204143826Smarius } else 205143826Smarius printf("model unknown\n"); 206143129Smarius 207111072Sjake for (i = FHC_FANFAIL; i <= FHC_TOD; i++) { 208172066Smarius bus_write_4(sc->sc_memres[i], FHC_ICLR, 0x0); 209172066Smarius (void)bus_read_4(sc->sc_memres[i], FHC_ICLR); 210111072Sjake } 211111072Sjake 212172066Smarius sc->sc_ign = board << 1; 213172066Smarius bus_write_4(sc->sc_memres[FHC_IGN], 0x0, sc->sc_ign); 214172066Smarius sc->sc_ign = bus_read_4(sc->sc_memres[FHC_IGN], 0x0); 215111123Sjake 216172066Smarius ctrl = bus_read_4(sc->sc_memres[FHC_INTERNAL], FHC_CTRL); 217172066Smarius if (central == 0) 218111123Sjake ctrl |= FHC_CTRL_IXIST; 219111123Sjake ctrl &= ~(FHC_CTRL_AOFF | FHC_CTRL_BOFF | FHC_CTRL_SLINE); 220172066Smarius bus_write_4(sc->sc_memres[FHC_INTERNAL], FHC_CTRL, ctrl); 221172066Smarius (void)bus_read_4(sc->sc_memres[FHC_INTERNAL], FHC_CTRL); 222111123Sjake 223111072Sjake sc->sc_nrange = OF_getprop_alloc(node, "ranges", 224111072Sjake sizeof(*sc->sc_ranges), (void **)&sc->sc_ranges); 225111072Sjake if (sc->sc_nrange == -1) { 226167308Smarius device_printf(dev, "cannot get ranges\n"); 227167308Smarius error = ENXIO; 228167308Smarius goto fail_memres; 229111072Sjake } 230111072Sjake 231172066Smarius /* 232172066Smarius * Apparently only the interrupt controller of boards hanging off 233172066Smarius * of central(4) is indented to be used, otherwise we would have 234172066Smarius * conflicts registering the interrupt controllers for all FHC 235172066Smarius * boards as the board number and thus the IGN isn't unique. 236172066Smarius */ 237172066Smarius if (central == 1) { 238172066Smarius /* 239172066Smarius * Hunt through all the interrupt mapping regs and register 240172066Smarius * our interrupt controller for the corresponding interrupt 241190098Smarius * vectors. We do this early in order to be able to catch 242190098Smarius * stray interrupts. 243172066Smarius */ 244172066Smarius for (i = FHC_FANFAIL; i <= FHC_TOD; i++) { 245172066Smarius fica = malloc(sizeof(*fica), M_DEVBUF, M_NOWAIT); 246172066Smarius if (fica == NULL) 247172066Smarius panic("%s: could not allocate interrupt " 248172066Smarius "controller argument", __func__); 249172066Smarius fica->fica_sc = sc; 250172066Smarius fica->fica_memres = sc->sc_memres[i]; 251172066Smarius#ifdef FHC_DEBUG 252172066Smarius device_printf(dev, "intr map %d: %#lx, clr: %#lx\n", i, 253172066Smarius (u_long)bus_read_4(fica->fica_memres, FHC_IMAP), 254172066Smarius (u_long)bus_read_4(fica->fica_memres, FHC_ICLR)); 255172066Smarius#endif 256172066Smarius /* 257172066Smarius * XXX we only pick the INO rather than the INR 258172066Smarius * from the IMR since the firmware may not provide 259172066Smarius * the IGN and the IGN is constant for all devices 260172066Smarius * on that FireHose controller. 261172066Smarius */ 262190098Smarius j = intr_controller_register(INTMAP_VEC(sc->sc_ign, 263172066Smarius INTINO(bus_read_4(fica->fica_memres, FHC_IMAP))), 264190098Smarius &fhc_ic, fica); 265190098Smarius if (j != 0) 266190098Smarius device_printf(dev, "could not register " 267190098Smarius "interrupt controller for map %d (%d)\n", 268190098Smarius i, j); 269172066Smarius } 270172066Smarius } else { 271172066Smarius snprintf(ledname, sizeof(ledname), "board%d", board); 272143826Smarius sc->sc_led_dev = led_create(fhc_led_func, sc, ledname); 273143826Smarius } 274143826Smarius 275111072Sjake for (child = OF_child(node); child != 0; child = OF_peer(child)) { 276152684Smarius fdi = malloc(sizeof(*fdi), M_DEVBUF, M_WAITOK | M_ZERO); 277152684Smarius if (ofw_bus_gen_setup_devinfo(&fdi->fdi_obdinfo, child) != 0) { 278152684Smarius free(fdi, M_DEVBUF); 279111072Sjake continue; 280152684Smarius } 281190098Smarius i = OF_getprop_alloc(child, "reg", sizeof(*reg), 282152684Smarius (void **)®); 283190098Smarius if (i == -1) { 284152684Smarius device_printf(dev, "<%s>: incomplete\n", 285152684Smarius fdi->fdi_obdinfo.obd_name); 286152684Smarius ofw_bus_gen_destroy_devinfo(&fdi->fdi_obdinfo); 287152684Smarius free(fdi, M_DEVBUF); 288152684Smarius continue; 289152684Smarius } 290152684Smarius resource_list_init(&fdi->fdi_rl); 291190098Smarius for (j = 0; j < i; j++) 292190098Smarius resource_list_add(&fdi->fdi_rl, SYS_RES_MEMORY, j, 293190098Smarius reg[j].sbr_offset, reg[j].sbr_offset + 294190098Smarius reg[j].sbr_size, reg[j].sbr_size); 295152684Smarius free(reg, M_OFWPROP); 296172066Smarius if (central == 1) { 297190098Smarius i = OF_getprop_alloc(child, "interrupts", 298172066Smarius sizeof(*intr), (void **)&intr); 299190098Smarius if (i != -1) { 300190098Smarius for (j = 0; j < i; j++) { 301190098Smarius iv = INTMAP_VEC(sc->sc_ign, intr[j]); 302172066Smarius resource_list_add(&fdi->fdi_rl, 303190098Smarius SYS_RES_IRQ, j, iv, iv, 1); 304172066Smarius } 305172066Smarius free(intr, M_OFWPROP); 306152684Smarius } 307152684Smarius } 308111072Sjake cdev = device_add_child(dev, NULL, -1); 309152684Smarius if (cdev == NULL) { 310152684Smarius device_printf(dev, "<%s>: device_add_child failed\n", 311152684Smarius fdi->fdi_obdinfo.obd_name); 312152684Smarius resource_list_free(&fdi->fdi_rl); 313152684Smarius ofw_bus_gen_destroy_devinfo(&fdi->fdi_obdinfo); 314152684Smarius free(fdi, M_DEVBUF); 315152684Smarius continue; 316152684Smarius } 317152684Smarius device_set_ivars(cdev, fdi); 318111072Sjake } 319111072Sjake 320111072Sjake return (bus_generic_attach(dev)); 321167308Smarius 322167308Smarius fail_memres: 323167308Smarius for (i = 0; i < FHC_NREG; i++) 324167308Smarius if (sc->sc_memres[i] != NULL) 325167308Smarius bus_release_resource(dev, SYS_RES_MEMORY, 326167308Smarius rman_get_rid(sc->sc_memres[i]), sc->sc_memres[i]); 327182070Smarius return (error); 328111072Sjake} 329111072Sjake 330167308Smariusstatic int 331111072Sjakefhc_print_child(device_t dev, device_t child) 332111072Sjake{ 333111072Sjake int rv; 334111072Sjake 335111072Sjake rv = bus_print_child_header(dev, child); 336152684Smarius rv += fhc_print_res(device_get_ivars(child)); 337111072Sjake rv += bus_print_child_footer(dev, child); 338111072Sjake return (rv); 339111072Sjake} 340111072Sjake 341167308Smariusstatic void 342111072Sjakefhc_probe_nomatch(device_t dev, device_t child) 343111072Sjake{ 344152684Smarius const char *type; 345111072Sjake 346152684Smarius device_printf(dev, "<%s>", ofw_bus_get_name(child)); 347152684Smarius fhc_print_res(device_get_ivars(child)); 348152684Smarius type = ofw_bus_get_type(child); 349111072Sjake printf(" type %s (no driver attached)\n", 350152684Smarius type != NULL ? type : "unknown"); 351111072Sjake} 352111072Sjake 353172066Smariusstatic void 354172066Smariusfhc_intr_enable(void *arg) 355111072Sjake{ 356172066Smarius struct intr_vector *iv = arg; 357172066Smarius struct fhc_icarg *fica = iv->iv_icarg; 358111072Sjake 359172066Smarius bus_write_4(fica->fica_memres, FHC_IMAP, 360172066Smarius INTMAP_ENABLE(iv->iv_vec, iv->iv_mid)); 361172066Smarius (void)bus_read_4(fica->fica_memres, FHC_IMAP); 362111072Sjake} 363111072Sjake 364172066Smariusstatic void 365172066Smariusfhc_intr_disable(void *arg) 366111072Sjake{ 367172066Smarius struct intr_vector *iv = arg; 368172066Smarius struct fhc_icarg *fica = iv->iv_icarg; 369111072Sjake 370172066Smarius bus_write_4(fica->fica_memres, FHC_IMAP, iv->iv_vec); 371172066Smarius (void)bus_read_4(fica->fica_memres, FHC_IMAP); 372111072Sjake} 373111072Sjake 374172066Smariusstatic void 375178443Smariusfhc_intr_assign(void *arg) 376170387Spiso{ 377172066Smarius struct intr_vector *iv = arg; 378172066Smarius struct fhc_icarg *fica = iv->iv_icarg; 379170387Spiso 380178443Smarius bus_write_4(fica->fica_memres, FHC_IMAP, INTMAP_TID( 381178443Smarius bus_read_4(fica->fica_memres, FHC_IMAP), iv->iv_mid)); 382178443Smarius (void)bus_read_4(fica->fica_memres, FHC_IMAP); 383178443Smarius} 384178443Smarius 385178443Smariusstatic void 386178443Smariusfhc_intr_clear(void *arg) 387178443Smarius{ 388178443Smarius struct intr_vector *iv = arg; 389178443Smarius struct fhc_icarg *fica = iv->iv_icarg; 390178443Smarius 391172066Smarius bus_write_4(fica->fica_memres, FHC_ICLR, 0x0); 392172066Smarius (void)bus_read_4(fica->fica_memres, FHC_ICLR); 393170387Spiso} 394170387Spiso 395172066Smariusstatic int 396172066Smariusfhc_setup_intr(device_t bus, device_t child, struct resource *r, int flags, 397172066Smarius driver_filter_t *filt, driver_intr_t *func, void *arg, void **cookiep) 398111123Sjake{ 399172066Smarius struct fhc_softc *sc; 400172066Smarius u_long vec; 401111123Sjake 402172066Smarius sc = device_get_softc(bus); 403172066Smarius /* 404172066Smarius * Make sure the vector is fully specified and we registered 405172066Smarius * our interrupt controller for it. 406182070Smarius */ 407172066Smarius vec = rman_get_start(r); 408172066Smarius if (INTIGN(vec) != sc->sc_ign || intr_vectors[vec].iv_ic != &fhc_ic) { 409172066Smarius device_printf(bus, "invalid interrupt vector 0x%lx\n", vec); 410182070Smarius return (EINVAL); 411182070Smarius } 412172066Smarius return (bus_generic_setup_intr(bus, child, r, flags, filt, func, 413172066Smarius arg, cookiep)); 414111123Sjake} 415111123Sjake 416167308Smariusstatic struct resource * 417111072Sjakefhc_alloc_resource(device_t bus, device_t child, int type, int *rid, 418111072Sjake u_long start, u_long end, u_long count, u_int flags) 419111072Sjake{ 420143826Smarius struct resource_list *rl; 421111072Sjake struct resource_list_entry *rle; 422111072Sjake struct fhc_softc *sc; 423111072Sjake struct resource *res; 424111072Sjake bus_addr_t coffset; 425111072Sjake bus_addr_t cend; 426111072Sjake bus_addr_t phys; 427111072Sjake int isdefault; 428143826Smarius int passthrough; 429111072Sjake int i; 430111072Sjake 431111072Sjake isdefault = (start == 0UL && end == ~0UL); 432143826Smarius passthrough = (device_get_parent(child) != bus); 433111072Sjake res = NULL; 434143826Smarius rle = NULL; 435143826Smarius rl = BUS_GET_RESOURCE_LIST(bus, child); 436111072Sjake sc = device_get_softc(bus); 437111072Sjake switch (type) { 438111072Sjake case SYS_RES_IRQ: 439143826Smarius return (resource_list_alloc(rl, bus, child, type, rid, start, 440143826Smarius end, count, flags)); 441111072Sjake case SYS_RES_MEMORY: 442143826Smarius if (!passthrough) { 443172066Smarius rle = resource_list_find(rl, type, *rid); 444143826Smarius if (rle == NULL) 445143826Smarius return (NULL); 446143826Smarius if (rle->res != NULL) 447143826Smarius panic("%s: resource entry is busy", __func__); 448143826Smarius if (isdefault) { 449143826Smarius start = rle->start; 450143826Smarius count = ulmax(count, rle->count); 451143826Smarius end = ulmax(rle->end, start + count - 1); 452143826Smarius } 453143826Smarius } 454111072Sjake for (i = 0; i < sc->sc_nrange; i++) { 455111072Sjake coffset = sc->sc_ranges[i].coffset; 456111072Sjake cend = coffset + sc->sc_ranges[i].size - 1; 457111072Sjake if (start >= coffset && end <= cend) { 458111072Sjake start -= coffset; 459111072Sjake end -= coffset; 460111072Sjake phys = sc->sc_ranges[i].poffset | 461111072Sjake ((bus_addr_t)sc->sc_ranges[i].pspace << 32); 462111072Sjake res = bus_generic_alloc_resource(bus, child, 463111072Sjake type, rid, phys + start, phys + end, 464111072Sjake count, flags); 465143826Smarius if (!passthrough) 466143826Smarius rle->res = res; 467111072Sjake break; 468111072Sjake } 469111072Sjake } 470111072Sjake break; 471111072Sjake } 472111072Sjake return (res); 473111072Sjake} 474111072Sjake 475167308Smariusstatic struct resource_list * 476143826Smariusfhc_get_resource_list(device_t bus, device_t child) 477111072Sjake{ 478111072Sjake struct fhc_devinfo *fdi; 479111072Sjake 480111072Sjake fdi = device_get_ivars(child); 481143826Smarius return (&fdi->fdi_rl); 482111072Sjake} 483133589Smarius 484167308Smariusstatic const struct ofw_bus_devinfo * 485152684Smariusfhc_get_devinfo(device_t bus, device_t child) 486152684Smarius{ 487152684Smarius struct fhc_devinfo *fdi; 488152684Smarius 489152684Smarius fdi = device_get_ivars(child); 490152684Smarius return (&fdi->fdi_obdinfo); 491152684Smarius} 492152684Smarius 493143826Smariusstatic void 494143826Smariusfhc_led_func(void *arg, int onoff) 495143826Smarius{ 496143826Smarius struct fhc_softc *sc; 497143826Smarius uint32_t ctrl; 498143826Smarius 499143826Smarius sc = (struct fhc_softc *)arg; 500143826Smarius 501172066Smarius ctrl = bus_read_4(sc->sc_memres[FHC_INTERNAL], FHC_CTRL); 502143826Smarius if (onoff) 503143826Smarius ctrl |= FHC_CTRL_RLED; 504143826Smarius else 505143826Smarius ctrl &= ~FHC_CTRL_RLED; 506143826Smarius ctrl &= ~(FHC_CTRL_AOFF | FHC_CTRL_BOFF | FHC_CTRL_SLINE); 507172066Smarius bus_write_4(sc->sc_memres[FHC_INTERNAL], FHC_CTRL, ctrl); 508172066Smarius (void)bus_read_4(sc->sc_memres[FHC_INTERNAL], FHC_CTRL); 509143826Smarius} 510143826Smarius 511152684Smariusstatic int 512152684Smariusfhc_print_res(struct fhc_devinfo *fdi) 513133589Smarius{ 514152684Smarius int rv; 515133589Smarius 516152684Smarius rv = 0; 517152684Smarius rv += resource_list_print_type(&fdi->fdi_rl, "mem", SYS_RES_MEMORY, 518152684Smarius "%#lx"); 519152684Smarius rv += resource_list_print_type(&fdi->fdi_rl, "irq", SYS_RES_IRQ, "%ld"); 520152684Smarius return (rv); 521133589Smarius} 522