1998-06-09 21:19:01 +04:00
|
|
|
/* $NetBSD: bus_subr.c,v 1.12 1998/06/09 17:19:01 gwr Exp $ */
|
1997-02-18 17:58:32 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Adam Glass and Gordon W. Ross.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1998-02-08 08:02:50 +03:00
|
|
|
* bus_xxx support functions, Sun3X-specific part.
|
|
|
|
* The common stuff is in autoconf.c
|
1997-02-18 17:58:32 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_map.h>
|
|
|
|
|
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/mon.h>
|
1998-02-05 07:56:24 +03:00
|
|
|
#include <machine/pmap.h>
|
|
|
|
#include <machine/pte.h>
|
|
|
|
|
|
|
|
#include <sun3/sun3/machdep.h>
|
|
|
|
#include <sun3/sun3x/vme.h>
|
1997-02-18 17:58:32 +03:00
|
|
|
|
|
|
|
label_t *nofault;
|
|
|
|
|
1997-05-30 11:02:14 +04:00
|
|
|
/* These are defined in pmap.c */
|
1997-02-18 17:58:32 +03:00
|
|
|
extern vm_offset_t tmp_vpages[];
|
1997-05-30 11:02:14 +04:00
|
|
|
extern int tmp_vpages_inuse;
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
static const struct {
|
|
|
|
long base;
|
|
|
|
long mask;
|
|
|
|
} bus_info[BUS__NTYPES] = {
|
|
|
|
{ /* OBIO */ 0, ~0 },
|
|
|
|
{ /* OBMEM */ 0, ~0 },
|
|
|
|
/* VME A16 */
|
|
|
|
{ VME16D16_BASE, VME16_MASK },
|
|
|
|
{ VME16D32_BASE, VME16_MASK },
|
|
|
|
/* VME A24 */
|
|
|
|
{ VME24D16_BASE, VME24_MASK },
|
|
|
|
{ VME24D32_BASE, VME24_MASK },
|
|
|
|
/* VME A32 */
|
|
|
|
{ VME32D16_BASE, VME32_MASK },
|
|
|
|
{ VME32D32_BASE, VME32_MASK },
|
|
|
|
};
|
1997-02-18 17:58:32 +03:00
|
|
|
|
|
|
|
/*
|
1998-02-08 08:02:50 +03:00
|
|
|
* Create a temporary, one-page mapping for a device.
|
|
|
|
* This is used by some device probe routines that
|
|
|
|
* need to do peek/write/read tricks.
|
1997-02-18 17:58:32 +03:00
|
|
|
*/
|
1998-02-08 08:02:50 +03:00
|
|
|
void *
|
|
|
|
bus_tmapin(bustype, pa)
|
|
|
|
int bustype, pa;
|
1997-02-18 17:58:32 +03:00
|
|
|
{
|
1997-10-16 20:13:21 +04:00
|
|
|
vm_offset_t pgva;
|
1998-06-09 21:19:01 +04:00
|
|
|
int off, s;
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
if ((bustype < 0) || (bustype >= BUS__NTYPES))
|
1998-02-08 08:02:50 +03:00
|
|
|
panic("bus_tmapin: bustype");
|
1998-02-05 07:56:24 +03:00
|
|
|
|
1997-10-16 20:13:21 +04:00
|
|
|
off = pa & PGOFSET;
|
|
|
|
pa -= off;
|
1998-02-08 08:02:50 +03:00
|
|
|
|
|
|
|
pa &= bus_info[bustype].mask;
|
|
|
|
pa |= bus_info[bustype].base;
|
1997-10-16 20:13:21 +04:00
|
|
|
pa |= PMAP_NC;
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1997-05-28 08:27:00 +04:00
|
|
|
s = splimp();
|
1997-05-30 11:02:14 +04:00
|
|
|
if (tmp_vpages_inuse)
|
1998-02-08 08:02:50 +03:00
|
|
|
panic("bus_tmapin: tmp_vpages_inuse");
|
1997-05-30 11:02:14 +04:00
|
|
|
tmp_vpages_inuse++;
|
1997-05-28 08:27:00 +04:00
|
|
|
|
1997-10-16 20:13:21 +04:00
|
|
|
pgva = tmp_vpages[1];
|
|
|
|
pmap_enter(pmap_kernel(), pgva, pa,
|
|
|
|
(VM_PROT_READ|VM_PROT_WRITE), TRUE);
|
1998-02-08 08:02:50 +03:00
|
|
|
splx(s);
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
return ((void *)(pgva + off));
|
|
|
|
}
|
|
|
|
|
|
|
|
void bus_tmapout(vp)
|
|
|
|
void *vp;
|
|
|
|
{
|
|
|
|
vm_offset_t pgva;
|
|
|
|
int s;
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
pgva = m68k_trunc_page(vp);
|
|
|
|
if (pgva != tmp_vpages[1])
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = splimp();
|
1997-10-16 20:13:21 +04:00
|
|
|
pmap_remove(pmap_kernel(), pgva, pgva + NBPG);
|
1997-05-30 11:02:14 +04:00
|
|
|
--tmp_vpages_inuse;
|
1997-05-28 08:27:00 +04:00
|
|
|
splx(s);
|
1997-02-18 17:58:32 +03:00
|
|
|
}
|
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
/*
|
|
|
|
* Make a permanent mapping for a device.
|
|
|
|
*/
|
1997-02-18 17:58:32 +03:00
|
|
|
void *
|
1997-10-16 20:13:21 +04:00
|
|
|
bus_mapin(bustype, pa, sz)
|
|
|
|
int bustype, pa, sz;
|
1997-02-18 17:58:32 +03:00
|
|
|
{
|
1998-02-05 07:56:24 +03:00
|
|
|
vm_offset_t va;
|
1997-10-16 20:13:21 +04:00
|
|
|
int off;
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
if ((bustype < 0) || (bustype >= BUS__NTYPES))
|
1997-10-16 20:13:21 +04:00
|
|
|
panic("bus_mapin: bustype");
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
off = pa & PGOFSET;
|
|
|
|
pa -= off;
|
|
|
|
sz += off;
|
|
|
|
sz = m68k_round_page(sz);
|
|
|
|
|
1998-02-05 07:56:24 +03:00
|
|
|
/* Borrow PROM mappings if we can. */
|
|
|
|
if (bustype == BUS_OBIO) {
|
1998-02-08 08:02:50 +03:00
|
|
|
va = (vm_offset_t) obio_find_mapping(pa, sz);
|
|
|
|
if (va != 0)
|
|
|
|
goto done;
|
1998-02-05 07:56:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pa &= bus_info[bustype].mask;
|
|
|
|
pa |= bus_info[bustype].base;
|
1997-10-16 20:13:21 +04:00
|
|
|
pa |= PMAP_NC; /* non-cached */
|
1997-02-18 17:58:32 +03:00
|
|
|
|
|
|
|
/* Get some kernel virtual address space. */
|
|
|
|
va = kmem_alloc_wait(kernel_map, sz);
|
|
|
|
if (va == 0)
|
|
|
|
panic("bus_mapin");
|
|
|
|
|
|
|
|
/* Map it to the specified bus. */
|
1998-02-08 08:02:50 +03:00
|
|
|
pmap_map(va, pa, pa + sz, VM_PROT_ALL);
|
1998-02-05 07:56:24 +03:00
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
done:
|
|
|
|
return ((void*)(va + off));
|
1997-02-22 22:27:18 +03:00
|
|
|
}
|
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
void
|
|
|
|
bus_mapout(ptr, sz)
|
|
|
|
void *ptr;
|
|
|
|
int sz;
|
1997-02-18 17:58:32 +03:00
|
|
|
{
|
1998-02-08 08:02:50 +03:00
|
|
|
vm_offset_t va;
|
|
|
|
int off;
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
va = (vm_offset_t)ptr;
|
1998-02-05 07:56:24 +03:00
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
/* If it was a PROM mapping, do NOT free it! */
|
|
|
|
if ((va >= SUN3X_MONSTART) && (va < SUN3X_MONEND))
|
|
|
|
return;
|
1997-02-18 17:58:32 +03:00
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
off = va & PGOFSET;
|
|
|
|
va -= off;
|
|
|
|
sz += off;
|
|
|
|
sz = m68k_round_page(sz);
|
1998-02-05 07:56:24 +03:00
|
|
|
|
1998-02-08 08:02:50 +03:00
|
|
|
kmem_free_wakeup(kernel_map, va, sz);
|
1997-02-18 17:58:32 +03:00
|
|
|
}
|