obio.c revision 180332
1275072Semaste/* $NetBSD: obio.c,v 1.11 2003/07/15 00:25:05 lukem Exp $ */ 2275072Semaste 3275072Semaste/*- 4275072Semaste * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. 5275072Semaste * All rights reserved. 6275072Semaste * 7275072Semaste * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8275072Semaste * 9275072Semaste * Redistribution and use in source and binary forms, with or without 10275072Semaste * modification, are permitted provided that the following conditions 11275072Semaste * are met: 12275072Semaste * 1. Redistributions of source code must retain the above copyright 13344779Sdim * notice, this list of conditions and the following disclaimer. 14275072Semaste * 2. Redistributions in binary form must reproduce the above copyright 15275072Semaste * notice, this list of conditions and the following disclaimer in the 16275072Semaste * documentation and/or other materials provided with the distribution. 17275072Semaste * 3. All advertising materials mentioning features or use of this software 18275072Semaste * must display the following acknowledgement: 19275072Semaste * This product includes software developed for the NetBSD Project by 20314564Sdim * Wasabi Systems, Inc. 21314564Sdim * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22314564Sdim * or promote products derived from this software without specific prior 23275072Semaste * written permission. 24314564Sdim * 25275072Semaste * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26275072Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27314564Sdim * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28321369Sdim * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29344779Sdim * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30314564Sdim * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31314564Sdim * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32314564Sdim * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33314564Sdim * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34344779Sdim * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35344779Sdim * POSSIBILITY OF SUCH DAMAGE. 36314564Sdim */ 37314564Sdim 38314564Sdim/* 39314564Sdim * On-board device autoconfiguration support for Intel IQ80321 40275072Semaste * evaluation boards. 41275072Semaste */ 42321369Sdim 43314564Sdim#include <sys/cdefs.h> 44314564Sdim__FBSDID("$FreeBSD: head/sys/mips/malta/obio.c 178173 2008-04-13 07:44:55Z imp $"); 45314564Sdim 46314564Sdim#include <sys/param.h> 47314564Sdim#include <sys/systm.h> 48314564Sdim#include <sys/bus.h> 49314564Sdim#include <sys/kernel.h> 50314564Sdim#include <sys/module.h> 51314564Sdim#include <sys/rman.h> 52314564Sdim#include <sys/malloc.h> 53314564Sdim 54314564Sdim#include <machine/bus.h> 55314564Sdim 56314564Sdim#include <mips/mips32/malta/maltareg.h> 57314564Sdim#include <mips/mips32/malta/obiovar.h> 58314564Sdim 59314564Sdimint obio_probe(device_t); 60275072Semasteint obio_attach(device_t); 61275072Semaste 62314564Sdim/* 63321369Sdim * A bit tricky and hackish. Since we need OBIO to rely 64321369Sdim * on PCI we make it pseudo-pci device. But there should 65314564Sdim * be only one such device, so we use this static flag 66314564Sdim * to prevent false positives on every realPCI device probe. 67314564Sdim */ 68314564Sdimstatic int have_one = 0; 69314564Sdim 70314564Sdimint 71314564Sdimobio_probe(device_t dev) 72314564Sdim{ 73314564Sdim if(!have_one) 74314564Sdim { 75314564Sdim have_one = 1; 76314564Sdim return 0; 77314564Sdim } 78314564Sdim else 79314564Sdim return (ENXIO); 80314564Sdim} 81314564Sdim 82314564Sdimint 83314564Sdimobio_attach(device_t dev) 84314564Sdim{ 85314564Sdim struct obio_softc *sc = device_get_softc(dev); 86314564Sdim 87275072Semaste sc->oba_st = MIPS_BUS_SPACE_IO; 88275072Semaste sc->oba_addr = MIPS_PHYS_TO_KSEG1(MALTA_UART0ADR); 89314564Sdim sc->oba_size = MALTA_PCIMEM3_SIZE; 90321369Sdim sc->oba_rman.rm_type = RMAN_ARRAY; 91314564Sdim sc->oba_rman.rm_descr = "OBIO I/O"; 92314564Sdim if (rman_init(&sc->oba_rman) != 0 || 93314564Sdim rman_manage_region(&sc->oba_rman, 94314564Sdim sc->oba_addr, sc->oba_addr + sc->oba_size) != 0) 95314564Sdim panic("obio_attach: failed to set up I/O rman"); 96314564Sdim sc->oba_irq_rman.rm_type = RMAN_ARRAY; 97314564Sdim sc->oba_irq_rman.rm_descr = "OBIO IRQ"; 98314564Sdim 99314564Sdim /* 100314564Sdim * This module is intended for UART purposes only and 101314564Sdim * it's IRQ is 4 102314564Sdim */ 103314564Sdim if (rman_init(&sc->oba_irq_rman) != 0 || 104314564Sdim rman_manage_region(&sc->oba_irq_rman, 4, 4) != 0) 105314564Sdim panic("obio_attach: failed to set up IRQ rman"); 106314564Sdim 107314564Sdim device_add_child(dev, "uart", 0); 108314564Sdim bus_generic_probe(dev); 109314564Sdim bus_generic_attach(dev); 110314564Sdim 111314564Sdim return (0); 112314564Sdim} 113275072Semaste 114static struct resource * 115obio_alloc_resource(device_t bus, device_t child, int type, int *rid, 116 u_long start, u_long end, u_long count, u_int flags) 117{ 118 struct resource *rv; 119 struct rman *rm; 120 bus_space_tag_t bt = 0; 121 bus_space_handle_t bh = 0; 122 struct obio_softc *sc = device_get_softc(bus); 123 124 switch (type) { 125 case SYS_RES_IRQ: 126 rm = &sc->oba_irq_rman; 127 break; 128 case SYS_RES_MEMORY: 129 return (NULL); 130 case SYS_RES_IOPORT: 131 rm = &sc->oba_rman; 132 bt = sc->oba_st; 133 bh = sc->oba_addr; 134 start = bh; 135 break; 136 default: 137 return (NULL); 138 } 139 140 141 rv = rman_reserve_resource(rm, start, end, count, flags, child); 142 if (rv == NULL) 143 return (NULL); 144 if (type == SYS_RES_IRQ) 145 return (rv); 146 rman_set_rid(rv, *rid); 147 rman_set_bustag(rv, bt); 148 rman_set_bushandle(rv, bh); 149 150 if (0) { 151 if (bus_activate_resource(child, type, *rid, rv)) { 152 rman_release_resource(rv); 153 return (NULL); 154 } 155 } 156 return (rv); 157 158} 159 160static int 161obio_activate_resource(device_t bus, device_t child, int type, int rid, 162 struct resource *r) 163{ 164 return (0); 165} 166static device_method_t obio_methods[] = { 167 DEVMETHOD(device_probe, obio_probe), 168 DEVMETHOD(device_attach, obio_attach), 169 170 DEVMETHOD(bus_alloc_resource, obio_alloc_resource), 171 DEVMETHOD(bus_activate_resource, obio_activate_resource), 172 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 173 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 174 175 {0, 0}, 176}; 177 178static driver_t obio_driver = { 179 "obio", 180 obio_methods, 181 sizeof(struct obio_softc), 182}; 183static devclass_t obio_devclass; 184 185DRIVER_MODULE(obio, pci, obio_driver, obio_devclass, 0, 0); 186