obio.c revision 202063
1194140Simp/* $NetBSD: obio.c,v 1.11 2003/07/15 00:25:05 lukem Exp $ */ 2194140Simp 3194140Simp/*- 4194140Simp * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. 5194140Simp * All rights reserved. 6194140Simp * 7194140Simp * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8194140Simp * 9194140Simp * Redistribution and use in source and binary forms, with or without 10194140Simp * modification, are permitted provided that the following conditions 11194140Simp * are met: 12194140Simp * 1. Redistributions of source code must retain the above copyright 13194140Simp * notice, this list of conditions and the following disclaimer. 14194140Simp * 2. Redistributions in binary form must reproduce the above copyright 15194140Simp * notice, this list of conditions and the following disclaimer in the 16194140Simp * documentation and/or other materials provided with the distribution. 17194140Simp * 3. All advertising materials mentioning features or use of this software 18194140Simp * must display the following acknowledgement: 19194140Simp * This product includes software developed for the NetBSD Project by 20194140Simp * Wasabi Systems, Inc. 21194140Simp * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22194140Simp * or promote products derived from this software without specific prior 23194140Simp * written permission. 24194140Simp * 25194140Simp * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26194140Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27194140Simp * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28194140Simp * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29194140Simp * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30194140Simp * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31194140Simp * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32194140Simp * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33194140Simp * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34194140Simp * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35194140Simp * POSSIBILITY OF SUCH DAMAGE. 36194140Simp */ 37194140Simp 38194140Simp/* 39194140Simp * On-board device autoconfiguration support for Intel IQ80321 40194140Simp * evaluation boards. 41194140Simp */ 42194140Simp 43194140Simp#include <sys/cdefs.h> 44194140Simp__FBSDID("$FreeBSD: head/sys/mips/cavium/obio.c 202063 2010-01-11 04:29:26Z imp $"); 45194140Simp 46194140Simp#include <sys/param.h> 47194140Simp#include <sys/systm.h> 48194140Simp#include <sys/bus.h> 49194140Simp#include <sys/kernel.h> 50194140Simp#include <sys/module.h> 51194140Simp#include <sys/rman.h> 52194140Simp#include <sys/malloc.h> 53194140Simp 54194140Simp#include <machine/bus.h> 55194140Simp 56202063Simp#include <mips/cavium/octeonreg.h> 57202063Simp#include <mips/cavium/obiovar.h> 58194140Simp 59194140Simpint obio_probe(device_t); 60194140Simpint obio_attach(device_t); 61194140Simp 62194140Simp/* 63196236Simp * We need only one obio. Any other device hanging off of it, 64196236Simp * shouldn't cause multiple of these to be found. 65194140Simp */ 66194140Simpstatic int have_one = 0; 67194140Simp 68194140Simpint 69194140Simpobio_probe(device_t dev) 70194140Simp{ 71196236Simp if (!have_one) { 72194140Simp have_one = 1; 73194140Simp return 0; 74194140Simp } 75196236Simp return (ENXIO); 76194140Simp} 77194140Simp 78194140Simpint 79194140Simpobio_attach(device_t dev) 80194140Simp{ 81194140Simp struct obio_softc *sc = device_get_softc(dev); 82194140Simp 83196236Simp sc->oba_st = mips_bus_space_generic; 84194140Simp sc->oba_addr = OCTEON_UART0ADR; 85194140Simp sc->oba_size = 0x10000; 86194140Simp sc->oba_rman.rm_type = RMAN_ARRAY; 87194140Simp sc->oba_rman.rm_descr = "OBIO I/O"; 88194140Simp if (rman_init(&sc->oba_rman) != 0 || 89194140Simp rman_manage_region(&sc->oba_rman, 90194140Simp sc->oba_addr, sc->oba_addr + sc->oba_size) != 0) 91194140Simp panic("obio_attach: failed to set up I/O rman"); 92194140Simp sc->oba_irq_rman.rm_type = RMAN_ARRAY; 93194140Simp sc->oba_irq_rman.rm_descr = "OBIO IRQ"; 94194140Simp 95194140Simp /* 96194140Simp * This module is intended for UART purposes only and 97194140Simp * it's IRQ is 0 corresponding to IP2. 98194140Simp */ 99194140Simp if (rman_init(&sc->oba_irq_rman) != 0 || 100194140Simp rman_manage_region(&sc->oba_irq_rman, 0, 0) != 0) 101194140Simp panic("obio_attach: failed to set up IRQ rman"); 102194140Simp 103194140Simp device_add_child(dev, "uart", 1); /* Setup Uart-1 first. */ 104194140Simp device_add_child(dev, "uart", 0); /* Uart-0 next. So it is first in console list */ 105194140Simp bus_generic_probe(dev); 106194140Simp bus_generic_attach(dev); 107194140Simp return (0); 108194140Simp} 109194140Simp 110194140Simpstatic struct resource * 111194140Simpobio_alloc_resource(device_t bus, device_t child, int type, int *rid, 112194140Simp u_long start, u_long end, u_long count, u_int flags) 113194140Simp{ 114194140Simp struct resource *rv; 115194140Simp struct rman *rm; 116194140Simp bus_space_tag_t bt = 0; 117194140Simp bus_space_handle_t bh = 0; 118194140Simp struct obio_softc *sc = device_get_softc(bus); 119194140Simp 120194140Simp switch (type) { 121194140Simp case SYS_RES_IRQ: 122194140Simp rm = &sc->oba_irq_rman; 123194140Simp break; 124194140Simp case SYS_RES_MEMORY: 125194140Simp return (NULL); 126194140Simp case SYS_RES_IOPORT: 127194140Simp rm = &sc->oba_rman; 128194140Simp bt = sc->oba_st; 129194140Simp bh = device_get_unit(child) ? OCTEON_UART1ADR : OCTEON_UART0ADR; 130194140Simp start = bh; 131194140Simp break; 132194140Simp default: 133194140Simp return (NULL); 134194140Simp } 135194140Simp 136194140Simp rv = rman_reserve_resource(rm, start, end, count, flags, child); 137194140Simp if (rv == NULL) { 138194140Simp return (NULL); 139194140Simp } 140194140Simp if (type == SYS_RES_IRQ) { 141194140Simp return (rv); 142194140Simp } 143194140Simp rman_set_rid(rv, *rid); 144194140Simp rman_set_bustag(rv, bt); 145194140Simp rman_set_bushandle(rv, bh); 146194140Simp 147194140Simp if (0) { 148194140Simp if (bus_activate_resource(child, type, *rid, rv)) { 149194140Simp rman_release_resource(rv); 150194140Simp return (NULL); 151194140Simp } 152194140Simp } 153194140Simp return (rv); 154194140Simp 155194140Simp} 156194140Simp 157194140Simpstatic int 158194140Simpobio_activate_resource(device_t bus, device_t child, int type, int rid, 159194140Simp struct resource *r) 160194140Simp{ 161194140Simp return (0); 162194140Simp} 163194140Simpstatic device_method_t obio_methods[] = { 164194140Simp DEVMETHOD(device_probe, obio_probe), 165194140Simp DEVMETHOD(device_attach, obio_attach), 166194140Simp 167194140Simp DEVMETHOD(bus_alloc_resource, obio_alloc_resource), 168194140Simp DEVMETHOD(bus_activate_resource, obio_activate_resource), 169194140Simp DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 170194140Simp DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 171194140Simp 172194140Simp {0, 0}, 173194140Simp}; 174194140Simp 175194140Simpstatic driver_t obio_driver = { 176194140Simp "obio", 177194140Simp obio_methods, 178194140Simp sizeof(struct obio_softc), 179194140Simp}; 180194140Simpstatic devclass_t obio_devclass; 181194140Simp 182194140SimpDRIVER_MODULE(obio, nexus, obio_driver, obio_devclass, 0, 0); 183