2001-10-17 22:43:04 +04:00
|
|
|
/* $NetBSD: iommu.c,v 1.44 2001/10/17 18:43:04 thorpej Exp $ */
|
2000-04-22 21:05:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1999, 2000 Matthew R. Green
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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-06-04 17:48:48 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* 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 University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
* from: NetBSD: sbus.c,v 1.13 1999/05/23 07:24:02 mrg Exp
|
|
|
|
* from: @(#)sbus.c 8.1 (Berkeley) 6/11/93
|
|
|
|
*/
|
|
|
|
|
2000-04-22 21:05:59 +04:00
|
|
|
/*
|
|
|
|
* UltraSPARC IOMMU support; used by both the sbus and pci code.
|
|
|
|
*/
|
2000-04-05 09:59:03 +04:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
1999-06-04 17:48:48 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/extent.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
2001-09-28 15:59:51 +04:00
|
|
|
#include <sys/proc.h>
|
2000-06-26 18:20:25 +04:00
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
1999-06-04 17:48:48 +04:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2000-04-22 21:05:59 +04:00
|
|
|
#include <sparc64/sparc64/cache.h>
|
1999-06-04 17:48:48 +04:00
|
|
|
#include <sparc64/dev/iommureg.h>
|
|
|
|
#include <sparc64/dev/iommuvar.h>
|
|
|
|
|
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-07-07 17:10:34 +04:00
|
|
|
#define IDB_BUSDMA 0x1
|
|
|
|
#define IDB_IOMMU 0x2
|
|
|
|
#define IDB_INFO 0x4
|
2001-07-20 04:07:12 +04:00
|
|
|
#define IDB_SYNC 0x8
|
2000-05-17 13:53:53 +04:00
|
|
|
int iommudebug = 0x0;
|
2000-04-05 09:59:03 +04:00
|
|
|
#define DPRINTF(l, s) do { if (iommudebug & l) printf s; } while (0)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(l, s)
|
1999-06-04 17:48:48 +04:00
|
|
|
#endif
|
|
|
|
|
2001-10-08 00:30:40 +04:00
|
|
|
#define iommu_strbuf_flush(i,v) do { \
|
|
|
|
if ((i)->is_sb[0]) \
|
|
|
|
bus_space_write_8((i)->is_bustag, \
|
|
|
|
(bus_space_handle_t)(u_long) \
|
|
|
|
&(i)->is_sb[0]->strbuf_pgflush, \
|
|
|
|
0, (v)); \
|
|
|
|
if ((i)->is_sb[1]) \
|
|
|
|
bus_space_write_8((i)->is_bustag, \
|
|
|
|
(bus_space_handle_t)(u_long) \
|
|
|
|
&(i)->is_sb[1]->strbuf_pgflush, \
|
|
|
|
0, (v)); \
|
|
|
|
} while (0)
|
|
|
|
|
2001-02-24 21:49:06 +03:00
|
|
|
static int iommu_strbuf_flush_done __P((struct iommu_state *));
|
2000-06-08 20:17:29 +04:00
|
|
|
|
1999-06-04 17:48:48 +04:00
|
|
|
/*
|
|
|
|
* initialise the UltraSPARC IOMMU (SBUS or PCI):
|
|
|
|
* - allocate and setup the iotsb.
|
|
|
|
* - enable the IOMMU
|
2000-04-22 21:05:59 +04:00
|
|
|
* - initialise the streaming buffers (if they exist)
|
1999-06-04 17:48:48 +04:00
|
|
|
* - create a private DVMA map.
|
|
|
|
*/
|
|
|
|
void
|
2001-07-20 04:07:12 +04:00
|
|
|
iommu_init(name, is, tsbsize, iovabase)
|
1999-06-04 17:48:48 +04:00
|
|
|
char *name;
|
|
|
|
struct iommu_state *is;
|
|
|
|
int tsbsize;
|
2001-07-20 04:07:12 +04:00
|
|
|
u_int32_t iovabase;
|
1999-06-04 17:48:48 +04:00
|
|
|
{
|
2000-06-08 20:17:29 +04:00
|
|
|
psize_t size;
|
|
|
|
vaddr_t va;
|
|
|
|
paddr_t pa;
|
2001-05-27 01:27:10 +04:00
|
|
|
struct vm_page *m;
|
2000-06-08 20:17:29 +04:00
|
|
|
struct pglist mlist;
|
1999-06-04 17:48:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the iommu.
|
|
|
|
*
|
2000-04-22 21:05:59 +04:00
|
|
|
* The sun4u iommu is part of the SBUS or PCI controller so we
|
|
|
|
* will deal with it here..
|
1999-06-20 04:51:29 +04:00
|
|
|
*
|
|
|
|
* The IOMMU address space always ends at 0xffffe000, but the starting
|
|
|
|
* address depends on the size of the map. The map size is 1024 * 2 ^
|
|
|
|
* is->is_tsbsize entries, where each entry is 8 bytes. The start of
|
|
|
|
* the map can be calculated by (0xffffe000 << (8 + is->is_tsbsize)).
|
|
|
|
*/
|
2000-06-08 20:17:29 +04:00
|
|
|
is->is_cr = (tsbsize << 16) | IOMMUCR_EN;
|
1999-06-04 17:48:48 +04:00
|
|
|
is->is_tsbsize = tsbsize;
|
2001-07-20 04:07:12 +04:00
|
|
|
is->is_dvmabase = iovabase;
|
|
|
|
if (iovabase == -1) is->is_dvmabase = IOTSB_VSTART(is->is_tsbsize);
|
2000-06-08 20:17:29 +04:00
|
|
|
|
|
|
|
/*
|
2000-06-20 03:30:32 +04:00
|
|
|
* Allocate memory for I/O pagetables. They need to be physically
|
|
|
|
* contiguous.
|
2000-06-08 20:17:29 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
size = NBPG<<(is->is_tsbsize);
|
|
|
|
TAILQ_INIT(&mlist);
|
|
|
|
if (uvm_pglistalloc((psize_t)size, (paddr_t)0, (paddr_t)-1,
|
|
|
|
(paddr_t)NBPG, (paddr_t)0, &mlist, 1, 0) != 0)
|
|
|
|
panic("iommu_init: no memory");
|
|
|
|
|
|
|
|
va = uvm_km_valloc(kernel_map, size);
|
|
|
|
if (va == 0)
|
|
|
|
panic("iommu_init: no memory");
|
|
|
|
is->is_tsb = (int64_t *)va;
|
|
|
|
|
|
|
|
m = TAILQ_FIRST(&mlist);
|
|
|
|
is->is_ptsb = VM_PAGE_TO_PHYS(m);
|
|
|
|
|
|
|
|
/* Map the pages */
|
|
|
|
for (; m != NULL; m = TAILQ_NEXT(m,pageq)) {
|
|
|
|
pa = VM_PAGE_TO_PHYS(m);
|
|
|
|
pmap_enter(pmap_kernel(), va, pa | PMAP_NVC,
|
|
|
|
VM_PROT_READ|VM_PROT_WRITE,
|
|
|
|
VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
|
|
|
|
va += NBPG;
|
|
|
|
}
|
2001-09-11 01:19:08 +04:00
|
|
|
pmap_update(pmap_kernel());
|
2000-06-08 20:17:29 +04:00
|
|
|
bzero(is->is_tsb, size);
|
1999-06-04 17:48:48 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-07-07 17:10:34 +04:00
|
|
|
if (iommudebug & IDB_INFO)
|
1999-06-04 17:48:48 +04:00
|
|
|
{
|
|
|
|
/* Probe the iommu */
|
|
|
|
struct iommureg *regs = is->is_iommu;
|
|
|
|
|
2000-12-06 04:47:49 +03:00
|
|
|
printf("iommu regs at: cr=%lx tsb=%lx flush=%lx\n",
|
|
|
|
(u_long)®s->iommu_cr,
|
|
|
|
(u_long)®s->iommu_tsb,
|
|
|
|
(u_long)®s->iommu_flush);
|
|
|
|
printf("iommu cr=%llx tsb=%llx\n", (unsigned long long)regs->iommu_cr, (unsigned long long)regs->iommu_tsb);
|
|
|
|
printf("TSB base %p phys %llx\n", (void *)is->is_tsb, (unsigned long long)is->is_ptsb);
|
1999-06-04 17:48:48 +04:00
|
|
|
delay(1000000); /* 1 s */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2000-04-25 18:59:38 +04:00
|
|
|
* Initialize streaming buffer, if it is there.
|
1999-06-04 17:48:48 +04:00
|
|
|
*/
|
2001-10-08 00:30:40 +04:00
|
|
|
if (is->is_sb[0] || is->is_sb[1])
|
|
|
|
(void)pmap_extract(pmap_kernel(), (vaddr_t)&is->is_flush[0],
|
2000-04-25 18:59:38 +04:00
|
|
|
(paddr_t *)&is->is_flushpa);
|
1999-06-04 17:48:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now actually start up the IOMMU
|
|
|
|
*/
|
|
|
|
iommu_reset(is);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now all the hardware's working we need to allocate a dvma map.
|
|
|
|
*/
|
2000-06-08 20:17:29 +04:00
|
|
|
printf("DVMA map: %x to %x\n",
|
|
|
|
(unsigned int)is->is_dvmabase,
|
2001-07-20 04:07:12 +04:00
|
|
|
(unsigned int)(is->is_dvmabase+(size<<10)));
|
1999-06-04 17:48:48 +04:00
|
|
|
is->is_dvmamap = extent_create(name,
|
2000-07-07 06:50:19 +04:00
|
|
|
is->is_dvmabase, (u_long)IOTSB_VEND,
|
1999-06-04 17:48:48 +04:00
|
|
|
M_DEVBUF, 0, 0, EX_NOWAIT);
|
|
|
|
}
|
|
|
|
|
2000-04-25 18:59:38 +04:00
|
|
|
/*
|
|
|
|
* Streaming buffers don't exist on the UltraSPARC IIi; we should have
|
|
|
|
* detected that already and disabled them. If not, we will notice that
|
|
|
|
* they aren't there when the STRBUF_EN bit does not remain.
|
|
|
|
*/
|
1999-06-04 17:48:48 +04:00
|
|
|
void
|
|
|
|
iommu_reset(is)
|
|
|
|
struct iommu_state *is;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Need to do 64-bit stores */
|
2000-07-07 06:50:19 +04:00
|
|
|
bus_space_write_8(is->is_bustag,
|
2001-10-08 00:30:40 +04:00
|
|
|
(bus_space_handle_t)(u_long)&is->is_iommu->iommu_tsb,
|
|
|
|
0, is->is_ptsb);
|
2000-06-08 20:17:29 +04:00
|
|
|
/* Enable IOMMU in diagnostic mode */
|
2000-07-07 06:50:19 +04:00
|
|
|
bus_space_write_8(is->is_bustag,
|
2001-10-08 00:30:40 +04:00
|
|
|
(bus_space_handle_t)(u_long)&is->is_iommu->iommu_cr,
|
|
|
|
0, is->is_cr|IOMMUCR_DE);
|
2000-06-08 20:17:29 +04:00
|
|
|
|
2001-10-08 00:30:40 +04:00
|
|
|
if (is->is_sb[0]) {
|
2000-04-05 18:26:51 +04:00
|
|
|
|
2001-10-08 00:30:40 +04:00
|
|
|
/* Enable diagnostics mode? */
|
|
|
|
bus_space_write_8(is->is_bustag,
|
|
|
|
(bus_space_handle_t)(u_long)&is->is_sb[0]->strbuf_ctl,
|
|
|
|
0, STRBUF_EN);
|
2000-04-22 21:05:59 +04:00
|
|
|
|
2001-10-08 00:30:40 +04:00
|
|
|
/* No streaming buffers? Disable them */
|
|
|
|
if (bus_space_read_8(is->is_bustag,
|
|
|
|
(bus_space_handle_t)(u_long)&is->is_sb[0]->strbuf_ctl,
|
|
|
|
0) == 0)
|
|
|
|
is->is_sb[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is->is_sb[1]) {
|
|
|
|
|
|
|
|
/* Enable diagnostics mode? */
|
|
|
|
bus_space_write_8(is->is_bustag,
|
|
|
|
(bus_space_handle_t)(u_long)&is->is_sb[1]->strbuf_ctl,
|
|
|
|
0, STRBUF_EN);
|
|
|
|
|
|
|
|
/* No streaming buffers? Disable them */
|
|
|
|
if (bus_space_read_8(is->is_bustag,
|
|
|
|
(bus_space_handle_t)(u_long)&is->is_sb[1]->strbuf_ctl,
|
|
|
|
0) == 0)
|
|
|
|
is->is_sb[1] = 0;
|
|
|
|
}
|
1999-06-04 17:48:48 +04:00
|
|
|
}
|
1999-06-20 04:51:29 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here are the iommu control routines.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
iommu_enter(is, va, pa, flags)
|
|
|
|
struct iommu_state *is;
|
|
|
|
vaddr_t va;
|
|
|
|
int64_t pa;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
int64_t tte;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (va < is->is_dvmabase)
|
2000-06-18 11:05:09 +04:00
|
|
|
panic("iommu_enter: va %#lx not in DVMA space", va);
|
1999-06-20 04:51:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
tte = MAKEIOTTE(pa, !(flags&BUS_DMA_NOWRITE), !(flags&BUS_DMA_NOCACHE),
|
2001-03-09 23:05:39 +03:00
|
|
|
(flags&BUS_DMA_STREAMING));
|
1999-06-20 04:51:29 +04:00
|
|
|
|
|
|
|
/* Is the streamcache flush really needed? */
|
2001-10-08 00:30:40 +04:00
|
|
|
if (is->is_sb[0] || is->is_sb[1]) {
|
2001-02-24 21:49:06 +03:00
|
|
|
iommu_strbuf_flush(is, va);
|
|
|
|
iommu_strbuf_flush_done(is);
|
2000-04-05 18:26:51 +04:00
|
|
|
}
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_IOMMU, ("Clearing TSB slot %d for va %p\n",
|
2000-12-06 04:47:49 +03:00
|
|
|
(int)IOTSBSLOT(va,is->is_tsbsize), (void *)(u_long)va));
|
1999-06-20 04:51:29 +04:00
|
|
|
is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)] = tte;
|
2000-07-07 06:50:19 +04:00
|
|
|
bus_space_write_8(is->is_bustag, (bus_space_handle_t)(u_long)
|
|
|
|
&is->is_iommu->iommu_flush, 0, va);
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_IOMMU, ("iommu_enter: va %lx pa %lx TSB[%lx]@%p=%lx\n",
|
2000-12-06 04:47:49 +03:00
|
|
|
va, (long)pa, (u_long)IOTSBSLOT(va,is->is_tsbsize),
|
|
|
|
(void *)(u_long)&is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)],
|
|
|
|
(u_long)tte));
|
1999-06-20 04:51:29 +04:00
|
|
|
}
|
|
|
|
|
2001-09-15 10:55:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the value of a DVMA address (debug routine).
|
|
|
|
*/
|
|
|
|
paddr_t
|
|
|
|
iommu_extract(is, dva)
|
|
|
|
struct iommu_state *is;
|
|
|
|
vaddr_t dva;
|
|
|
|
{
|
|
|
|
int64_t tte = 0;
|
|
|
|
|
|
|
|
if (dva >= is->is_dvmabase)
|
|
|
|
tte = is->is_tsb[IOTSBSLOT(dva,is->is_tsbsize)];
|
|
|
|
|
|
|
|
if ((tte&IOTTE_V) == 0)
|
|
|
|
return ((paddr_t)-1L);
|
|
|
|
return (tte&IOTTE_PAMASK);
|
|
|
|
}
|
|
|
|
|
1999-06-20 04:51:29 +04:00
|
|
|
/*
|
|
|
|
* iommu_remove: removes mappings created by iommu_enter
|
|
|
|
*
|
|
|
|
* Only demap from IOMMU if flag is set.
|
2000-04-25 18:59:38 +04:00
|
|
|
*
|
|
|
|
* XXX: this function needs better internal error checking.
|
1999-06-20 04:51:29 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
iommu_remove(is, va, len)
|
|
|
|
struct iommu_state *is;
|
|
|
|
vaddr_t va;
|
|
|
|
size_t len;
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (va < is->is_dvmabase)
|
2000-12-06 04:47:49 +03:00
|
|
|
panic("iommu_remove: va 0x%lx not in DVMA space", (u_long)va);
|
1999-06-20 04:51:29 +04:00
|
|
|
if ((long)(va + len) < (long)va)
|
2000-04-05 09:59:03 +04:00
|
|
|
panic("iommu_remove: va 0x%lx + len 0x%lx wraps",
|
1999-06-20 04:51:29 +04:00
|
|
|
(long) va, (long) len);
|
|
|
|
if (len & ~0xfffffff)
|
2000-12-06 04:47:49 +03:00
|
|
|
panic("iommu_remove: rediculous len 0x%lx", (u_long)len);
|
1999-06-20 04:51:29 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
va = trunc_page(va);
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_IOMMU, ("iommu_remove: va %lx TSB[%lx]@%p\n",
|
2000-12-06 04:47:49 +03:00
|
|
|
va, (u_long)IOTSBSLOT(va,is->is_tsbsize),
|
2000-04-25 18:59:38 +04:00
|
|
|
&is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)]));
|
1999-06-20 04:51:29 +04:00
|
|
|
while (len > 0) {
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_IOMMU, ("iommu_remove: clearing TSB slot %d for va %p size %lx\n",
|
2000-12-06 04:47:49 +03:00
|
|
|
(int)IOTSBSLOT(va,is->is_tsbsize), (void *)(u_long)va, (u_long)len));
|
2001-10-08 00:30:40 +04:00
|
|
|
if (is->is_sb[0] || is->is_sb[0]) {
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_IOMMU, ("iommu_remove: flushing va %p TSB[%lx]@%p=%lx, %lu bytes left\n",
|
2000-12-06 04:47:49 +03:00
|
|
|
(void *)(u_long)va, (long)IOTSBSLOT(va,is->is_tsbsize),
|
|
|
|
(void *)(u_long)&is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)],
|
1999-06-20 04:51:29 +04:00
|
|
|
(long)(is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)]),
|
2000-04-05 09:59:03 +04:00
|
|
|
(u_long)len));
|
2001-02-24 21:49:06 +03:00
|
|
|
iommu_strbuf_flush(is, va);
|
2000-05-17 13:53:53 +04:00
|
|
|
if (len <= NBPG)
|
2001-02-24 21:49:06 +03:00
|
|
|
iommu_strbuf_flush_done(is);
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_IOMMU, ("iommu_remove: flushed va %p TSB[%lx]@%p=%lx, %lu bytes left\n",
|
2000-12-06 04:47:49 +03:00
|
|
|
(void *)(u_long)va, (long)IOTSBSLOT(va,is->is_tsbsize),
|
|
|
|
(void *)(u_long)&is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)],
|
1999-06-20 04:51:29 +04:00
|
|
|
(long)(is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)]),
|
2000-04-05 09:59:03 +04:00
|
|
|
(u_long)len));
|
2001-07-20 04:07:12 +04:00
|
|
|
}
|
2000-05-17 13:53:53 +04:00
|
|
|
|
|
|
|
if (len <= NBPG)
|
|
|
|
len = 0;
|
|
|
|
else
|
|
|
|
len -= NBPG;
|
2000-04-25 18:59:38 +04:00
|
|
|
|
1999-06-20 04:51:29 +04:00
|
|
|
is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)] = 0;
|
2000-07-07 06:50:19 +04:00
|
|
|
bus_space_write_8(is->is_bustag, (bus_space_handle_t)(u_long)
|
|
|
|
&is->is_iommu->iommu_flush, 0, va);
|
1999-06-20 04:51:29 +04:00
|
|
|
va += NBPG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-18 11:17:40 +04:00
|
|
|
static int
|
2001-02-24 21:49:06 +03:00
|
|
|
iommu_strbuf_flush_done(is)
|
1999-06-20 04:51:29 +04:00
|
|
|
struct iommu_state *is;
|
|
|
|
{
|
|
|
|
struct timeval cur, flushtimeout;
|
|
|
|
|
|
|
|
#define BUMPTIME(t, usec) { \
|
|
|
|
register volatile struct timeval *tp = (t); \
|
|
|
|
register long us; \
|
|
|
|
\
|
|
|
|
tp->tv_usec = us = tp->tv_usec + (usec); \
|
|
|
|
if (us >= 1000000) { \
|
|
|
|
tp->tv_usec = us - 1000000; \
|
|
|
|
tp->tv_sec++; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2001-10-08 00:30:40 +04:00
|
|
|
if (!is->is_sb[0] && !is->is_sb[1])
|
2000-04-05 18:26:51 +04:00
|
|
|
return (0);
|
2000-04-22 21:05:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Streaming buffer flushes:
|
|
|
|
*
|
|
|
|
* 1 Tell strbuf to flush by storing va to strbuf_pgflush. If
|
|
|
|
* we're not on a cache line boundary (64-bits):
|
|
|
|
* 2 Store 0 in flag
|
|
|
|
* 3 Store pointer to flag in flushsync
|
|
|
|
* 4 wait till flushsync becomes 0x1
|
|
|
|
*
|
|
|
|
* If it takes more than .5 sec, something
|
|
|
|
* went wrong.
|
|
|
|
*/
|
2000-04-05 18:26:51 +04:00
|
|
|
|
2001-10-08 00:30:40 +04:00
|
|
|
is->is_flush[0] = 1;
|
|
|
|
is->is_flush[1] = 1;
|
|
|
|
if (is->is_sb[0]) {
|
|
|
|
is->is_flush[0] = 0;
|
|
|
|
bus_space_write_8(is->is_bustag, (bus_space_handle_t)(u_long)
|
|
|
|
&is->is_sb[0]->strbuf_flushsync, 0, is->is_flushpa);
|
|
|
|
}
|
|
|
|
if (is->is_sb[1]) {
|
|
|
|
is->is_flush[0] = 1;
|
|
|
|
bus_space_write_8(is->is_bustag, (bus_space_handle_t)(u_long)
|
|
|
|
&is->is_sb[1]->strbuf_flushsync, 0, is->is_flushpa + 8);
|
|
|
|
}
|
1999-06-20 04:51:29 +04:00
|
|
|
|
|
|
|
microtime(&flushtimeout);
|
|
|
|
cur = flushtimeout;
|
|
|
|
BUMPTIME(&flushtimeout, 500000); /* 1/2 sec */
|
|
|
|
|
2001-10-08 00:30:40 +04:00
|
|
|
DPRINTF(IDB_IOMMU, ("iommu_strbuf_flush_done: flush = %lx,%lx "
|
|
|
|
"at va = %lx pa = %lx now=%lx:%lx until = %lx:%lx\n",
|
|
|
|
(long)is->is_flush[0], (long)is->is_flush[1],
|
|
|
|
(long)&is->is_flush[0], (long)is->is_flushpa,
|
|
|
|
cur.tv_sec, cur.tv_usec,
|
|
|
|
flushtimeout.tv_sec, flushtimeout.tv_usec));
|
|
|
|
|
1999-06-20 04:51:29 +04:00
|
|
|
/* Bypass non-coherent D$ */
|
2001-10-08 00:30:40 +04:00
|
|
|
while ((!ldxa(is->is_flushpa, ASI_PHYS_CACHED) ||
|
|
|
|
!ldxa(is->is_flushpa + 8, ASI_PHYS_CACHED)) &&
|
|
|
|
((cur.tv_sec <= flushtimeout.tv_sec) &&
|
|
|
|
(cur.tv_usec <= flushtimeout.tv_usec)))
|
1999-06-20 04:51:29 +04:00
|
|
|
microtime(&cur);
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
2001-10-17 22:43:04 +04:00
|
|
|
if (!ldxa(is->is_flushpa, ASI_PHYS_CACHED) ||
|
|
|
|
!ldxa(is->is_flushpa + 8, ASI_PHYS_CACHED)) {
|
2001-10-08 00:30:40 +04:00
|
|
|
printf("iommu_strbuf_flush_done: flush timeout %p,%p at %p\n",
|
|
|
|
(void *)(u_long)is->is_flush[0],
|
|
|
|
(void *)(u_long)is->is_flush[1],
|
|
|
|
(void *)(u_long)is->is_flushpa); /* panic? */
|
1999-06-20 04:51:29 +04:00
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2001-02-24 21:49:06 +03:00
|
|
|
DPRINTF(IDB_IOMMU, ("iommu_strbuf_flush_done: flushed\n"));
|
2001-10-08 00:30:40 +04:00
|
|
|
return (is->is_flush[0] && is->is_flush[1]);
|
1999-06-20 04:51:29 +04:00
|
|
|
}
|
2000-04-22 21:05:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IOMMU DVMA operations, common to SBUS and PCI.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iommu_dvmamap_load(t, is, map, buf, buflen, p, flags)
|
|
|
|
bus_dma_tag_t t;
|
|
|
|
struct iommu_state *is;
|
|
|
|
bus_dmamap_t map;
|
|
|
|
void *buf;
|
|
|
|
bus_size_t buflen;
|
|
|
|
struct proc *p;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
int err;
|
|
|
|
bus_size_t sgsize;
|
|
|
|
paddr_t curaddr;
|
2001-09-21 07:04:09 +04:00
|
|
|
u_long dvmaddr, sgstart, sgend;
|
2000-07-07 06:50:19 +04:00
|
|
|
bus_size_t align, boundary;
|
2000-04-22 21:05:59 +04:00
|
|
|
vaddr_t vaddr = (vaddr_t)buf;
|
2001-09-21 07:04:09 +04:00
|
|
|
int seg;
|
2000-04-22 21:05:59 +04:00
|
|
|
pmap_t pmap;
|
|
|
|
|
|
|
|
if (map->dm_nsegs) {
|
|
|
|
/* Already in use?? */
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("iommu_dvmamap_load: map still in use\n");
|
|
|
|
#endif
|
|
|
|
bus_dmamap_unload(t, map);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Make sure that on error condition we return "no valid mappings".
|
|
|
|
*/
|
|
|
|
map->dm_nsegs = 0;
|
|
|
|
|
|
|
|
if (buflen > map->_dm_size) {
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_BUSDMA,
|
2000-04-22 21:05:59 +04:00
|
|
|
("iommu_dvmamap_load(): error %d > %d -- "
|
2000-12-06 04:47:49 +03:00
|
|
|
"map size exceeded!\n", (int)buflen, (int)map->_dm_size));
|
2000-04-22 21:05:59 +04:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
sgsize = round_page(buflen + ((int)vaddr & PGOFSET));
|
2000-07-02 18:00:38 +04:00
|
|
|
|
2000-04-22 21:05:59 +04:00
|
|
|
/*
|
2000-07-07 06:50:19 +04:00
|
|
|
* A boundary presented to bus_dmamem_alloc() takes precedence
|
|
|
|
* over boundary in the map.
|
2000-04-22 21:05:59 +04:00
|
|
|
*/
|
2000-07-07 06:50:19 +04:00
|
|
|
if ((boundary = (map->dm_segs[0]._ds_boundary)) == 0)
|
|
|
|
boundary = map->_dm_boundary;
|
|
|
|
align = max(map->dm_segs[0]._ds_align, NBPG);
|
2000-04-22 21:05:59 +04:00
|
|
|
s = splhigh();
|
2001-09-21 07:04:09 +04:00
|
|
|
/*
|
|
|
|
* If our segment size is larger than the boundary we need to
|
|
|
|
* split the transfer up int little pieces ourselves.
|
|
|
|
*/
|
|
|
|
err = extent_alloc(is->is_dvmamap, sgsize, align,
|
|
|
|
(sgsize > boundary) ? 0 : boundary,
|
|
|
|
EX_NOWAIT|EX_BOUNDZERO, (u_long *)&dvmaddr);
|
2000-04-22 21:05:59 +04:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-06-08 20:17:29 +04:00
|
|
|
if (err || (dvmaddr == (bus_addr_t)-1))
|
2000-04-22 21:05:59 +04:00
|
|
|
{
|
|
|
|
printf("iommu_dvmamap_load(): extent_alloc(%d, %x) failed!\n",
|
2000-12-06 04:47:49 +03:00
|
|
|
(int)sgsize, flags);
|
2001-09-21 07:04:09 +04:00
|
|
|
#ifdef DDB
|
2000-04-22 21:05:59 +04:00
|
|
|
Debugger();
|
2001-09-21 07:04:09 +04:00
|
|
|
#endif
|
2000-04-22 21:05:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
2000-06-08 20:17:29 +04:00
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
|
2000-04-22 21:05:59 +04:00
|
|
|
if (dvmaddr == (bus_addr_t)-1)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
2001-09-21 07:04:09 +04:00
|
|
|
/* Set the active DVMA map */
|
|
|
|
map->_dm_dvmastart = dvmaddr;
|
|
|
|
map->_dm_dvmasize = sgsize;
|
|
|
|
|
2000-04-22 21:05:59 +04:00
|
|
|
/*
|
2001-09-21 07:04:09 +04:00
|
|
|
* Now split the DVMA range into segments, not crossing
|
|
|
|
* the boundary.
|
2000-04-22 21:05:59 +04:00
|
|
|
*/
|
2001-09-21 07:04:09 +04:00
|
|
|
seg = 0;
|
|
|
|
sgstart = dvmaddr + (vaddr & PGOFSET);
|
|
|
|
sgend = sgstart + buflen - 1;
|
|
|
|
map->dm_segs[seg].ds_addr = sgstart;
|
|
|
|
DPRINTF(IDB_INFO, ("iommu_dvmamap_load: boundary %lx boundary-1 %lx "
|
|
|
|
"~(boundary-1) %lx\n", boundary, (boundary-1), ~(boundary-1)));
|
|
|
|
while ((sgstart & ~(boundary - 1)) != (sgend & ~(boundary - 1))) {
|
|
|
|
/* Oops. We crossed a boundary. Split the xfer. */
|
|
|
|
DPRINTF(IDB_INFO, ("iommu_dvmamap_load: "
|
|
|
|
"seg %d start %lx size %lx\n", seg,
|
|
|
|
map->dm_segs[seg].ds_addr, map->dm_segs[seg].ds_len));
|
|
|
|
map->dm_segs[seg].ds_len = sgstart & (boundary - 1);
|
|
|
|
if (++seg > map->_dm_segcnt) {
|
|
|
|
/* Too many segments. Fail the operation. */
|
|
|
|
DPRINTF(IDB_INFO, ("iommu_dvmamap_load: "
|
|
|
|
"too many segments %d\n", seg));
|
|
|
|
s = splhigh();
|
|
|
|
/* How can this fail? And if it does what can we do? */
|
|
|
|
err = extent_free(is->is_dvmamap,
|
|
|
|
dvmaddr, sgsize, EX_NOWAIT);
|
|
|
|
map->_dm_dvmastart = 0;
|
|
|
|
map->_dm_dvmasize = 0;
|
2001-10-08 23:24:20 +04:00
|
|
|
splx(s);
|
2001-09-21 07:04:09 +04:00
|
|
|
return (E2BIG);
|
|
|
|
}
|
|
|
|
sgstart = roundup(sgstart, boundary);
|
|
|
|
map->dm_segs[seg].ds_addr = sgstart;
|
|
|
|
}
|
|
|
|
map->dm_segs[seg].ds_len = sgend - sgstart + 1;
|
|
|
|
DPRINTF(IDB_INFO, ("iommu_dvmamap_load: "
|
|
|
|
"seg %d start %lx size %lx\n", seg,
|
|
|
|
map->dm_segs[seg].ds_addr, map->dm_segs[seg].ds_len));
|
|
|
|
map->dm_nsegs = seg+1;
|
2000-04-22 21:05:59 +04:00
|
|
|
map->dm_mapsize = buflen;
|
|
|
|
|
|
|
|
if (p != NULL)
|
|
|
|
pmap = p->p_vmspace->vm_map.pmap;
|
|
|
|
else
|
|
|
|
pmap = pmap_kernel();
|
|
|
|
|
|
|
|
for (; buflen > 0; ) {
|
|
|
|
/*
|
|
|
|
* Get the physical address for this page.
|
|
|
|
*/
|
|
|
|
if (pmap_extract(pmap, (vaddr_t)vaddr, &curaddr) == FALSE) {
|
|
|
|
bus_dmamap_unload(t, map);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the segment size, and adjust counts.
|
|
|
|
*/
|
|
|
|
sgsize = NBPG - ((u_long)vaddr & PGOFSET);
|
|
|
|
if (buflen < sgsize)
|
|
|
|
sgsize = buflen;
|
|
|
|
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_BUSDMA,
|
2001-07-20 04:07:12 +04:00
|
|
|
("iommu_dvmamap_load: map %p loading va %p "
|
|
|
|
"dva %lx at pa %lx\n",
|
|
|
|
map, (void *)vaddr, (long)dvmaddr,
|
|
|
|
(long)(curaddr&~(NBPG-1))));
|
2000-04-22 21:05:59 +04:00
|
|
|
iommu_enter(is, trunc_page(dvmaddr), trunc_page(curaddr),
|
|
|
|
flags);
|
|
|
|
|
|
|
|
dvmaddr += PAGE_SIZE;
|
|
|
|
vaddr += sgsize;
|
|
|
|
buflen -= sgsize;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
iommu_dvmamap_unload(t, is, map)
|
|
|
|
bus_dma_tag_t t;
|
|
|
|
struct iommu_state *is;
|
|
|
|
bus_dmamap_t map;
|
|
|
|
{
|
2001-09-21 07:04:09 +04:00
|
|
|
int error, s;
|
2000-04-22 21:05:59 +04:00
|
|
|
bus_size_t sgsize;
|
|
|
|
|
2001-09-21 07:04:09 +04:00
|
|
|
/* Flush the iommu */
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!map->_dm_dvmastart) {
|
|
|
|
printf("iommu_dvmamap_unload: No dvmastart is zero\n");
|
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
2001-01-23 23:31:28 +03:00
|
|
|
}
|
2001-09-21 07:04:09 +04:00
|
|
|
#endif
|
|
|
|
iommu_remove(is, map->_dm_dvmastart, map->_dm_dvmasize);
|
|
|
|
|
2000-08-01 04:22:41 +04:00
|
|
|
/* Flush the caches */
|
|
|
|
bus_dmamap_unload(t->_parent, map);
|
|
|
|
|
2000-04-22 21:05:59 +04:00
|
|
|
/* Mark the mappings as invalid. */
|
|
|
|
map->dm_mapsize = 0;
|
|
|
|
map->dm_nsegs = 0;
|
|
|
|
|
|
|
|
s = splhigh();
|
2001-09-21 07:04:09 +04:00
|
|
|
error = extent_free(is->is_dvmamap, map->_dm_dvmastart,
|
|
|
|
map->_dm_dvmasize, EX_NOWAIT);
|
2001-10-08 23:24:20 +04:00
|
|
|
map->_dm_dvmastart = 0;
|
|
|
|
map->_dm_dvmasize = 0;
|
2000-04-22 21:05:59 +04:00
|
|
|
splx(s);
|
|
|
|
if (error != 0)
|
|
|
|
printf("warning: %qd of DVMA space lost\n", (long long)sgsize);
|
2001-09-21 07:04:09 +04:00
|
|
|
|
|
|
|
/* Clear the map */
|
2000-04-22 21:05:59 +04:00
|
|
|
}
|
|
|
|
|
2000-05-17 06:31:12 +04:00
|
|
|
|
|
|
|
int
|
2000-07-07 17:10:34 +04:00
|
|
|
iommu_dvmamap_load_raw(t, is, map, segs, nsegs, flags, size)
|
2000-05-17 06:31:12 +04:00
|
|
|
bus_dma_tag_t t;
|
|
|
|
struct iommu_state *is;
|
|
|
|
bus_dmamap_t map;
|
|
|
|
bus_dma_segment_t *segs;
|
|
|
|
int nsegs;
|
|
|
|
int flags;
|
2000-07-07 17:10:34 +04:00
|
|
|
bus_size_t size;
|
2000-05-17 06:31:12 +04:00
|
|
|
{
|
2001-05-27 01:27:10 +04:00
|
|
|
struct vm_page *m;
|
2001-09-21 07:04:09 +04:00
|
|
|
int i, j, s;
|
2001-01-23 23:31:28 +03:00
|
|
|
int left;
|
2000-05-17 06:31:12 +04:00
|
|
|
int err;
|
|
|
|
bus_size_t sgsize;
|
|
|
|
paddr_t pa;
|
2000-07-07 06:50:19 +04:00
|
|
|
bus_size_t boundary, align;
|
2001-09-21 07:04:09 +04:00
|
|
|
u_long dvmaddr, sgstart, sgend;
|
2000-05-17 06:31:12 +04:00
|
|
|
struct pglist *mlist;
|
|
|
|
int pagesz = PAGE_SIZE;
|
|
|
|
|
|
|
|
if (map->dm_nsegs) {
|
|
|
|
/* Already in use?? */
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("iommu_dvmamap_load_raw: map still in use\n");
|
|
|
|
#endif
|
|
|
|
bus_dmamap_unload(t, map);
|
|
|
|
}
|
2001-09-21 07:04:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A boundary presented to bus_dmamem_alloc() takes precedence
|
|
|
|
* over boundary in the map.
|
|
|
|
*/
|
|
|
|
if ((boundary = segs[0]._ds_boundary) == 0)
|
|
|
|
boundary = map->_dm_boundary;
|
|
|
|
|
|
|
|
align = max(segs[0]._ds_align, NBPG);
|
|
|
|
|
2000-05-17 06:31:12 +04:00
|
|
|
/*
|
|
|
|
* Make sure that on error condition we return "no valid mappings".
|
|
|
|
*/
|
|
|
|
map->dm_nsegs = 0;
|
2001-01-23 23:31:28 +03:00
|
|
|
/* Count up the total number of pages we need */
|
|
|
|
pa = segs[0].ds_addr;
|
|
|
|
sgsize = 0;
|
2001-09-21 07:04:09 +04:00
|
|
|
left = size;
|
|
|
|
for (i=0; left && i<nsegs; i++) {
|
2001-01-23 23:31:28 +03:00
|
|
|
if (round_page(pa) != round_page(segs[i].ds_addr))
|
|
|
|
sgsize = round_page(sgsize);
|
2001-09-21 07:04:09 +04:00
|
|
|
sgsize += min(left, segs[i].ds_len);
|
|
|
|
left -= segs[i].ds_len;
|
2001-01-23 23:31:28 +03:00
|
|
|
pa = segs[i].ds_addr + segs[i].ds_len;
|
|
|
|
}
|
|
|
|
sgsize = round_page(sgsize);
|
2000-05-17 06:31:12 +04:00
|
|
|
|
|
|
|
s = splhigh();
|
2001-09-21 07:04:09 +04:00
|
|
|
/*
|
|
|
|
* If our segment size is larger than the boundary we need to
|
|
|
|
* split the transfer up int little pieces ourselves.
|
|
|
|
*/
|
|
|
|
err = extent_alloc(is->is_dvmamap, sgsize, align,
|
|
|
|
(sgsize > boundary) ? 0 : boundary,
|
|
|
|
((flags & BUS_DMA_NOWAIT) == 0 ? EX_WAITOK : EX_NOWAIT) |
|
|
|
|
EX_BOUNDZERO, (u_long *)&dvmaddr);
|
2000-05-17 06:31:12 +04:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (dvmaddr == (bus_addr_t)-1)
|
|
|
|
{
|
|
|
|
printf("iommu_dvmamap_load_raw(): extent_alloc(%d, %x) failed!\n",
|
2000-12-06 04:47:49 +03:00
|
|
|
(int)sgsize, flags);
|
2000-05-17 06:31:12 +04:00
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (dvmaddr == (bus_addr_t)-1)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
2001-09-21 07:04:09 +04:00
|
|
|
/* Set the active DVMA map */
|
|
|
|
map->_dm_dvmastart = dvmaddr;
|
|
|
|
map->_dm_dvmasize = sgsize;
|
|
|
|
|
2001-01-23 23:31:28 +03:00
|
|
|
if ((mlist = segs[0]._ds_mlist) == NULL) {
|
|
|
|
u_long prev_va = NULL;
|
|
|
|
/*
|
|
|
|
* This segs is made up of individual physical pages,
|
|
|
|
* probably by _bus_dmamap_load_uio() or
|
|
|
|
* _bus_dmamap_load_mbuf(). Ignore the mlist and
|
|
|
|
* load each segment individually.
|
|
|
|
*/
|
2001-09-21 07:04:09 +04:00
|
|
|
map->dm_mapsize = size;
|
2001-01-23 23:31:28 +03:00
|
|
|
|
2001-09-21 07:04:09 +04:00
|
|
|
i = j = 0;
|
2001-01-23 23:31:28 +03:00
|
|
|
pa = segs[i].ds_addr;
|
2001-09-21 07:04:09 +04:00
|
|
|
dvmaddr += (pa & PGOFSET);
|
|
|
|
left = min(size, segs[i].ds_len);
|
|
|
|
|
|
|
|
sgstart = dvmaddr;
|
|
|
|
sgend = sgstart + left - 1;
|
|
|
|
|
|
|
|
map->dm_segs[j].ds_addr = dvmaddr;
|
|
|
|
map->dm_segs[j].ds_len = left;
|
2001-01-23 23:31:28 +03:00
|
|
|
|
2001-09-21 07:04:09 +04:00
|
|
|
/* Set the size (which we will be destroying */
|
|
|
|
map->dm_mapsize = size;
|
|
|
|
|
|
|
|
while (size > 0) {
|
2001-01-23 23:31:28 +03:00
|
|
|
int incr;
|
|
|
|
|
2001-09-21 07:04:09 +04:00
|
|
|
if (left <= 0) {
|
|
|
|
u_long offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the two segs are on different physical
|
|
|
|
* pages move to a new virtual page.
|
|
|
|
*/
|
|
|
|
if (trunc_page(pa) !=
|
|
|
|
trunc_page(segs[++i].ds_addr))
|
|
|
|
dvmaddr += NBPG;
|
|
|
|
|
|
|
|
pa = segs[i].ds_addr;
|
|
|
|
left = min(size, segs[i].ds_len);
|
|
|
|
|
|
|
|
offset = (pa & PGOFSET);
|
|
|
|
if (dvmaddr == trunc_page(dvmaddr) + offset) {
|
|
|
|
/* We can combine segments */
|
|
|
|
map->dm_segs[j].ds_len += left;
|
|
|
|
sgend += left;
|
|
|
|
} else {
|
|
|
|
/* Need a new segment */
|
|
|
|
dvmaddr = trunc_page(dvmaddr) + offset;
|
|
|
|
DPRINTF(IDB_INFO,
|
|
|
|
("iommu_dvmamap_load_raw: "
|
|
|
|
"seg %d start %lx "
|
|
|
|
"size %lx\n", j,
|
|
|
|
map->dm_segs[j].ds_addr,
|
|
|
|
map->dm_segs[j].
|
|
|
|
ds_len));
|
|
|
|
if (++j > map->_dm_segcnt)
|
|
|
|
goto fail;
|
|
|
|
map->dm_segs[j].ds_addr = dvmaddr;
|
|
|
|
map->dm_segs[j].ds_len = left;
|
|
|
|
|
|
|
|
sgstart = dvmaddr;
|
|
|
|
sgend = sgstart + left - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for boundary issues */
|
|
|
|
while ((sgstart & ~(boundary - 1)) !=
|
|
|
|
(sgend & ~(boundary - 1))) {
|
|
|
|
/* Need a new segment. */
|
|
|
|
map->dm_segs[j].ds_len =
|
|
|
|
sgstart & (boundary - 1);
|
|
|
|
DPRINTF(IDB_INFO, ("iommu_dvmamap_load_raw: "
|
|
|
|
"seg %d start %lx size %lx\n", j,
|
|
|
|
map->dm_segs[j].ds_addr,
|
|
|
|
map->dm_segs[j].ds_len));
|
|
|
|
if (++j > map->_dm_segcnt) {
|
|
|
|
fail:
|
|
|
|
iommu_dvmamap_unload(t, is, map);
|
|
|
|
return (E2BIG);
|
|
|
|
}
|
|
|
|
sgstart = roundup(sgstart, boundary);
|
|
|
|
map->dm_segs[j].ds_addr = sgstart;
|
|
|
|
map->dm_segs[j].ds_len = sgend - sgstart + 1;
|
|
|
|
}
|
|
|
|
|
2001-01-23 23:31:28 +03:00
|
|
|
if (sgsize == 0)
|
|
|
|
panic("iommu_dmamap_load_raw: size botch");
|
2001-09-21 07:04:09 +04:00
|
|
|
|
2001-01-23 23:31:28 +03:00
|
|
|
DPRINTF(IDB_BUSDMA,
|
|
|
|
("iommu_dvmamap_load_raw: map %p loading va %lx at pa %lx\n",
|
2001-09-21 07:04:09 +04:00
|
|
|
map, (long)dvmaddr, (long)(pa)));
|
2001-01-23 23:31:28 +03:00
|
|
|
/* Enter it if we haven't before. */
|
|
|
|
if (prev_va != trunc_page(dvmaddr))
|
2001-09-21 07:04:09 +04:00
|
|
|
iommu_enter(is, prev_va = trunc_page(dvmaddr),
|
|
|
|
trunc_page(pa), flags);
|
2001-01-23 23:31:28 +03:00
|
|
|
incr = min(pagesz, left);
|
|
|
|
dvmaddr += incr;
|
|
|
|
pa += incr;
|
|
|
|
left -= incr;
|
2001-09-21 07:04:09 +04:00
|
|
|
size -= incr;
|
2001-01-23 23:31:28 +03:00
|
|
|
}
|
2001-09-21 07:04:09 +04:00
|
|
|
DPRINTF(IDB_INFO, ("iommu_dvmamap_load_raw: "
|
|
|
|
"seg %d start %lx size %lx\n", j,
|
|
|
|
map->dm_segs[j].ds_addr, map->dm_segs[j].ds_len));
|
|
|
|
map->dm_nsegs = j+1;
|
2001-01-23 23:31:28 +03:00
|
|
|
return (0);
|
|
|
|
}
|
2000-05-17 06:31:12 +04:00
|
|
|
/*
|
2001-09-21 07:04:09 +04:00
|
|
|
* This was allocated with bus_dmamem_alloc.
|
|
|
|
* The pages are on an `mlist'.
|
2000-05-17 06:31:12 +04:00
|
|
|
*/
|
|
|
|
map->dm_mapsize = size;
|
2001-01-23 23:31:28 +03:00
|
|
|
i = 0;
|
2001-09-21 07:04:09 +04:00
|
|
|
sgstart = dvmaddr;
|
|
|
|
sgend = sgstart + size - 1;
|
|
|
|
map->dm_segs[i].ds_addr = sgstart;
|
|
|
|
while ((sgstart & ~(boundary - 1)) != (sgend & ~(boundary - 1))) {
|
|
|
|
/* Oops. We crossed a boundary. Split the xfer. */
|
|
|
|
map->dm_segs[i].ds_len = sgstart & (boundary - 1);
|
|
|
|
DPRINTF(IDB_INFO, ("iommu_dvmamap_load_raw: "
|
|
|
|
"seg %d start %lx size %lx\n", i,
|
|
|
|
map->dm_segs[i].ds_addr,
|
|
|
|
map->dm_segs[i].ds_len));
|
|
|
|
if (++i > map->_dm_segcnt) {
|
|
|
|
/* Too many segments. Fail the operation. */
|
|
|
|
s = splhigh();
|
|
|
|
/* How can this fail? And if it does what can we do? */
|
|
|
|
err = extent_free(is->is_dvmamap,
|
|
|
|
dvmaddr, sgsize, EX_NOWAIT);
|
|
|
|
map->_dm_dvmastart = 0;
|
|
|
|
map->_dm_dvmasize = 0;
|
2001-10-08 23:24:20 +04:00
|
|
|
splx(s);
|
2001-09-21 07:04:09 +04:00
|
|
|
return (E2BIG);
|
|
|
|
}
|
|
|
|
sgstart = roundup(sgstart, boundary);
|
|
|
|
map->dm_segs[i].ds_addr = sgstart;
|
|
|
|
}
|
|
|
|
DPRINTF(IDB_INFO, ("iommu_dvmamap_load_raw: "
|
|
|
|
"seg %d start %lx size %lx\n", i,
|
|
|
|
map->dm_segs[i].ds_addr, map->dm_segs[i].ds_len));
|
|
|
|
map->dm_segs[i].ds_len = sgend - sgstart + 1;
|
2000-05-17 06:31:12 +04:00
|
|
|
|
|
|
|
for (m = TAILQ_FIRST(mlist); m != NULL; m = TAILQ_NEXT(m,pageq)) {
|
|
|
|
if (sgsize == 0)
|
|
|
|
panic("iommu_dmamap_load_raw: size botch");
|
|
|
|
pa = VM_PAGE_TO_PHYS(m);
|
|
|
|
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_BUSDMA,
|
2000-05-17 06:31:12 +04:00
|
|
|
("iommu_dvmamap_load_raw: map %p loading va %lx at pa %lx\n",
|
|
|
|
map, (long)dvmaddr, (long)(pa)));
|
|
|
|
iommu_enter(is, dvmaddr, pa, flags);
|
|
|
|
|
|
|
|
dvmaddr += pagesz;
|
|
|
|
sgsize -= pagesz;
|
|
|
|
}
|
2001-09-21 07:04:09 +04:00
|
|
|
map->dm_mapsize = size;
|
|
|
|
map->dm_nsegs = i+1;
|
2000-05-17 06:31:12 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-04-22 21:05:59 +04:00
|
|
|
void
|
|
|
|
iommu_dvmamap_sync(t, is, map, offset, len, ops)
|
|
|
|
bus_dma_tag_t t;
|
|
|
|
struct iommu_state *is;
|
|
|
|
bus_dmamap_t map;
|
|
|
|
bus_addr_t offset;
|
|
|
|
bus_size_t len;
|
|
|
|
int ops;
|
|
|
|
{
|
|
|
|
vaddr_t va = map->dm_segs[0].ds_addr + offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support one DMA segment; supporting more makes this code
|
|
|
|
* too unweildy.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ops & BUS_DMASYNC_PREREAD) {
|
2001-07-20 04:07:12 +04:00
|
|
|
DPRINTF(IDB_SYNC,
|
2000-04-22 21:05:59 +04:00
|
|
|
("iommu_dvmamap_sync: syncing va %p len %lu "
|
2000-12-06 04:47:49 +03:00
|
|
|
"BUS_DMASYNC_PREREAD\n", (void *)(u_long)va, (u_long)len));
|
2000-04-22 21:05:59 +04:00
|
|
|
|
|
|
|
/* Nothing to do */;
|
|
|
|
}
|
|
|
|
if (ops & BUS_DMASYNC_POSTREAD) {
|
2001-07-20 04:07:12 +04:00
|
|
|
DPRINTF(IDB_SYNC,
|
2000-04-22 21:05:59 +04:00
|
|
|
("iommu_dvmamap_sync: syncing va %p len %lu "
|
2000-12-06 04:47:49 +03:00
|
|
|
"BUS_DMASYNC_POSTREAD\n", (void *)(u_long)va, (u_long)len));
|
2000-04-22 21:05:59 +04:00
|
|
|
/* if we have a streaming buffer, flush it here first */
|
2001-10-08 00:30:40 +04:00
|
|
|
if (is->is_sb[0] || is->is_sb[1])
|
2000-04-22 21:05:59 +04:00
|
|
|
while (len > 0) {
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_BUSDMA,
|
2000-04-22 21:05:59 +04:00
|
|
|
("iommu_dvmamap_sync: flushing va %p, %lu "
|
2000-12-06 04:47:49 +03:00
|
|
|
"bytes left\n", (void *)(u_long)va, (u_long)len));
|
2001-02-24 21:49:06 +03:00
|
|
|
iommu_strbuf_flush(is, va);
|
2000-04-22 21:05:59 +04:00
|
|
|
if (len <= NBPG) {
|
2001-02-24 21:49:06 +03:00
|
|
|
iommu_strbuf_flush_done(is);
|
2000-04-22 21:05:59 +04:00
|
|
|
len = 0;
|
|
|
|
} else
|
|
|
|
len -= NBPG;
|
|
|
|
va += NBPG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ops & BUS_DMASYNC_PREWRITE) {
|
2001-07-20 04:07:12 +04:00
|
|
|
DPRINTF(IDB_SYNC,
|
2000-04-22 21:05:59 +04:00
|
|
|
("iommu_dvmamap_sync: syncing va %p len %lu "
|
2000-12-06 04:47:49 +03:00
|
|
|
"BUS_DMASYNC_PREWRITE\n", (void *)(u_long)va, (u_long)len));
|
2001-02-24 21:49:06 +03:00
|
|
|
/* if we have a streaming buffer, flush it here first */
|
2001-10-08 00:30:40 +04:00
|
|
|
if (is->is_sb[0] || is->is_sb[1])
|
2001-02-24 21:49:06 +03:00
|
|
|
while (len > 0) {
|
|
|
|
DPRINTF(IDB_BUSDMA,
|
|
|
|
("iommu_dvmamap_sync: flushing va %p, %lu "
|
|
|
|
"bytes left\n", (void *)(u_long)va, (u_long)len));
|
|
|
|
iommu_strbuf_flush(is, va);
|
|
|
|
if (len <= NBPG) {
|
|
|
|
iommu_strbuf_flush_done(is);
|
|
|
|
len = 0;
|
|
|
|
} else
|
|
|
|
len -= NBPG;
|
|
|
|
va += NBPG;
|
|
|
|
}
|
2000-04-22 21:05:59 +04:00
|
|
|
}
|
|
|
|
if (ops & BUS_DMASYNC_POSTWRITE) {
|
2001-07-20 04:07:12 +04:00
|
|
|
DPRINTF(IDB_SYNC,
|
2000-04-22 21:05:59 +04:00
|
|
|
("iommu_dvmamap_sync: syncing va %p len %lu "
|
2000-12-06 04:47:49 +03:00
|
|
|
"BUS_DMASYNC_POSTWRITE\n", (void *)(u_long)va, (u_long)len));
|
2000-04-22 21:05:59 +04:00
|
|
|
/* Nothing to do */;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
iommu_dvmamem_alloc(t, is, size, alignment, boundary, segs, nsegs, rsegs, flags)
|
|
|
|
bus_dma_tag_t t;
|
|
|
|
struct iommu_state *is;
|
|
|
|
bus_size_t size, alignment, boundary;
|
|
|
|
bus_dma_segment_t *segs;
|
|
|
|
int nsegs;
|
|
|
|
int *rsegs;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
|
2000-12-06 04:47:49 +03:00
|
|
|
DPRINTF(IDB_BUSDMA, ("iommu_dvmamem_alloc: sz %llx align %llx bound %llx "
|
|
|
|
"segp %p flags %d\n", (unsigned long long)size,
|
|
|
|
(unsigned long long)alignment, (unsigned long long)boundary,
|
|
|
|
segs, flags));
|
2000-04-22 21:05:59 +04:00
|
|
|
return (bus_dmamem_alloc(t->_parent, size, alignment, boundary,
|
2000-07-07 06:50:19 +04:00
|
|
|
segs, nsegs, rsegs, flags|BUS_DMA_DVMA));
|
2000-04-22 21:05:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iommu_dvmamem_free(t, is, segs, nsegs)
|
|
|
|
bus_dma_tag_t t;
|
|
|
|
struct iommu_state *is;
|
|
|
|
bus_dma_segment_t *segs;
|
|
|
|
int nsegs;
|
|
|
|
{
|
|
|
|
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_BUSDMA, ("iommu_dvmamem_free: segp %p nsegs %d\n",
|
2000-04-22 21:05:59 +04:00
|
|
|
segs, nsegs));
|
|
|
|
bus_dmamem_free(t->_parent, segs, nsegs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map the DVMA mappings into the kernel pmap.
|
|
|
|
* Check the flags to see whether we're streaming or coherent.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iommu_dvmamem_map(t, is, segs, nsegs, size, kvap, flags)
|
|
|
|
bus_dma_tag_t t;
|
|
|
|
struct iommu_state *is;
|
|
|
|
bus_dma_segment_t *segs;
|
|
|
|
int nsegs;
|
|
|
|
size_t size;
|
|
|
|
caddr_t *kvap;
|
|
|
|
int flags;
|
|
|
|
{
|
2001-05-27 01:27:10 +04:00
|
|
|
struct vm_page *m;
|
2000-04-22 21:05:59 +04:00
|
|
|
vaddr_t va;
|
|
|
|
bus_addr_t addr;
|
|
|
|
struct pglist *mlist;
|
2000-04-25 18:59:38 +04:00
|
|
|
int cbit;
|
2000-04-22 21:05:59 +04:00
|
|
|
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_BUSDMA, ("iommu_dvmamem_map: segp %p nsegs %d size %lx\n",
|
2000-04-22 21:05:59 +04:00
|
|
|
segs, nsegs, size));
|
|
|
|
|
|
|
|
/*
|
2000-04-25 18:59:38 +04:00
|
|
|
* Allocate some space in the kernel map, and then map these pages
|
|
|
|
* into this space.
|
2000-04-22 21:05:59 +04:00
|
|
|
*/
|
2000-04-25 18:59:38 +04:00
|
|
|
size = round_page(size);
|
|
|
|
va = uvm_km_valloc(kernel_map, size);
|
|
|
|
if (va == 0)
|
|
|
|
return (ENOMEM);
|
2000-04-22 21:05:59 +04:00
|
|
|
|
2000-04-25 18:59:38 +04:00
|
|
|
*kvap = (caddr_t)va;
|
2000-04-22 21:05:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* digest flags:
|
|
|
|
*/
|
|
|
|
cbit = 0;
|
|
|
|
if (flags & BUS_DMA_COHERENT) /* Disable vcache */
|
|
|
|
cbit |= PMAP_NVC;
|
|
|
|
if (flags & BUS_DMA_NOCACHE) /* sideffects */
|
|
|
|
cbit |= PMAP_NC;
|
|
|
|
|
|
|
|
/*
|
2000-04-25 18:59:38 +04:00
|
|
|
* Now take this and map it into the CPU.
|
2000-04-22 21:05:59 +04:00
|
|
|
*/
|
|
|
|
mlist = segs[0]._ds_mlist;
|
|
|
|
for (m = mlist->tqh_first; m != NULL; m = m->pageq.tqe_next) {
|
2000-04-25 18:59:38 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2000-04-22 21:05:59 +04:00
|
|
|
if (size == 0)
|
|
|
|
panic("iommu_dvmamem_map: size botch");
|
2000-04-25 18:59:38 +04:00
|
|
|
#endif
|
2000-04-22 21:05:59 +04:00
|
|
|
addr = VM_PAGE_TO_PHYS(m);
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_BUSDMA, ("iommu_dvmamem_map: "
|
2000-12-06 04:47:49 +03:00
|
|
|
"mapping va %lx at %llx\n", va, (unsigned long long)addr | cbit));
|
2000-04-22 21:05:59 +04:00
|
|
|
pmap_enter(pmap_kernel(), va, addr | cbit,
|
2000-09-28 19:28:43 +04:00
|
|
|
VM_PROT_READ | VM_PROT_WRITE,
|
|
|
|
VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
|
2000-04-22 21:05:59 +04:00
|
|
|
va += PAGE_SIZE;
|
|
|
|
size -= PAGE_SIZE;
|
|
|
|
}
|
2001-09-11 01:19:08 +04:00
|
|
|
pmap_update(pmap_kernel());
|
2000-04-22 21:05:59 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmap DVMA mappings from kernel
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
iommu_dvmamem_unmap(t, is, kva, size)
|
|
|
|
bus_dma_tag_t t;
|
|
|
|
struct iommu_state *is;
|
|
|
|
caddr_t kva;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
|
2000-07-07 17:10:34 +04:00
|
|
|
DPRINTF(IDB_BUSDMA, ("iommu_dvmamem_unmap: kvm %p size %lx\n",
|
2000-04-22 21:05:59 +04:00
|
|
|
kva, size));
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((u_long)kva & PGOFSET)
|
|
|
|
panic("iommu_dvmamem_unmap");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
size = round_page(size);
|
|
|
|
pmap_remove(pmap_kernel(), (vaddr_t)kva, size);
|
2001-09-11 01:19:08 +04:00
|
|
|
pmap_update(pmap_kernel());
|
2000-04-25 18:59:38 +04:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* XXX ? is this necessary? i think so and i think other
|
|
|
|
* implementations are missing it.
|
|
|
|
*/
|
|
|
|
uvm_km_free(kernel_map, (vaddr_t)kva, size);
|
|
|
|
#endif
|
2000-04-22 21:05:59 +04:00
|
|
|
}
|