NetBSD/sys/arch/x68k/dev/neptune.c

193 lines
5.2 KiB
C
Raw Normal View History

/* $NetBSD: neptune.c,v 1.19 2008/12/18 05:56:42 isaki Exp $ */
1999-03-16 19:30:16 +03:00
2000-01-16 17:20:54 +03:00
/*-
2008-05-04 04:35:37 +04:00
* Copyright (c) 1998 The NetBSD Foundation, Inc.
1999-03-16 19:30:16 +03:00
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Minoura Makoto.
*
* 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.
*
2000-01-16 17:20:54 +03:00
* 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.
1999-03-16 19:30:16 +03:00
*/
/*
* Neptune-X -- X68k-ISA Bus Bridge
*/
2003-07-15 05:44:50 +04:00
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: neptune.c,v 1.19 2008/12/18 05:56:42 isaki Exp $");
2003-07-15 05:44:50 +04:00
1999-03-16 19:30:16 +03:00
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/frame.h>
#include <arch/x68k/dev/intiovar.h>
#include <arch/x68k/dev/neptunevar.h>
/* bus_space stuff */
2005-01-18 10:12:15 +03:00
static int neptune_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
int, bus_space_handle_t *);
static void neptune_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
bus_size_t);
static int neptune_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_size_t, bus_space_handle_t *);
1999-03-16 19:30:16 +03:00
static struct x68k_bus_space neptune_bus = {
#if 0
X68K_NEPUTUNE_BUS,
#endif
neptune_bus_space_map, neptune_bus_space_unmap,
neptune_bus_space_subregion,
x68k_bus_space_alloc, x68k_bus_space_free,
};
static int neptune_match(device_t, cfdata_t, void *);
static void neptune_attach(device_t, device_t, void *);
static int neptune_search(device_t, cfdata_t, const int *, void *);
2005-01-18 10:12:15 +03:00
static int neptune_print(void *, const char *);
1999-03-16 19:30:16 +03:00
CFATTACH_DECL_NEW(neptune, sizeof(struct neptune_softc),
2002-10-02 20:02:08 +04:00
neptune_match, neptune_attach, NULL, NULL);
1999-03-16 19:30:16 +03:00
2007-03-11 11:09:23 +03:00
static int
neptune_match(device_t parent, cfdata_t cf, void *aux)
1999-03-16 19:30:16 +03:00
{
struct intio_attach_args *ia = aux;
if (strcmp(ia->ia_name, "neptune") != 0)
return 0;
ia->ia_size = 0x400;
2007-03-11 11:09:23 +03:00
if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
1999-03-16 19:30:16 +03:00
return 0;
/* Neptune is a virtual device. Always there. */
return (1);
}
2007-03-11 11:09:23 +03:00
static void
neptune_attach(device_t parent, device_t self, void *aux)
1999-03-16 19:30:16 +03:00
{
struct neptune_softc *sc = device_private(self);
1999-03-16 19:30:16 +03:00
struct intio_attach_args *ia = aux;
struct neptune_attach_args na;
int r;
cfdata_t cf;
1999-03-16 19:30:16 +03:00
ia->ia_size = 0x400;
2007-03-11 11:09:23 +03:00
r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
1999-03-16 19:30:16 +03:00
#ifdef DIAGNOSTIC
if (r)
2007-03-11 11:09:23 +03:00
panic("IO map for Neptune corruption??");
1999-03-16 19:30:16 +03:00
#endif
sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_NOWAIT);
if (sc->sc_bst == NULL)
panic("neptune_attach: can't allocate bus_space structure");
*sc->sc_bst = neptune_bus;
sc->sc_bst->x68k_bus_device = self;
sc->sc_addr = (vaddr_t)IIOV(ia->ia_addr);
1999-03-16 19:30:16 +03:00
na.na_bst = sc->sc_bst;
na.na_intr = ia->ia_intr;
cf = config_search_ia(neptune_search, self, "neptune", &na);
1999-03-16 19:30:16 +03:00
if (cf) {
aprint_normal(": Neptune-X ISA bridge\n");
1999-03-16 19:30:16 +03:00
config_attach(self, cf, &na, neptune_print);
} else {
aprint_normal(": no device found.\n");
1999-03-16 19:30:16 +03:00
intio_map_free_region(parent, ia);
}
}
2007-03-11 11:09:23 +03:00
static int
neptune_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
1999-03-16 19:30:16 +03:00
{
struct neptune_attach_args *na = aux;
na->na_addr = cf->neptune_cf_addr;
return config_match(parent, cf, na);
1999-03-16 19:30:16 +03:00
}
2007-03-11 11:09:23 +03:00
static int
2005-01-18 10:12:15 +03:00
neptune_print(void *aux, const char *name)
1999-03-16 19:30:16 +03:00
{
struct neptune_attach_args *na = aux;
/* if (na->na_addr > 0) */
2007-03-11 11:09:23 +03:00
aprint_normal(" addr 0x%06x", na->na_addr);
1999-03-16 19:30:16 +03:00
return (QUIET);
}
/*
* neptune bus space stuff.
*/
2007-03-11 11:09:23 +03:00
static int
2005-01-18 10:12:15 +03:00
neptune_bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size,
int flags, bus_space_handle_t *bshp)
1999-03-16 19:30:16 +03:00
{
struct neptune_softc *sc = device_private(t->x68k_bus_device);
vaddr_t start = sc->sc_addr;
1999-03-16 19:30:16 +03:00
/*
* Neptune bus is mapped permanently.
*/
*bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2);
2007-03-11 11:09:23 +03:00
if (badaddr((void *)*bshp)) {
1999-03-16 19:30:16 +03:00
return 1;
}
*bshp |= 0x80000000; /* higher byte (= even address) only */
return (0);
}
2007-03-11 11:09:23 +03:00
static void
2005-01-18 10:12:15 +03:00
neptune_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
bus_size_t size)
1999-03-16 19:30:16 +03:00
{
return;
}
2007-03-11 11:09:23 +03:00
static int
2005-01-18 10:12:15 +03:00
neptune_bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
1999-03-16 19:30:16 +03:00
{
*nbshp = bsh + offset*2;
return (0);
}