obio.c revision 178173
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 Broadcom Sentry5
40178173Simp * based boards.
41178173Simp * XXX This is totally bogus and is just enough to get the console hopefully
42178173Simp * running on the sentry5.
43178173Simp */
44178173Simp
45178173Simp#include <sys/cdefs.h>
46178173Simp__FBSDID("$FreeBSD: head/sys/mips/mips32/sentry5/obio.c 178173 2008-04-13 07:44:55Z imp $");
47178173Simp
48178173Simp#include <sys/param.h>
49178173Simp#include <sys/systm.h>
50178173Simp#include <sys/bus.h>
51178173Simp#include <sys/kernel.h>
52178173Simp#include <sys/module.h>
53178173Simp#include <sys/rman.h>
54178173Simp#include <sys/malloc.h>
55178173Simp
56178173Simp#include <machine/bus.h>
57178173Simp
58178173Simp#include <mips/mips32/sentry5/obiovar.h>
59178173Simp#include <mips/mips32/sentry5/sentry5reg.h>
60178173Simp
61178173Simpint	obio_probe(device_t);
62178173Simpint	obio_attach(device_t);
63178173Simp
64178173Simp/*
65178173Simp * A bit tricky and hackish. Since we need OBIO to rely
66178173Simp * on PCI we make it pseudo-pci device. But there should
67178173Simp * be only one such device, so we use this static flag
68178173Simp * to prevent false positives on every realPCI device probe.
69178173Simp */
70178173Simpstatic int have_one = 0;
71178173Simp
72178173Simpint
73178173Simpobio_probe(device_t dev)
74178173Simp{
75178173Simp	if(!have_one)
76178173Simp	{
77178173Simp		have_one = 1;
78178173Simp		return 0;
79178173Simp	}
80178173Simp	else
81178173Simp		return (ENXIO);
82178173Simp}
83178173Simp
84178173Simpint
85178173Simpobio_attach(device_t dev)
86178173Simp{
87178173Simp	struct obio_softc *sc = device_get_softc(dev);
88178173Simp
89178173Simp	sc->oba_st = MIPS_BUS_SPACE_IO;
90178173Simp	sc->oba_addr = MIPS_PHYS_TO_KSEG1(SENTRY5_UART1ADR);
91178173Simp	sc->oba_size = 0x03FFFFFF;	/* XXX sb pci bus 0 aperture size? */
92178173Simp	sc->oba_rman.rm_type = RMAN_ARRAY;
93178173Simp	sc->oba_rman.rm_descr = "OBIO I/O";
94178173Simp	if (rman_init(&sc->oba_rman) != 0 ||
95178173Simp	    rman_manage_region(&sc->oba_rman,
96178173Simp	    sc->oba_addr, sc->oba_addr + sc->oba_size) != 0)
97178173Simp		panic("obio_attach: failed to set up I/O rman");
98178173Simp	sc->oba_irq_rman.rm_type = RMAN_ARRAY;
99178173Simp	sc->oba_irq_rman.rm_descr = "OBIO IRQ";
100178173Simp
101178173Simp	/*
102178173Simp	 * This module is intended for UART purposes only and
103178173Simp	 * it's IRQ is 4
104178173Simp	 */
105178173Simp	if (rman_init(&sc->oba_irq_rman) != 0 ||
106178173Simp	    rman_manage_region(&sc->oba_irq_rman, 4, 4) != 0)
107178173Simp		panic("obio_attach: failed to set up IRQ rman");
108178173Simp
109178173Simp	device_add_child(dev, "uart", 0);
110178173Simp	bus_generic_probe(dev);
111178173Simp	bus_generic_attach(dev);
112178173Simp
113178173Simp	return (0);
114178173Simp}
115178173Simp
116178173Simpstatic struct resource *
117178173Simpobio_alloc_resource(device_t bus, device_t child, int type, int *rid,
118178173Simp    u_long start, u_long end, u_long count, u_int flags)
119178173Simp{
120178173Simp	struct resource *rv;
121178173Simp	struct rman *rm;
122178173Simp	bus_space_tag_t bt = 0;
123178173Simp	bus_space_handle_t bh = 0;
124178173Simp	struct obio_softc *sc = device_get_softc(bus);
125178173Simp
126178173Simp	switch (type) {
127178173Simp	case SYS_RES_IRQ:
128178173Simp		rm = &sc->oba_irq_rman;
129178173Simp		break;
130178173Simp	case SYS_RES_MEMORY:
131178173Simp		return (NULL);
132178173Simp	case SYS_RES_IOPORT:
133178173Simp		rm = &sc->oba_rman;
134178173Simp		bt = sc->oba_st;
135178173Simp		bh = sc->oba_addr;
136178173Simp		start = bh;
137178173Simp		break;
138178173Simp	default:
139178173Simp		return (NULL);
140178173Simp	}
141178173Simp
142178173Simp
143178173Simp	rv = rman_reserve_resource(rm, start, end, count, flags, child);
144178173Simp	if (rv == NULL)
145178173Simp		return (NULL);
146178173Simp	if (type == SYS_RES_IRQ)
147178173Simp		return (rv);
148178173Simp	rman_set_rid(rv, *rid);
149178173Simp	rman_set_bustag(rv, bt);
150178173Simp	rman_set_bushandle(rv, bh);
151178173Simp
152178173Simp	if (0) {
153178173Simp		if (bus_activate_resource(child, type, *rid, rv)) {
154178173Simp			rman_release_resource(rv);
155178173Simp			return (NULL);
156178173Simp		}
157178173Simp	}
158178173Simp	return (rv);
159178173Simp
160178173Simp}
161178173Simp
162178173Simpstatic int
163178173Simpobio_activate_resource(device_t bus, device_t child, int type, int rid,
164178173Simp    struct resource *r)
165178173Simp{
166178173Simp	return (0);
167178173Simp}
168178173Simpstatic device_method_t obio_methods[] = {
169178173Simp	DEVMETHOD(device_probe, obio_probe),
170178173Simp	DEVMETHOD(device_attach, obio_attach),
171178173Simp
172178173Simp	DEVMETHOD(bus_alloc_resource, obio_alloc_resource),
173178173Simp	DEVMETHOD(bus_activate_resource, obio_activate_resource),
174178173Simp	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
175178173Simp	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
176178173Simp
177178173Simp	{0, 0},
178178173Simp};
179178173Simp
180178173Simpstatic driver_t obio_driver = {
181178173Simp	"obio",
182178173Simp	obio_methods,
183178173Simp	sizeof(struct obio_softc),
184178173Simp};
185178173Simpstatic devclass_t obio_devclass;
186178173Simp
187178173SimpDRIVER_MODULE(obio, pci, obio_driver, obio_devclass, 0, 0);
188