static struct resource * ixp425_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct ixp425_softc *sc = device_get_softc(dev); struct rman *rmanp; struct resource *rv; uint32_t vbase, addr; int irq; switch (type) { case SYS_RES_IRQ: rmanp = &sc->sc_irq_rman; /* override per hints */ if (BUS_READ_IVAR(dev, child, IXP425_IVAR_IRQ, &irq) == 0) start = end = irq; rv = rman_reserve_resource(rmanp, start, end, count, flags, child); if (rv != NULL) rman_set_rid(rv, *rid); break; case SYS_RES_MEMORY: rmanp = &sc->sc_mem_rman; /* override per hints */ if (BUS_READ_IVAR(dev, child, IXP425_IVAR_ADDR, &addr) == 0) { start = addr; end = start + 0x1000; /* XXX */ } if (getvbase(start, end - start, &vbase) != 0) { /* likely means above table needs to be updated */ device_printf(dev, "%s: no mapping for 0x%lx:0x%lx\n", __func__, start, end-start); return NULL; } rv = rman_reserve_resource(rmanp, start, end, count, flags, child); if (rv != NULL) { rman_set_rid(rv, *rid); if (strcmp(device_get_name(child), "uart") == 0) rman_set_bustag(rv, &ixp425_a4x_bs_tag); else rman_set_bustag(rv, sc->sc_iot); rman_set_bushandle(rv, vbase); } break; default: rv = NULL; break; } return rv; }
int uart_cpu_getdev(int devtype, struct uart_devinfo *di) { uint32_t i, ivar, vaddr; /* * Scan the hints. The IXP425 only have 2 serial ports, so only * scan them. */ for (i = 0; i < 2; i++) { if (resource_int_value("uart", i, "flags", &ivar)) continue; if (devtype == UART_DEV_CONSOLE && !UART_FLAGS_CONSOLE(ivar)) continue; if (devtype == UART_DEV_DBGPORT && !UART_FLAGS_DBGPORT(ivar)) continue; /* * We have a possible device. Make sure it's enabled and * that we have an I/O port. */ if (resource_int_value("uart", i, "disabled", &ivar) == 0 && ivar != 0) continue; if (resource_int_value("uart", i, "addr", &ivar) != 0 || ivar == 0) continue; /* Got it. Fill in the instance and return it. */ di->ops = uart_getops(&uart_ns8250_class); di->bas.chan = 0; di->bas.bst = &ixp425_a4x_bs_tag; di->bas.regshft = 0; di->bas.rclk = IXP425_UART_FREQ; di->baudrate = 115200; di->databits = 8; di->stopbits = 1; di->parity = UART_PARITY_NONE; uart_bus_space_io = NULL; uart_bus_space_mem = &ixp425_a4x_bs_tag; getvbase(ivar, IXP425_REG_SIZE, &vaddr); di->bas.bsh = vaddr; return (0); } return (ENXIO); }