1178173Simp/* $NetBSD: obio.c,v 1.11 2003/07/15 00:25:05 lukem Exp $ */ 2178173Simp 3178173Simp/*- 4178173Simp * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. 5178173Simp * All rights reserved. 6178173Simp * 7178173Simp * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8178173Simp * 9178173Simp * Redistribution and use in source and binary forms, with or without 10178173Simp * modification, are permitted provided that the following conditions 11178173Simp * are met: 12178173Simp * 1. Redistributions of source code must retain the above copyright 13178173Simp * notice, this list of conditions and the following disclaimer. 14178173Simp * 2. Redistributions in binary form must reproduce the above copyright 15178173Simp * notice, this list of conditions and the following disclaimer in the 16178173Simp * documentation and/or other materials provided with the distribution. 17178173Simp * 3. All advertising materials mentioning features or use of this software 18178173Simp * must display the following acknowledgement: 19178173Simp * This product includes software developed for the NetBSD Project by 20178173Simp * Wasabi Systems, Inc. 21178173Simp * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22178173Simp * or promote products derived from this software without specific prior 23178173Simp * written permission. 24178173Simp * 25178173Simp * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26178173Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27178173Simp * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28178173Simp * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29178173Simp * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30178173Simp * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31178173Simp * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32178173Simp * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33178173Simp * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34178173Simp * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35178173Simp * POSSIBILITY OF SUCH DAMAGE. 36178173Simp */ 37178173Simp 38178173Simp/* 39178173Simp * On-board device autoconfiguration support for Intel IQ80321 40178173Simp * evaluation boards. 41178173Simp */ 42178173Simp 43178173Simp#include <sys/cdefs.h> 44178173Simp__FBSDID("$FreeBSD$"); 45178173Simp 46178173Simp#include <sys/param.h> 47178173Simp#include <sys/systm.h> 48178173Simp#include <sys/bus.h> 49178173Simp#include <sys/kernel.h> 50178173Simp#include <sys/module.h> 51178173Simp#include <sys/rman.h> 52178173Simp#include <sys/malloc.h> 53178173Simp 54178173Simp#include <machine/bus.h> 55178173Simp 56182901Sgonzo#include <mips/malta/maltareg.h> 57182901Sgonzo#include <mips/malta/obiovar.h> 58178173Simp 59178173Simpint obio_probe(device_t); 60178173Simpint obio_attach(device_t); 61178173Simp 62178173Simp/* 63178173Simp * A bit tricky and hackish. Since we need OBIO to rely 64178173Simp * on PCI we make it pseudo-pci device. But there should 65178173Simp * be only one such device, so we use this static flag 66202035Simp * to prevent false positives on every real PCI device probe. 67178173Simp */ 68178173Simpstatic int have_one = 0; 69178173Simp 70178173Simpint 71178173Simpobio_probe(device_t dev) 72178173Simp{ 73202035Simp if (!have_one) { 74178173Simp have_one = 1; 75178173Simp return 0; 76178173Simp } 77202035Simp return (ENXIO); 78178173Simp} 79178173Simp 80178173Simpint 81178173Simpobio_attach(device_t dev) 82178173Simp{ 83178173Simp struct obio_softc *sc = device_get_softc(dev); 84178173Simp 85202035Simp sc->oba_st = mips_bus_space_generic; 86178173Simp sc->oba_addr = MIPS_PHYS_TO_KSEG1(MALTA_UART0ADR); 87178173Simp sc->oba_size = MALTA_PCIMEM3_SIZE; 88178173Simp sc->oba_rman.rm_type = RMAN_ARRAY; 89178173Simp sc->oba_rman.rm_descr = "OBIO I/O"; 90178173Simp if (rman_init(&sc->oba_rman) != 0 || 91178173Simp rman_manage_region(&sc->oba_rman, 92178173Simp sc->oba_addr, sc->oba_addr + sc->oba_size) != 0) 93178173Simp panic("obio_attach: failed to set up I/O rman"); 94178173Simp sc->oba_irq_rman.rm_type = RMAN_ARRAY; 95178173Simp sc->oba_irq_rman.rm_descr = "OBIO IRQ"; 96178173Simp 97178173Simp /* 98178173Simp * This module is intended for UART purposes only and 99178173Simp * it's IRQ is 4 100178173Simp */ 101178173Simp if (rman_init(&sc->oba_irq_rman) != 0 || 102178173Simp rman_manage_region(&sc->oba_irq_rman, 4, 4) != 0) 103178173Simp panic("obio_attach: failed to set up IRQ rman"); 104178173Simp 105178173Simp device_add_child(dev, "uart", 0); 106178173Simp bus_generic_probe(dev); 107178173Simp bus_generic_attach(dev); 108178173Simp 109178173Simp return (0); 110178173Simp} 111178173Simp 112178173Simpstatic struct resource * 113178173Simpobio_alloc_resource(device_t bus, device_t child, int type, int *rid, 114178173Simp u_long start, u_long end, u_long count, u_int flags) 115178173Simp{ 116178173Simp struct resource *rv; 117178173Simp struct rman *rm; 118178173Simp bus_space_tag_t bt = 0; 119178173Simp bus_space_handle_t bh = 0; 120178173Simp struct obio_softc *sc = device_get_softc(bus); 121178173Simp 122178173Simp switch (type) { 123178173Simp case SYS_RES_IRQ: 124178173Simp rm = &sc->oba_irq_rman; 125178173Simp break; 126178173Simp case SYS_RES_MEMORY: 127178173Simp return (NULL); 128178173Simp case SYS_RES_IOPORT: 129178173Simp rm = &sc->oba_rman; 130178173Simp bt = sc->oba_st; 131178173Simp bh = sc->oba_addr; 132178173Simp start = bh; 133178173Simp break; 134178173Simp default: 135178173Simp return (NULL); 136178173Simp } 137178173Simp 138178173Simp 139178173Simp rv = rman_reserve_resource(rm, start, end, count, flags, child); 140178173Simp if (rv == NULL) 141178173Simp return (NULL); 142178173Simp if (type == SYS_RES_IRQ) 143178173Simp return (rv); 144178173Simp rman_set_rid(rv, *rid); 145178173Simp rman_set_bustag(rv, bt); 146178173Simp rman_set_bushandle(rv, bh); 147178173Simp 148178173Simp if (0) { 149178173Simp if (bus_activate_resource(child, type, *rid, rv)) { 150178173Simp rman_release_resource(rv); 151178173Simp return (NULL); 152178173Simp } 153178173Simp } 154178173Simp return (rv); 155178173Simp 156178173Simp} 157178173Simp 158178173Simpstatic int 159178173Simpobio_activate_resource(device_t bus, device_t child, int type, int rid, 160178173Simp struct resource *r) 161178173Simp{ 162178173Simp return (0); 163178173Simp} 164178173Simpstatic device_method_t obio_methods[] = { 165178173Simp DEVMETHOD(device_probe, obio_probe), 166178173Simp DEVMETHOD(device_attach, obio_attach), 167178173Simp 168178173Simp DEVMETHOD(bus_alloc_resource, obio_alloc_resource), 169178173Simp DEVMETHOD(bus_activate_resource, obio_activate_resource), 170178173Simp DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 171178173Simp DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 172178173Simp 173178173Simp {0, 0}, 174178173Simp}; 175178173Simp 176178173Simpstatic driver_t obio_driver = { 177178173Simp "obio", 178178173Simp obio_methods, 179178173Simp sizeof(struct obio_softc), 180178173Simp}; 181178173Simpstatic devclass_t obio_devclass; 182178173Simp 183178173SimpDRIVER_MODULE(obio, pci, obio_driver, obio_devclass, 0, 0); 184