xref: /freebsd/sys/kern/subr_devmap.c (revision 5df74441b35f2303ecdc7b79f9d331f5e77a07db)
130b72b68SRuslan Bukin /*-
230b72b68SRuslan Bukin  * Copyright (c) 2013 Ian Lepore <ian@freebsd.org>
330b72b68SRuslan Bukin  * All rights reserved.
430b72b68SRuslan Bukin  *
530b72b68SRuslan Bukin  * Redistribution and use in source and binary forms, with or without
630b72b68SRuslan Bukin  * modification, are permitted provided that the following conditions
730b72b68SRuslan Bukin  * are met:
830b72b68SRuslan Bukin  * 1. Redistributions of source code must retain the above copyright
930b72b68SRuslan Bukin  *    notice, this list of conditions and the following disclaimer.
1030b72b68SRuslan Bukin  * 2. Redistributions in binary form must reproduce the above copyright
1130b72b68SRuslan Bukin  *    notice, this list of conditions and the following disclaimer in the
1230b72b68SRuslan Bukin  *    documentation and/or other materials provided with the distribution.
1330b72b68SRuslan Bukin  *
1430b72b68SRuslan Bukin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1530b72b68SRuslan Bukin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1630b72b68SRuslan Bukin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1730b72b68SRuslan Bukin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1830b72b68SRuslan Bukin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1930b72b68SRuslan Bukin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2030b72b68SRuslan Bukin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2130b72b68SRuslan Bukin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2230b72b68SRuslan Bukin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2330b72b68SRuslan Bukin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2430b72b68SRuslan Bukin  * SUCH DAMAGE.
2530b72b68SRuslan Bukin  */
2630b72b68SRuslan Bukin 
2730b72b68SRuslan Bukin #include <sys/cdefs.h>
2830b72b68SRuslan Bukin /* Routines for mapping device memory. */
2930b72b68SRuslan Bukin 
3030b72b68SRuslan Bukin #include "opt_ddb.h"
3130b72b68SRuslan Bukin 
3230b72b68SRuslan Bukin #include <sys/param.h>
3330b72b68SRuslan Bukin #include <sys/systm.h>
3430b72b68SRuslan Bukin #include <sys/devmap.h>
3530b72b68SRuslan Bukin #include <vm/vm.h>
3630b72b68SRuslan Bukin #include <vm/vm_extern.h>
3730b72b68SRuslan Bukin #include <vm/pmap.h>
3830b72b68SRuslan Bukin #include <machine/vmparam.h>
3930b72b68SRuslan Bukin 
4030b72b68SRuslan Bukin static const struct devmap_entry *devmap_table;
4130b72b68SRuslan Bukin static boolean_t devmap_bootstrap_done = false;
4230b72b68SRuslan Bukin 
4330b72b68SRuslan Bukin /*
4430b72b68SRuslan Bukin  * The allocated-kva (akva) devmap table and metadata.  Platforms can call
4530b72b68SRuslan Bukin  * devmap_add_entry() to add static device mappings to this table using
4630b72b68SRuslan Bukin  * automatically allocated virtual addresses carved out of the top of kva space.
471d954438SKristof Provost  * Allocation begins immediately below the max kernel virtual address.
4830b72b68SRuslan Bukin  */
4930b72b68SRuslan Bukin #define	AKVA_DEVMAP_MAX_ENTRIES	32
5030b72b68SRuslan Bukin static struct devmap_entry	akva_devmap_entries[AKVA_DEVMAP_MAX_ENTRIES];
5130b72b68SRuslan Bukin static u_int			akva_devmap_idx;
5230b72b68SRuslan Bukin static vm_offset_t		akva_devmap_vaddr = DEVMAP_MAX_VADDR;
5330b72b68SRuslan Bukin 
54ca20f8ecSRuslan Bukin #if defined(__aarch64__) || defined(__riscv)
5530b72b68SRuslan Bukin extern int early_boot;
5630b72b68SRuslan Bukin #endif
5730b72b68SRuslan Bukin 
5830b72b68SRuslan Bukin /*
5930b72b68SRuslan Bukin  * Print the contents of the static mapping table using the provided printf-like
6030b72b68SRuslan Bukin  * output function (which will be either printf or db_printf).
6130b72b68SRuslan Bukin  */
6230b72b68SRuslan Bukin static void
devmap_dump_table(int (* prfunc)(const char *,...))6330b72b68SRuslan Bukin devmap_dump_table(int (*prfunc)(const char *, ...))
6430b72b68SRuslan Bukin {
6530b72b68SRuslan Bukin 	const struct devmap_entry *pd;
6630b72b68SRuslan Bukin 
6730b72b68SRuslan Bukin 	if (devmap_table == NULL || devmap_table[0].pd_size == 0) {
6830b72b68SRuslan Bukin 		prfunc("No static device mappings.\n");
6930b72b68SRuslan Bukin 		return;
7030b72b68SRuslan Bukin 	}
7130b72b68SRuslan Bukin 
7230b72b68SRuslan Bukin 	prfunc("Static device mappings:\n");
7330b72b68SRuslan Bukin 	for (pd = devmap_table; pd->pd_size != 0; ++pd) {
741b6dd6d7SPhilip Paeps 		prfunc("  0x%08jx - 0x%08jx mapped at VA 0x%08jx\n",
759976b42bSThomas Skibo 		    (uintmax_t)pd->pd_pa,
769976b42bSThomas Skibo 		    (uintmax_t)(pd->pd_pa + pd->pd_size - 1),
779976b42bSThomas Skibo 		    (uintmax_t)pd->pd_va);
7830b72b68SRuslan Bukin 	}
7930b72b68SRuslan Bukin }
8030b72b68SRuslan Bukin 
8130b72b68SRuslan Bukin /*
8230b72b68SRuslan Bukin  * Print the contents of the static mapping table.  Used for bootverbose.
8330b72b68SRuslan Bukin  */
8430b72b68SRuslan Bukin void
devmap_print_table(void)858e9ca137SAndrew Turner devmap_print_table(void)
8630b72b68SRuslan Bukin {
8730b72b68SRuslan Bukin 	devmap_dump_table(printf);
8830b72b68SRuslan Bukin }
8930b72b68SRuslan Bukin 
9030b72b68SRuslan Bukin /*
9130b72b68SRuslan Bukin  * Return the "last" kva address used by the registered devmap table.  It's
9230b72b68SRuslan Bukin  * actually the lowest address used by the static mappings, i.e., the address of
9330b72b68SRuslan Bukin  * the first unusable byte of KVA.
9430b72b68SRuslan Bukin  */
9530b72b68SRuslan Bukin vm_offset_t
devmap_lastaddr(void)968e9ca137SAndrew Turner devmap_lastaddr(void)
9730b72b68SRuslan Bukin {
9830b72b68SRuslan Bukin 	const struct devmap_entry *pd;
9930b72b68SRuslan Bukin 	vm_offset_t lowaddr;
10030b72b68SRuslan Bukin 
10130b72b68SRuslan Bukin 	if (akva_devmap_idx > 0)
10230b72b68SRuslan Bukin 		return (akva_devmap_vaddr);
10330b72b68SRuslan Bukin 
10430b72b68SRuslan Bukin 	lowaddr = DEVMAP_MAX_VADDR;
10530b72b68SRuslan Bukin 	for (pd = devmap_table; pd != NULL && pd->pd_size != 0; ++pd) {
10630b72b68SRuslan Bukin 		if (lowaddr > pd->pd_va)
10730b72b68SRuslan Bukin 			lowaddr = pd->pd_va;
10830b72b68SRuslan Bukin 	}
10930b72b68SRuslan Bukin 
11030b72b68SRuslan Bukin 	return (lowaddr);
11130b72b68SRuslan Bukin }
11230b72b68SRuslan Bukin 
11330b72b68SRuslan Bukin /*
11430b72b68SRuslan Bukin  * Add an entry to the internal "akva" static devmap table using the given
11530b72b68SRuslan Bukin  * physical address and size and a virtual address allocated from the top of
11630b72b68SRuslan Bukin  * kva.  This automatically registers the akva table on the first call, so all a
11730b72b68SRuslan Bukin  * platform has to do is call this routine to install as many mappings as it
1181d954438SKristof Provost  * needs and when the platform-specific init function calls devmap_bootstrap()
1191d954438SKristof Provost  * it will pick up all the entries in the akva table automatically.
12030b72b68SRuslan Bukin  */
12130b72b68SRuslan Bukin void
devmap_add_entry(vm_paddr_t pa,vm_size_t sz)12230b72b68SRuslan Bukin devmap_add_entry(vm_paddr_t pa, vm_size_t sz)
12330b72b68SRuslan Bukin {
12430b72b68SRuslan Bukin 	struct devmap_entry *m;
12530b72b68SRuslan Bukin 
12630b72b68SRuslan Bukin 	if (devmap_bootstrap_done)
12730b72b68SRuslan Bukin 		panic("devmap_add_entry() after devmap_bootstrap()");
12830b72b68SRuslan Bukin 
12930b72b68SRuslan Bukin 	if (akva_devmap_idx == (AKVA_DEVMAP_MAX_ENTRIES - 1))
13030b72b68SRuslan Bukin 		panic("AKVA_DEVMAP_MAX_ENTRIES is too small");
13130b72b68SRuslan Bukin 
13230b72b68SRuslan Bukin 	if (akva_devmap_idx == 0)
13330b72b68SRuslan Bukin 		devmap_register_table(akva_devmap_entries);
13430b72b68SRuslan Bukin 
1351d954438SKristof Provost 	 /* Allocate virtual address space from the top of kva downwards. */
13630b72b68SRuslan Bukin #ifdef __arm__
1371d954438SKristof Provost 	/*
1381d954438SKristof Provost 	 * If the range being mapped is aligned and sized to 1MB boundaries then
1391d954438SKristof Provost 	 * also align the virtual address to the next-lower 1MB boundary so that
1401d954438SKristof Provost 	 * we end with a nice efficient section mapping.
1411d954438SKristof Provost 	 */
14230b72b68SRuslan Bukin 	if ((pa & 0x000fffff) == 0 && (sz & 0x000fffff) == 0) {
14330b72b68SRuslan Bukin 		akva_devmap_vaddr = trunc_1mpage(akva_devmap_vaddr - sz);
14430b72b68SRuslan Bukin 	} else
14530b72b68SRuslan Bukin #endif
14630b72b68SRuslan Bukin 	{
14730b72b68SRuslan Bukin 		akva_devmap_vaddr = trunc_page(akva_devmap_vaddr - sz);
14830b72b68SRuslan Bukin 	}
14930b72b68SRuslan Bukin 	m = &akva_devmap_entries[akva_devmap_idx++];
15030b72b68SRuslan Bukin 	m->pd_va    = akva_devmap_vaddr;
15130b72b68SRuslan Bukin 	m->pd_pa    = pa;
15230b72b68SRuslan Bukin 	m->pd_size  = sz;
15330b72b68SRuslan Bukin }
15430b72b68SRuslan Bukin 
15530b72b68SRuslan Bukin /*
15630b72b68SRuslan Bukin  * Register the given table as the one to use in devmap_bootstrap().
15730b72b68SRuslan Bukin  */
15830b72b68SRuslan Bukin void
devmap_register_table(const struct devmap_entry * table)15930b72b68SRuslan Bukin devmap_register_table(const struct devmap_entry *table)
16030b72b68SRuslan Bukin {
16130b72b68SRuslan Bukin 
16230b72b68SRuslan Bukin 	devmap_table = table;
16330b72b68SRuslan Bukin }
16430b72b68SRuslan Bukin 
16530b72b68SRuslan Bukin /*
16630b72b68SRuslan Bukin  * Map all of the static regions in the devmap table, and remember the devmap
16730b72b68SRuslan Bukin  * table so the mapdev, ptov, and vtop functions can do lookups later.
16830b72b68SRuslan Bukin  */
16930b72b68SRuslan Bukin void
devmap_bootstrap(void)170*5df74441SMitchell Horne devmap_bootstrap(void)
17130b72b68SRuslan Bukin {
17230b72b68SRuslan Bukin 	const struct devmap_entry *pd;
17330b72b68SRuslan Bukin 
17430b72b68SRuslan Bukin 	devmap_bootstrap_done = true;
17530b72b68SRuslan Bukin 
17630b72b68SRuslan Bukin 	/*
177*5df74441SMitchell Horne 	 * If a table was previously registered, use it.  Otherwise, no work to
178*5df74441SMitchell Horne 	 * do.
17930b72b68SRuslan Bukin 	 */
180*5df74441SMitchell Horne 	if (devmap_table == NULL)
18130b72b68SRuslan Bukin 		return;
18230b72b68SRuslan Bukin 
18330b72b68SRuslan Bukin 	for (pd = devmap_table; pd->pd_size != 0; ++pd) {
18430b72b68SRuslan Bukin #if defined(__arm__)
18530b72b68SRuslan Bukin 		pmap_preboot_map_attr(pd->pd_pa, pd->pd_va, pd->pd_size,
18630b72b68SRuslan Bukin 		    VM_PROT_READ | VM_PROT_WRITE, VM_MEMATTR_DEVICE);
187ca20f8ecSRuslan Bukin #elif defined(__aarch64__) || defined(__riscv)
18830b72b68SRuslan Bukin 		pmap_kenter_device(pd->pd_va, pd->pd_size, pd->pd_pa);
18930b72b68SRuslan Bukin #endif
19030b72b68SRuslan Bukin 	}
19130b72b68SRuslan Bukin }
19230b72b68SRuslan Bukin 
19330b72b68SRuslan Bukin /*
19430b72b68SRuslan Bukin  * Look up the given physical address in the static mapping data and return the
19530b72b68SRuslan Bukin  * corresponding virtual address, or NULL if not found.
19630b72b68SRuslan Bukin  */
19730b72b68SRuslan Bukin void *
devmap_ptov(vm_paddr_t pa,vm_size_t size)19830b72b68SRuslan Bukin devmap_ptov(vm_paddr_t pa, vm_size_t size)
19930b72b68SRuslan Bukin {
20030b72b68SRuslan Bukin 	const struct devmap_entry *pd;
20130b72b68SRuslan Bukin 
20230b72b68SRuslan Bukin 	if (devmap_table == NULL)
20330b72b68SRuslan Bukin 		return (NULL);
20430b72b68SRuslan Bukin 
20530b72b68SRuslan Bukin 	for (pd = devmap_table; pd->pd_size != 0; ++pd) {
20630b72b68SRuslan Bukin 		if (pa >= pd->pd_pa && pa + size <= pd->pd_pa + pd->pd_size)
20730b72b68SRuslan Bukin 			return ((void *)(pd->pd_va + (pa - pd->pd_pa)));
20830b72b68SRuslan Bukin 	}
20930b72b68SRuslan Bukin 
21030b72b68SRuslan Bukin 	return (NULL);
21130b72b68SRuslan Bukin }
21230b72b68SRuslan Bukin 
21330b72b68SRuslan Bukin /*
21430b72b68SRuslan Bukin  * Look up the given virtual address in the static mapping data and return the
21530b72b68SRuslan Bukin  * corresponding physical address, or DEVMAP_PADDR_NOTFOUND if not found.
21630b72b68SRuslan Bukin  */
21730b72b68SRuslan Bukin vm_paddr_t
devmap_vtop(void * vpva,vm_size_t size)21830b72b68SRuslan Bukin devmap_vtop(void * vpva, vm_size_t size)
21930b72b68SRuslan Bukin {
22030b72b68SRuslan Bukin 	const struct devmap_entry *pd;
22130b72b68SRuslan Bukin 	vm_offset_t va;
22230b72b68SRuslan Bukin 
22330b72b68SRuslan Bukin 	if (devmap_table == NULL)
22430b72b68SRuslan Bukin 		return (DEVMAP_PADDR_NOTFOUND);
22530b72b68SRuslan Bukin 
22630b72b68SRuslan Bukin 	va = (vm_offset_t)vpva;
22730b72b68SRuslan Bukin 	for (pd = devmap_table; pd->pd_size != 0; ++pd) {
22830b72b68SRuslan Bukin 		if (va >= pd->pd_va && va + size <= pd->pd_va + pd->pd_size)
22930b72b68SRuslan Bukin 			return ((vm_paddr_t)(pd->pd_pa + (va - pd->pd_va)));
23030b72b68SRuslan Bukin 	}
23130b72b68SRuslan Bukin 
23230b72b68SRuslan Bukin 	return (DEVMAP_PADDR_NOTFOUND);
23330b72b68SRuslan Bukin }
23430b72b68SRuslan Bukin 
23530b72b68SRuslan Bukin /*
23630b72b68SRuslan Bukin  * Map a set of physical memory pages into the kernel virtual address space.
23730b72b68SRuslan Bukin  * Return a pointer to where it is mapped.
23830b72b68SRuslan Bukin  *
23930b72b68SRuslan Bukin  * This uses a pre-established static mapping if one exists for the requested
24030b72b68SRuslan Bukin  * range, otherwise it allocates kva space and maps the physical pages into it.
24130b72b68SRuslan Bukin  *
24230b72b68SRuslan Bukin  * This routine is intended to be used for mapping device memory, NOT real
24330b72b68SRuslan Bukin  * memory; the mapping type is inherently VM_MEMATTR_DEVICE in
24430b72b68SRuslan Bukin  * pmap_kenter_device().
24530b72b68SRuslan Bukin  */
24630b72b68SRuslan Bukin void *
pmap_mapdev(vm_paddr_t pa,vm_size_t size)247ea8f128cSJohn Baldwin pmap_mapdev(vm_paddr_t pa, vm_size_t size)
24830b72b68SRuslan Bukin {
24930b72b68SRuslan Bukin 	vm_offset_t va, offset;
25030b72b68SRuslan Bukin 	void * rva;
25130b72b68SRuslan Bukin 
25230b72b68SRuslan Bukin 	/* First look in the static mapping table. */
25330b72b68SRuslan Bukin 	if ((rva = devmap_ptov(pa, size)) != NULL)
25430b72b68SRuslan Bukin 		return (rva);
25530b72b68SRuslan Bukin 
25630b72b68SRuslan Bukin 	offset = pa & PAGE_MASK;
25730b72b68SRuslan Bukin 	pa = trunc_page(pa);
25830b72b68SRuslan Bukin 	size = round_page(size + offset);
25930b72b68SRuslan Bukin 
260ca20f8ecSRuslan Bukin #if defined(__aarch64__) || defined(__riscv)
26130b72b68SRuslan Bukin 	if (early_boot) {
26230b72b68SRuslan Bukin 		akva_devmap_vaddr = trunc_page(akva_devmap_vaddr - size);
26330b72b68SRuslan Bukin 		va = akva_devmap_vaddr;
264818390ceSMitchell Horne 		KASSERT(va >= VM_MAX_KERNEL_ADDRESS - PMAP_MAPDEV_EARLY_SIZE,
26530b72b68SRuslan Bukin 		    ("Too many early devmap mappings"));
26630b72b68SRuslan Bukin 	} else
26730b72b68SRuslan Bukin #endif
268e0388a90SAlan Cox #ifdef __aarch64__
269e0388a90SAlan Cox 	if (size >= L2_SIZE && (pa & L2_OFFSET) == 0)
270e0388a90SAlan Cox 		va = kva_alloc_aligned(size, L2_SIZE);
271e0388a90SAlan Cox 	else if (size >= L3C_SIZE && (pa & L3C_OFFSET) == 0)
272e0388a90SAlan Cox 		va = kva_alloc_aligned(size, L3C_SIZE);
273e0388a90SAlan Cox 	else
274e0388a90SAlan Cox #endif
27530b72b68SRuslan Bukin 		va = kva_alloc(size);
27630b72b68SRuslan Bukin 	if (!va)
27730b72b68SRuslan Bukin 		panic("pmap_mapdev: Couldn't alloc kernel virtual memory");
27830b72b68SRuslan Bukin 
27930b72b68SRuslan Bukin 	pmap_kenter_device(va, size, pa);
28030b72b68SRuslan Bukin 
28130b72b68SRuslan Bukin 	return ((void *)(va + offset));
28230b72b68SRuslan Bukin }
28330b72b68SRuslan Bukin 
284682c00a6SJessica Clarke #if defined(__aarch64__) || defined(__riscv)
28578442297SEmmanuel Vadot void *
pmap_mapdev_attr(vm_paddr_t pa,vm_size_t size,vm_memattr_t ma)286ea8f128cSJohn Baldwin pmap_mapdev_attr(vm_paddr_t pa, vm_size_t size, vm_memattr_t ma)
28778442297SEmmanuel Vadot {
28878442297SEmmanuel Vadot 	vm_offset_t va, offset;
28978442297SEmmanuel Vadot 	void * rva;
29078442297SEmmanuel Vadot 
29178442297SEmmanuel Vadot 	/* First look in the static mapping table. */
29278442297SEmmanuel Vadot 	if ((rva = devmap_ptov(pa, size)) != NULL)
29378442297SEmmanuel Vadot 		return (rva);
29478442297SEmmanuel Vadot 
29578442297SEmmanuel Vadot 	offset = pa & PAGE_MASK;
29678442297SEmmanuel Vadot 	pa = trunc_page(pa);
29778442297SEmmanuel Vadot 	size = round_page(size + offset);
29878442297SEmmanuel Vadot 
29978442297SEmmanuel Vadot 	if (early_boot) {
30078442297SEmmanuel Vadot 		akva_devmap_vaddr = trunc_page(akva_devmap_vaddr - size);
30178442297SEmmanuel Vadot 		va = akva_devmap_vaddr;
302c54fe25dSEmmanuel Vadot 		KASSERT(va >= (VM_MAX_KERNEL_ADDRESS - (PMAP_MAPDEV_EARLY_SIZE)),
303c54fe25dSEmmanuel Vadot 		    ("Too many early devmap mappings 2"));
30478442297SEmmanuel Vadot 	} else
305e0388a90SAlan Cox #ifdef __aarch64__
306e0388a90SAlan Cox 	if (size >= L2_SIZE && (pa & L2_OFFSET) == 0)
307e0388a90SAlan Cox 		va = kva_alloc_aligned(size, L2_SIZE);
308e0388a90SAlan Cox 	else if (size >= L3C_SIZE && (pa & L3C_OFFSET) == 0)
309e0388a90SAlan Cox 		va = kva_alloc_aligned(size, L3C_SIZE);
310e0388a90SAlan Cox 	else
311e0388a90SAlan Cox #endif
31278442297SEmmanuel Vadot 		va = kva_alloc(size);
31378442297SEmmanuel Vadot 	if (!va)
31478442297SEmmanuel Vadot 		panic("pmap_mapdev: Couldn't alloc kernel virtual memory");
31578442297SEmmanuel Vadot 
31678442297SEmmanuel Vadot 	pmap_kenter(va, size, pa, ma);
31778442297SEmmanuel Vadot 
31878442297SEmmanuel Vadot 	return ((void *)(va + offset));
31978442297SEmmanuel Vadot }
32078442297SEmmanuel Vadot #endif
32178442297SEmmanuel Vadot 
32230b72b68SRuslan Bukin /*
32330b72b68SRuslan Bukin  * Unmap device memory and free the kva space.
32430b72b68SRuslan Bukin  */
32530b72b68SRuslan Bukin void
pmap_unmapdev(void * p,vm_size_t size)3267ae99f80SJohn Baldwin pmap_unmapdev(void *p, vm_size_t size)
32730b72b68SRuslan Bukin {
3287ae99f80SJohn Baldwin 	vm_offset_t offset, va;
32930b72b68SRuslan Bukin 
33030b72b68SRuslan Bukin 	/* Nothing to do if we find the mapping in the static table. */
3317ae99f80SJohn Baldwin 	if (devmap_vtop(p, size) != DEVMAP_PADDR_NOTFOUND)
33230b72b68SRuslan Bukin 		return;
33330b72b68SRuslan Bukin 
3347ae99f80SJohn Baldwin 	va = (vm_offset_t)p;
33530b72b68SRuslan Bukin 	offset = va & PAGE_MASK;
33630b72b68SRuslan Bukin 	va = trunc_page(va);
33730b72b68SRuslan Bukin 	size = round_page(size + offset);
33830b72b68SRuslan Bukin 
33930b72b68SRuslan Bukin 	pmap_kremove_device(va, size);
34030b72b68SRuslan Bukin 	kva_free(va, size);
34130b72b68SRuslan Bukin }
34230b72b68SRuslan Bukin 
34330b72b68SRuslan Bukin #ifdef DDB
34430b72b68SRuslan Bukin #include <ddb/ddb.h>
34530b72b68SRuslan Bukin 
DB_SHOW_COMMAND_FLAGS(devmap,db_show_devmap,DB_CMD_MEMSAFE)346c84c5e00SMitchell Horne DB_SHOW_COMMAND_FLAGS(devmap, db_show_devmap, DB_CMD_MEMSAFE)
34730b72b68SRuslan Bukin {
34830b72b68SRuslan Bukin 	devmap_dump_table(db_printf);
34930b72b68SRuslan Bukin }
35030b72b68SRuslan Bukin 
35130b72b68SRuslan Bukin #endif /* DDB */
352