Add autoconfiguration support for the Sun4d "bootbus". Add a
zs @ bootbus attachment.
This commit is contained in:
parent
89fd7196ed
commit
41c25cb648
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: files.sparc,v 1.114 2002/08/23 18:00:46 thorpej Exp $
|
||||
# $NetBSD: files.sparc,v 1.115 2002/08/24 05:26:56 thorpej Exp $
|
||||
|
||||
# @(#)files.sparc 8.1 (Berkeley) 7/19/93
|
||||
# sparc-specific configuration info
|
||||
|
@ -44,6 +44,14 @@ file arch/sparc/sparc/iommu.c iommu
|
|||
device obio { [addr = -1], [level = -1] }
|
||||
attach obio at mainbus
|
||||
|
||||
device cpuunit { }
|
||||
attach cpuunit at mainbus
|
||||
file arch/sparc/sparc/cpuunit.c cpuunit
|
||||
|
||||
device bootbus { [slot = -1], [offset = -1] }
|
||||
attach bootbus at cpuunit
|
||||
file arch/sparc/dev/bootbus.c bootbus
|
||||
|
||||
include "dev/vme/files.vme"
|
||||
device sparcvme: vmebus
|
||||
attach sparcvme at mainbus with vme_mainbus
|
||||
|
@ -89,10 +97,6 @@ device power
|
|||
attach power at obio
|
||||
file arch/sparc/dev/power.c power needs-flag
|
||||
|
||||
device cpuunit { }
|
||||
attach cpuunit at mainbus
|
||||
file arch/sparc/sparc/cpuunit.c cpuunit
|
||||
|
||||
device cpu
|
||||
attach cpu at mainbus with cpu_mainbus
|
||||
attach cpu at cpuunit with cpu_cpuunit
|
||||
|
@ -116,6 +120,7 @@ include "dev/sun/files.sun"
|
|||
device zs {channel = -1}
|
||||
attach zs at mainbus with zs_mainbus
|
||||
attach zs at obio with zs_obio
|
||||
attach zs at bootbus with zs_bootbus
|
||||
file arch/sparc/dev/zs.c zs needs-count
|
||||
file dev/ic/z8530sc.c zs
|
||||
|
||||
|
|
|
@ -0,0 +1,304 @@
|
|||
/* $NetBSD: bootbus.c,v 1.1 2002/08/24 05:26:57 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jason R. Thorpe.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Autoconfiguration support for Sun4d "bootbus".
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <sparc/sparc/cpuunitvar.h>
|
||||
#include <sparc/dev/bootbusvar.h>
|
||||
#include <machine/autoconf.h>
|
||||
|
||||
#include "locators.h"
|
||||
|
||||
struct bootbus_softc {
|
||||
struct device sc_dev;
|
||||
int sc_node; /* our OBP node */
|
||||
|
||||
bus_space_tag_t sc_st; /* ours */
|
||||
bus_space_tag_t sc_bustag; /* passed on to children */
|
||||
|
||||
struct openprom_range *sc_range; /* our address ranges */
|
||||
int sc_nrange;
|
||||
};
|
||||
|
||||
static int bootbus_match(struct device *, struct cfdata *, void *);
|
||||
static void bootbus_attach(struct device *, struct device *, void *);
|
||||
|
||||
struct cfattach bootbus_ca = {
|
||||
sizeof(struct bootbus_softc), bootbus_match, bootbus_attach,
|
||||
};
|
||||
|
||||
static int bootbus_submatch(struct device *, struct cfdata *, void *);
|
||||
static int bootbus_print(void *, const char *);
|
||||
|
||||
static int bootbus_bus_map(bus_space_tag_t, bus_addr_t, size_t, int,
|
||||
vaddr_t, bus_space_handle_t *);
|
||||
static paddr_t bootbus_bus_mmap(bus_space_tag_t, bus_addr_t, off_t,
|
||||
int, int);
|
||||
static void *bootbus_intr_establish(bus_space_tag_t, int, int, int,
|
||||
int (*)(void *), void *);
|
||||
|
||||
static int bootbus_setup_attach_args(struct bootbus_softc *, bus_space_tag_t,
|
||||
int, struct bootbus_attach_args *);
|
||||
static void bootbus_destroy_attach_args(struct bootbus_attach_args *);
|
||||
|
||||
static int
|
||||
bootbus_match(struct device *parent, struct cfdata *cf, void *aux)
|
||||
{
|
||||
struct cpuunit_attach_args *cpua = aux;
|
||||
|
||||
if (strcmp(cpua->cpua_name, cf->cf_driver->cd_name) == 0)
|
||||
return (1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
bootbus_attach(struct device *parent, struct device *self, void *aux)
|
||||
{
|
||||
struct bootbus_softc *sc = (void *) self;
|
||||
struct cpuunit_attach_args *cpua = aux;
|
||||
int node, error;
|
||||
|
||||
sc->sc_node = cpua->cpua_node;
|
||||
sc->sc_st = cpua->cpua_bustag;
|
||||
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
* Initialize the bus space tag we pass on to our children.
|
||||
*/
|
||||
sc->sc_bustag = malloc(sizeof(*sc->sc_bustag), M_DEVBUF,
|
||||
M_WAITOK|M_ZERO);
|
||||
sc->sc_bustag->cookie = sc;
|
||||
sc->sc_bustag->parent = sc->sc_st;
|
||||
sc->sc_bustag->sparc_bus_map = bootbus_bus_map;
|
||||
sc->sc_bustag->sparc_bus_mmap = bootbus_bus_mmap;
|
||||
sc->sc_bustag->sparc_intr_establish = bootbus_intr_establish;
|
||||
|
||||
/*
|
||||
* Collect address translations from the OBP.
|
||||
*/
|
||||
error = PROM_getprop(sc->sc_node, "ranges",
|
||||
sizeof(struct openprom_range), &sc->sc_nrange,
|
||||
(void **) &sc->sc_range);
|
||||
if (error) {
|
||||
printf("%s: error %d getting \"ranges\" property\n",
|
||||
sc->sc_dev.dv_xname, error);
|
||||
panic("bootbus_attach");
|
||||
}
|
||||
|
||||
/* Attach the CPU (and possibly bootbus) child nodes. */
|
||||
for (node = firstchild(sc->sc_node); node != 0;
|
||||
node = nextsibling(node)) {
|
||||
struct bootbus_attach_args baa;
|
||||
|
||||
if (bootbus_setup_attach_args(sc, sc->sc_bustag, node, &baa))
|
||||
panic("bootbus_attach: failed to set up attach args");
|
||||
|
||||
(void) config_found_sm(&sc->sc_dev, &baa, bootbus_print,
|
||||
bootbus_submatch);
|
||||
|
||||
bootbus_destroy_attach_args(&baa);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
bootbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
|
||||
{
|
||||
struct bootbus_attach_args *baa = aux;
|
||||
|
||||
if (cf->cf_loc[BOOTBUSCF_SLOT] != BOOTBUSCF_SLOT_DEFAULT &&
|
||||
cf->cf_loc[BOOTBUSCF_SLOT] != baa->ba_slot)
|
||||
return (0);
|
||||
|
||||
if (cf->cf_loc[BOOTBUSCF_OFFSET] != BOOTBUSCF_OFFSET_DEFAULT &&
|
||||
cf->cf_loc[BOOTBUSCF_OFFSET] != baa->ba_offset)
|
||||
return (0);
|
||||
|
||||
return ((*cf->cf_attach->ca_match)(parent, cf, aux));
|
||||
}
|
||||
|
||||
static int
|
||||
bootbus_print(void *aux, const char *pnp)
|
||||
{
|
||||
struct bootbus_attach_args *baa = aux;
|
||||
int i;
|
||||
|
||||
if (pnp)
|
||||
printf("%s at %s", baa->ba_name, pnp);
|
||||
printf(" slot %d offset 0x%x", baa->ba_slot, baa->ba_offset);
|
||||
for (i = 0; i < baa->ba_nintr; i++)
|
||||
printf(" ipl %d", baa->ba_intr[i].oi_pri);
|
||||
|
||||
return (UNCONF);
|
||||
}
|
||||
|
||||
static int
|
||||
bootbus_setup_attach_args(struct bootbus_softc *sc, bus_space_tag_t bustag,
|
||||
int node, struct bootbus_attach_args *baa)
|
||||
{
|
||||
int n, error;
|
||||
|
||||
memset(baa, 0, sizeof(*baa));
|
||||
|
||||
error = PROM_getprop(node, "name", 1, &n, (void **) &baa->ba_name);
|
||||
if (error)
|
||||
return (error);
|
||||
baa->ba_name[n] = '\0';
|
||||
|
||||
baa->ba_bustag = bustag;
|
||||
baa->ba_node = node;
|
||||
|
||||
error = PROM_getprop(node, "reg", sizeof(struct openprom_addr),
|
||||
&baa->ba_nreg, (void **) &baa->ba_reg);
|
||||
if (error) {
|
||||
bootbus_destroy_attach_args(baa);
|
||||
return (error);
|
||||
}
|
||||
|
||||
error = PROM_getprop(node, "intr", sizeof(struct openprom_intr),
|
||||
&baa->ba_nintr, (void **) &baa->ba_intr);
|
||||
if (error != 0 && error != ENOENT) {
|
||||
bootbus_destroy_attach_args(baa);
|
||||
return (error);
|
||||
}
|
||||
|
||||
error = PROM_getprop(node, "address", sizeof(uint32_t),
|
||||
&baa->ba_npromvaddrs, (void **) &baa->ba_promvaddrs);
|
||||
if (error != 0 && error != ENOENT) {
|
||||
bootbus_destroy_attach_args(baa);
|
||||
return (error);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
bootbus_destroy_attach_args(struct bootbus_attach_args *baa)
|
||||
{
|
||||
|
||||
if (baa->ba_name != NULL)
|
||||
free(baa->ba_name, M_DEVBUF);
|
||||
|
||||
if (baa->ba_reg != NULL)
|
||||
free(baa->ba_reg, M_DEVBUF);
|
||||
|
||||
if (baa->ba_intr != NULL)
|
||||
free(baa->ba_intr, M_DEVBUF);
|
||||
|
||||
if (baa->ba_promvaddrs != NULL)
|
||||
free(baa->ba_promvaddrs, M_DEVBUF);
|
||||
}
|
||||
|
||||
static int
|
||||
bootbus_translate_address(struct bootbus_softc *sc, bus_addr_t addr,
|
||||
bus_addr_t *addrp)
|
||||
{
|
||||
int space = BUS_ADDR_IOSPACE(addr);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sc->sc_nrange; i++) {
|
||||
struct openprom_range *rp = &sc->sc_range[i];
|
||||
|
||||
if (rp->or_child_space != space)
|
||||
continue;
|
||||
|
||||
/* We've found the connection to the parent bus. */
|
||||
*addrp = BUS_ADDR(rp->or_parent_space,
|
||||
rp->or_parent_base + BUS_ADDR_PADDR(addr));
|
||||
return (0);
|
||||
}
|
||||
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
static int
|
||||
bootbus_bus_map(bus_space_tag_t t, bus_addr_t ba, bus_size_t size,
|
||||
int flags, vaddr_t va, bus_space_handle_t *hp)
|
||||
{
|
||||
struct bootbus_softc *sc = t->cookie;
|
||||
bus_addr_t addr;
|
||||
int error;
|
||||
|
||||
error = bootbus_translate_address(sc, ba, &addr);
|
||||
if (error)
|
||||
return (error);
|
||||
return (bus_space_map2(sc->sc_st, addr, size, flags, va, hp));
|
||||
}
|
||||
|
||||
static paddr_t
|
||||
bootbus_bus_mmap(bus_space_tag_t t, bus_addr_t ba, off_t off, int prot,
|
||||
int flags)
|
||||
{
|
||||
struct bootbus_softc *sc = t->cookie;
|
||||
bus_addr_t addr;
|
||||
int error;
|
||||
|
||||
error = bootbus_translate_address(sc, ba, &addr);
|
||||
if (error)
|
||||
return (-1);
|
||||
return (bus_space_mmap(sc->sc_st, addr, off, prot, flags));
|
||||
}
|
||||
|
||||
static void *
|
||||
bootbus_intr_establish(bus_space_tag_t t, int pil, int level, int flags,
|
||||
int (*handler)(void *), void *arg)
|
||||
{
|
||||
struct intrhand *ih;
|
||||
|
||||
ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
|
||||
if (ih == NULL)
|
||||
return (NULL);
|
||||
|
||||
ih->ih_fun = handler;
|
||||
ih->ih_arg = arg;
|
||||
if ((flags & BUS_INTR_ESTABLISH_FASTTRAP) != 0)
|
||||
intr_fasttrap(pil, (void (*)__P((void)))handler);
|
||||
else
|
||||
intr_establish(pil, ih);
|
||||
return (ih);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/* $NetBSD: bootbusvar.h,v 1.1 2002/08/24 05:26:57 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jason R. Thorpe.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SPARC_BOOTBUSVAR_H_
|
||||
#define _SPARC_BOOTBUSVAR_H_
|
||||
|
||||
struct bootbus_attach_args {
|
||||
char *ba_name;
|
||||
int ba_node;
|
||||
bus_space_tag_t ba_bustag;
|
||||
|
||||
struct openprom_addr *ba_reg;
|
||||
int ba_nreg;
|
||||
#define ba_slot ba_reg[0].oa_space
|
||||
#define ba_offset ba_reg[0].oa_base
|
||||
#define ba_size ba_reg[0].oa_size
|
||||
|
||||
struct openprom_intr *ba_intr;
|
||||
int ba_nintr;
|
||||
|
||||
uint32_t *ba_promvaddrs;
|
||||
int ba_npromvaddrs;
|
||||
};
|
||||
|
||||
#endif /* _SPARC_BOOTBUSVAR_H_ */
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: zs.c,v 1.85 2002/03/11 16:27:02 pk Exp $ */
|
||||
/* $NetBSD: zs.c,v 1.86 2002/08/24 05:26:57 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
|
@ -46,6 +46,7 @@
|
|||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_kgdb.h"
|
||||
#include "opt_sparc_arch.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -172,6 +173,16 @@ static int zs_match_obio __P((struct device *, struct cfdata *, void *));
|
|||
static void zs_attach_mainbus __P((struct device *, struct device *, void *));
|
||||
static void zs_attach_obio __P((struct device *, struct device *, void *));
|
||||
|
||||
#if defined(SUN4D)
|
||||
#include <sparc/dev/bootbusvar.h>
|
||||
|
||||
static int zs_match_bootbus __P((struct device *, struct cfdata *, void *));
|
||||
static void zs_attach_bootbus __P((struct device *, struct device *, void *));
|
||||
|
||||
struct cfattach zs_bootbus_ca = {
|
||||
sizeof(struct zsc_softc), zs_match_bootbus, zs_attach_bootbus
|
||||
};
|
||||
#endif /* SUN4D */
|
||||
|
||||
static void zs_attach __P((struct zsc_softc *, struct zsdevice *, int));
|
||||
static int zs_print __P((void *, const char *name));
|
||||
|
@ -240,6 +251,19 @@ zs_match_obio(parent, cf, aux)
|
|||
1, 0, 0, NULL, NULL));
|
||||
}
|
||||
|
||||
#if defined(SUN4D)
|
||||
static int
|
||||
zs_match_bootbus(parent, cf, aux)
|
||||
struct device *parent;
|
||||
struct cfdata *cf;
|
||||
void *aux;
|
||||
{
|
||||
struct bootbus_attach_args *baa = aux;
|
||||
|
||||
return (strcmp(cf->cf_driver->cd_name, baa->ba_name) == 0);
|
||||
}
|
||||
#endif /* SUN4D */
|
||||
|
||||
static void
|
||||
zs_attach_mainbus(parent, self, aux)
|
||||
struct device *parent;
|
||||
|
@ -352,6 +376,44 @@ zs_attach_obio(parent, self, aux)
|
|||
zs_attach(zsc, (void *)bh, oba->oba_pri);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SUN4D)
|
||||
static void
|
||||
zs_attach_bootbus(parent, self, aux)
|
||||
struct device *parent;
|
||||
struct device *self;
|
||||
void *aux;
|
||||
{
|
||||
struct zsc_softc *zsc = (void *) self;
|
||||
struct bootbus_attach_args *baa = aux;
|
||||
void *va;
|
||||
|
||||
if (baa->ba_nintr == 0) {
|
||||
printf(": no interrupt lines\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (baa->ba_npromvaddrs > 0)
|
||||
va = (void *) baa->ba_promvaddrs;
|
||||
else {
|
||||
bus_space_handle_t bh;
|
||||
|
||||
if (bus_space_map(baa->ba_bustag,
|
||||
BUS_ADDR(baa->ba_slot, baa->ba_offset),
|
||||
baa->ba_size, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
|
||||
printf(": cannot map zs registers\n");
|
||||
return;
|
||||
}
|
||||
va = (void *) bh;
|
||||
}
|
||||
|
||||
zsc->zsc_bustag = baa->ba_bustag;
|
||||
zsc->zsc_promunit = PROM_getpropint(baa->ba_node, "slave", -2);
|
||||
zsc->zsc_node = baa->ba_node;
|
||||
zs_attach(zsc, va, baa->ba_intr[0].oi_pri);
|
||||
}
|
||||
#endif /* SUN4D */
|
||||
|
||||
/*
|
||||
* Attach a found zs.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue