1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef	_SYS_PROM_PLAT_H
27#define	_SYS_PROM_PLAT_H
28
29#include <sys/feature_tests.h>
30
31#ifdef	__cplusplus
32extern "C" {
33#endif
34
35#if !defined(_LONGLONG_TYPE)
36#error "This header won't work without long long support"
37#endif
38
39/*
40 * This file contains external platform-specific promif interface definitions.
41 * There may be none.  This file is included by reference in <sys/promif.h>
42 *
43 * Common sun4 subset for the IEEE 1275-1994 compliant prom.
44 */
45
46/*
47 * Memory allocation plus memory/mmu interfaces:
48 *
49 * Routines with fine-grained memory and MMU control are platform-dependent.
50 *
51 * MMU node virtualized "mode" arguments and results for Spitfire MMU:
52 *
53 * The default virtualized "mode" for client program mappings created
54 * by the firmware is as follows:
55 *
56 * G (global)		Clear
57 * L (locked)		Clear
58 * W (write)		Set
59 * R (read - soft)	Set (Prom is not required to implement soft bits)
60 * X (exec - soft)	Set (Prom is not required to implement soft bits)
61 * CV,CP (Cacheable)	Set if memory page, Clear if IO page
62 * E (side effects)	Clear if memory page; Set if IO page
63 * IE (Invert endian.)	Clear
64 *
65 * The following fields are initialized as follows in the TTE-data for any
66 * mappings created by the firmware on behalf of the client program:
67 *
68 * P (Priviledged)	Set
69 * V (Valid)		Set
70 * NFO (No Fault Only)	Clear
71 * Context		0
72 * Soft bits		< private to the firmware implementation >
73 *
74 * Page size of Prom mappings are typically 8k, "modify" cannot change
75 * page sizes. Mappings created by "map" are 8k pages.
76 *
77 * If the virtualized "mode" is -1, the defaults as shown above are used,
78 * otherwise the virtualized "mode" is set (and returned) based on the
79 * following virtualized "mode" abstractions. The mmu node "translations"
80 * property contains the actual tte-data, not the virtualized "mode".
81 *
82 * Note that client programs may not create locked mappings by setting
83 * the LOCKED bit. There are Spitfire specific client interfaces to create
84 * and remove locked mappings. (SUNW,{i,d}tlb-load).
85 * The LOCKED bit is defined here since it may be returned by the
86 * "translate" method.
87 *
88 * The PROM is not required to implement the Read and eXecute soft bits,
89 * and is not required to track them for the client program. They may be
90 * set on calls to "map" and "modfify" and may be ignored by the firmware,
91 * and are not necessarily returned from "translate".
92 *
93 * The TTE soft bits are private to the firmware.  No assumptions may
94 * be made regarding the contents of the TTE soft bits.
95 *
96 * Changing a mapping from cacheable to non-cacheable implies a flush
97 * or invalidate operation, if necessary.
98 *
99 * NB: The "map" MMU node method should NOT be used to create IO device
100 * mappings. The correct way to do this is to call the device's parent
101 * "map-in" method using the CALL-METHOD client interface service.
102 */
103
104#define	PROM_MMU_MODE_DEFAULT	((int)-1)	/* Default "mode", see above */
105
106/*
107 * NB: These are not implemented in PROM version P1.0 ...
108 */
109#define	PROM_MMU_MODE_WRITE	0x0001	/* Translation is Writable */
110#define	PROM_MMU_MODE_READ	0x0002	/* Soft: Readable, See above */
111#define	PROM_MMU_MODE_EXEC	0x0004	/* Soft: eXecutable, See above */
112#define	PROM_MMU_MODE_RWX_MASK	0x0007	/* Mask for R-W-X bits */
113
114#define	PROM_MMU_MODE_LOCKED	0x0010	/* Read-only: Locked; see above */
115#define	PROM_MMU_MODE_CACHED	0x0020	/* Set means both CV,CP bits */
116#define	PROM_MMU_MODE_EFFECTS	0x0040	/* side Effects bit in MMU */
117#define	PROM_MMU_MODE_GLOBAL	0x0080	/* Global bit */
118#define	PROM_MMU_MODE_INVERT	0x0100	/* Invert Endianness */
119
120/*
121 * resource allocation group: OBP only. (mapping functions are platform
122 * dependent because they use physical address arguments.)
123 */
124extern	caddr_t		prom_map(caddr_t virthint,
125			    unsigned long long physaddr, uint_t size);
126
127/*
128 * prom_alloc is platform dependent and has historical semantics
129 * associated with the align argument and the return value.
130 * prom_malloc is the generic memory allocator.
131 */
132extern	caddr_t		prom_malloc(caddr_t virt, size_t size, uint_t align);
133
134extern	caddr_t		prom_allocate_virt(uint_t align, size_t size);
135extern	caddr_t		prom_claim_virt(size_t size, caddr_t virt);
136extern	void		prom_free_virt(size_t size, caddr_t virt);
137
138extern	int		prom_allocate_phys(size_t size, uint_t align,
139			    unsigned long long *physaddr);
140extern	int		prom_claim_phys(size_t size,
141			    unsigned long long physaddr);
142extern	void		prom_free_phys(size_t size,
143			    unsigned long long physaddr);
144
145extern	int		prom_map_phys(int mode, size_t size, caddr_t virt,
146			    unsigned long long physaddr);
147extern	void		prom_unmap_phys(size_t size, caddr_t virt);
148extern	void		prom_unmap_virt(size_t size, caddr_t virt);
149
150extern	int		prom_phys_installed_len(void);
151extern	int		prom_phys_avail_len(void);
152extern	int		prom_virt_avail_len(void);
153
154extern	int		prom_phys_installed(caddr_t);
155extern	int		prom_phys_avail(caddr_t);
156extern	int		prom_virt_avail(caddr_t);
157
158/*
159 * prom_retain allocates or returns retained physical memory
160 * identified by the arguments of name string "id", "size" and "align".
161 */
162extern	int		prom_retain(char *id, size_t size, uint_t align,
163			    unsigned long long *physaddr);
164
165/*
166 * prom_translate_virt returns the physical address and virtualized "mode"
167 * for the given virtual address. After the call, if *valid is non-zero,
168 * a mapping to 'virt' exists and the physical address and virtualized
169 * "mode" were returned to the caller.
170 */
171extern	int		prom_translate_virt(caddr_t virt, int *valid,
172			    unsigned long long *physaddr, int *mode);
173
174/*
175 * prom_modify_mapping changes the "mode" of an existing mapping or
176 * repeated mappings. virt is the virtual address whose "mode" is to
177 * be changed; size is some multiple of the fundamental pagesize.
178 * This method cannot be used to change the pagesize of an MMU mapping,
179 * nor can it be used to Lock a translation into the i or d tlb.
180 */
181extern	int	prom_modify_mapping(caddr_t virt, size_t size, int mode);
182
183/*
184 * Client interfaces for managing the {i,d}tlb handoff to client programs.
185 */
186extern	int		prom_itlb_load(int index,
187			    unsigned long long tte_data, caddr_t virt);
188
189extern	int		prom_dtlb_load(int index,
190			    unsigned long long tte_data, caddr_t virt);
191
192
193/*
194 * The client program implementation is required to provide a wrapper
195 * to the client handler, for the 32 bit client program to 64 bit cell-sized
196 * client interface handler (switch stack, etc.).  This function is not
197 * to be used externally!
198 */
199
200extern	int		client_handler(void *cif_handler, void *arg_array);
201
202/*
203 * The 'format' of the "translations" property in the 'mmu' node ...
204 */
205
206struct translation {
207	uint32_t virt_hi;	/* upper 32 bits of vaddr */
208	uint32_t virt_lo;	/* lower 32 bits of vaddr */
209	uint32_t size_hi;	/* upper 32 bits of size in bytes */
210	uint32_t size_lo;	/* lower 32 bits of size in bytes */
211	uint32_t tte_hi;	/* higher 32 bites of tte */
212	uint32_t tte_lo;	/* lower 32 bits of tte */
213};
214
215#ifdef	__cplusplus
216}
217#endif
218
219#endif /* _SYS_PROM_PLAT_H */
220