1257648Sian/*-
2257648Sian * Copyright (c) 2013 Ian Lepore <ian@freebsd.org>
3257648Sian * All rights reserved.
4257648Sian *
5257648Sian * Redistribution and use in source and binary forms, with or without
6257648Sian * modification, are permitted provided that the following conditions
7257648Sian * are met:
8257648Sian * 1. Redistributions of source code must retain the above copyright
9257648Sian *    notice, this list of conditions and the following disclaimer.
10257648Sian * 2. Redistributions in binary form must reproduce the above copyright
11257648Sian *    notice, this list of conditions and the following disclaimer in the
12257648Sian *    documentation and/or other materials provided with the distribution.
13257648Sian *
14257648Sian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15257648Sian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16257648Sian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17257648Sian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18257648Sian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19257648Sian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20257648Sian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21257648Sian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22257648Sian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23257648Sian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24257648Sian * SUCH DAMAGE.
25257648Sian *
26257648Sian * $FreeBSD$
27257648Sian */
28257648Sian
29257648Sian#ifndef	_MACHINE_DEVMAP_H_
30257648Sian#define	_MACHINE_DEVMAP_H_
31257648Sian
32257648Sian/*
33259364Sian * This structure is used by MD code to describe static mappings of devices
34259364Sian * which are established as part of bringing up the MMU early in the boot.
35259364Sian */
36259364Sianstruct arm_devmap_entry {
37259364Sian	vm_offset_t	pd_va;		/* virtual address */
38259364Sian	vm_paddr_t	pd_pa;		/* physical address */
39259364Sian	vm_size_t	pd_size;	/* size of region */
40259364Sian	vm_prot_t	pd_prot;	/* protection code */
41259364Sian	int		pd_cache;	/* cache attributes */
42259364Sian};
43259364Sian
44259364Sian/*
45259365Sian * Return the lowest KVA address used in any entry in the registered devmap
46259365Sian * table.  This works with whatever table is registered, including the internal
47259365Sian * table used by arm_devmap_add_entry() if that routine was used. Platforms can
48259365Sian * implement initarm_lastaddr() by calling this if static device mappings are
49259365Sian * their only use of high KVA space.
50259365Sian */
51259365Sianvm_offset_t arm_devmap_lastaddr(void);
52259365Sian
53259365Sian/*
54259365Sian * Automatically allocate KVA (from the top of the address space downwards) and
55259365Sian * make static device mapping entries in an internal table.  The internal table
56259365Sian * is automatically registered on the first call to this.
57259365Sian */
58259365Sianvoid arm_devmap_add_entry(vm_paddr_t pa, vm_size_t sz);
59259365Sian
60259365Sian/*
61259364Sian * Register a platform-local table to be bootstrapped by the generic
62259364Sian * initarm() in arm/machdep.c.  This is used by newer code that allocates and
63259364Sian * fills in its own local table but does not have its own initarm() routine.
64259364Sian */
65259364Sianvoid arm_devmap_register_table(const struct arm_devmap_entry * _table);
66259364Sian
67259364Sian/*
68259365Sian * Establish mappings for all the entries in the table.  This is called
69259365Sian * automatically from the common initarm() in arm/machdep.c, and also from the
70259365Sian * custom initarm() routines in older code.  If the table pointer is NULL, this
71259365Sian * will use the table installed previously by arm_devmap_register_table().
72259364Sian */
73259364Sianvoid arm_devmap_bootstrap(vm_offset_t _l1pt,
74259364Sian    const struct arm_devmap_entry *_table);
75259364Sian
76259364Sian/*
77259365Sian * Translate between virtual and physical addresses within a region that is
78259365Sian * static-mapped by the devmap code.  If the given address range isn't
79257648Sian * static-mapped, then ptov returns NULL and vtop returns DEVMAP_PADDR_NOTFOUND.
80257648Sian * The latter implies that you can't vtop just the last byte of physical address
81257648Sian * space.  This is not as limiting as it might sound, because even if a device
82257648Sian * occupies the end of the physical address space, you're only prevented from
83257648Sian * doing vtop for that single byte.  If you vtop a size bigger than 1 it works.
84257648Sian */
85257648Sian#define	DEVMAP_PADDR_NOTFOUND	((vm_paddr_t)(-1))
86257648Sian
87257648Sianvoid *     arm_devmap_ptov(vm_paddr_t _pa, vm_size_t _sz);
88257648Sianvm_paddr_t arm_devmap_vtop(void * _va, vm_size_t _sz);
89257648Sian
90266086Sian/* Print the static mapping table; used for bootverbose output. */
91266086Sianvoid arm_devmap_print_table(void);
92266086Sian
93257648Sian#endif
94