xref: /illumos-gate/usr/src/uts/sun4u/sys/prom_plat.h (revision 0173c38a73f34277e0c97a19fedfd25d81ba8380)
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 2006 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/feature_tests.h>
32 #include <sys/cpuvar.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #if !defined(_LONGLONG_TYPE)
39 #error "This header won't work without long long support"
40 #endif
41 
42 /*
43  * This file contains external platform-specific promif interface definitions.
44  * There may be none.  This file is included by reference in <sys/promif.h>
45  *
46  * This version of the file is for the IEEE 1275-1994 compliant sun4u prom.
47  */
48 
49 /*
50  * Memory allocation plus memory/mmu interfaces:
51  *
52  * Routines with fine-grained memory and MMU control are platform-dependent.
53  *
54  * MMU node virtualized "mode" arguments and results for Spitfire MMU:
55  *
56  * The default virtualized "mode" for client program mappings created
57  * by the firmware is as follows:
58  *
59  * G (global)		Clear
60  * L (locked)		Clear
61  * W (write)		Set
62  * R (read - soft)	Set (Prom is not required to implement soft bits)
63  * X (exec - soft)	Set (Prom is not required to implement soft bits)
64  * CV,CP (Cacheable)	Set if memory page, Clear if IO page
65  * E (side effects)	Clear if memory page; Set if IO page
66  * IE (Invert endian.)	Clear
67  *
68  * The following fields are initialized as follows in the TTE-data for any
69  * mappings created by the firmware on behalf of the client program:
70  *
71  * P (Priviledged)	Set
72  * V (Valid)		Set
73  * NFO (No Fault Only)	Clear
74  * Context		0
75  * Soft bits		< private to the firmware implementation >
76  *
77  * Page size of Prom mappings are typically 8k, "modify" cannot change
78  * page sizes. Mappings created by "map" are 8k pages.
79  *
80  * If the virtualized "mode" is -1, the defaults as shown above are used,
81  * otherwise the virtualized "mode" is set (and returned) based on the
82  * following virtualized "mode" abstractions. The mmu node "translations"
83  * property contains the actual tte-data, not the virtualized "mode".
84  *
85  * Note that client programs may not create locked mappings by setting
86  * the LOCKED bit. There are Spitfire specific client interfaces to create
87  * and remove locked mappings. (SUNW,{i,d}tlb-load).
88  * The LOCKED bit is defined here since it may be returned by the
89  * "translate" method.
90  *
91  * The PROM is not required to implement the Read and eXecute soft bits,
92  * and is not required to track them for the client program. They may be
93  * set on calls to "map" and "modfify" and may be ignored by the firmware,
94  * and are not necessarily returned from "translate".
95  *
96  * The TTE soft bits are private to the firmware.  No assumptions may
97  * be made regarding the contents of the TTE soft bits.
98  *
99  * Changing a mapping from cacheable to non-cacheable implies a flush
100  * or invalidate operation, if necessary.
101  *
102  * NB: The "map" MMU node method should NOT be used to create IO device
103  * mappings. The correct way to do this is to call the device's parent
104  * "map-in" method using the CALL-METHOD client interface service.
105  */
106 
107 #define	PROM_MMU_MODE_DEFAULT	((int)-1)	/* Default "mode", see above */
108 
109 /*
110  * NB: These are not implemented in PROM version P1.0 ...
111  */
112 #define	PROM_MMU_MODE_WRITE	0x0001	/* Translation is Writable */
113 #define	PROM_MMU_MODE_READ	0x0002	/* Soft: Readable, See above */
114 #define	PROM_MMU_MODE_EXEC	0x0004	/* Soft: eXecutable, See above */
115 #define	PROM_MMU_MODE_RWX_MASK	0x0007	/* Mask for R-W-X bits */
116 
117 #define	PROM_MMU_MODE_LOCKED	0x0010	/* Read-only: Locked; see above */
118 #define	PROM_MMU_MODE_CACHED	0x0020	/* Set means both CV,CP bits */
119 #define	PROM_MMU_MODE_EFFECTS	0x0040	/* side Effects bit in MMU */
120 #define	PROM_MMU_MODE_GLOBAL	0x0080	/* Global bit */
121 #define	PROM_MMU_MODE_INVERT	0x0100	/* Invert Endianness */
122 
123 /*
124  * resource allocation group: OBP only. (mapping functions are platform
125  * dependent because they use physical address arguments.)
126  */
127 extern	caddr_t		prom_map(caddr_t virthint,
128 			    unsigned long long physaddr, uint_t size);
129 
130 /*
131  * prom_alloc is platform dependent and has historical semantics
132  * associated with the align argument and the return value.
133  * prom_malloc is the generic memory allocator.
134  */
135 extern	caddr_t		prom_malloc(caddr_t virt, size_t size, uint_t align);
136 
137 extern	caddr_t		prom_allocate_virt(uint_t align, size_t size);
138 extern	caddr_t		prom_claim_virt(size_t size, caddr_t virt);
139 extern	void		prom_free_virt(size_t size, caddr_t virt);
140 
141 extern	int		prom_allocate_phys(size_t size, uint_t align,
142 			    unsigned long long *physaddr);
143 extern	int		prom_claim_phys(size_t size,
144 			    unsigned long long physaddr);
145 extern	void		prom_free_phys(size_t size,
146 			    unsigned long long physaddr);
147 
148 extern	int		prom_map_phys(int mode, size_t size, caddr_t virt,
149 			    unsigned long long physaddr);
150 extern	void		prom_unmap_phys(size_t size, caddr_t virt);
151 extern	void		prom_unmap_virt(size_t size, caddr_t virt);
152 
153 /*
154  * prom_retain allocates or returns retained physical memory
155  * identified by the arguments of name string "id", "size" and "align".
156  */
157 extern	int		prom_retain(char *id, size_t size, uint_t align,
158 			    unsigned long long *physaddr);
159 
160 /*
161  * prom_translate_virt returns the physical address and virtualized "mode"
162  * for the given virtual address. After the call, if *valid is non-zero,
163  * a mapping to 'virt' exists and the physical address and virtualized
164  * "mode" were returned to the caller.
165  */
166 extern	int		prom_translate_virt(caddr_t virt, int *valid,
167 			    unsigned long long *physaddr, int *mode);
168 
169 /*
170  * prom_modify_mapping changes the "mode" of an existing mapping or
171  * repeated mappings. virt is the virtual address whose "mode" is to
172  * be changed; size is some multiple of the fundamental pagesize.
173  * This method cannot be used to change the pagesize of an MMU mapping,
174  * nor can it be used to Lock a translation into the i or d tlb.
175  */
176 extern	int	prom_modify_mapping(caddr_t virt, size_t size, int mode);
177 
178 /*
179  * Client interfaces for managing the {i,d}tlb handoff to client programs.
180  */
181 extern	int		prom_itlb_load(int index,
182 			    unsigned long long tte_data, caddr_t virt);
183 
184 extern	int		prom_dtlb_load(int index,
185 			    unsigned long long tte_data, caddr_t virt);
186 
187 /*
188  * Administrative group: OBP only and SMCC platform specific.
189  * XXX: IDPROM related stuff should be replaced with specific data-oriented
190  * XXX: functions.
191  */
192 
193 extern	int		prom_heartbeat(int msecs);
194 extern	int		prom_get_unum(int syn_code, unsigned long long physaddr,
195 				char *buf, uint_t buflen, int *ustrlen);
196 extern	int		prom_serengeti_get_ecacheunum(int cpuid,
197 				unsigned long long physaddr, char *buf,
198 				uint_t buflen, int *ustrlen);
199 
200 extern	int		prom_getidprom(caddr_t addr, int size);
201 extern	int		prom_getmacaddr(ihandle_t hd, caddr_t ea);
202 
203 /*
204  * CPU Control Group: MP's only.
205  */
206 extern	int		prom_startcpu(pnode_t node, caddr_t pc, int arg);
207 extern	int		prom_startcpu_bycpuid(int cpuid, caddr_t pc, int arg);
208 extern	int		prom_stopcpu_bycpuid(int);
209 extern	int		prom_sunfire_cpu_off(void);	/* SunFire only */
210 extern	int		prom_wakeupcpu(pnode_t node);
211 extern	int		prom_serengeti_wakeupcpu(pnode_t node);
212 extern	int		prom_hotaddcpu(int cpuid);
213 extern	int		prom_hotremovecpu(int cpuid);
214 extern	void		promsafe_pause_cpus(void);
215 extern	void		promsafe_xc_attention(cpuset_t cpuset);
216 extern	int		prom_serengeti_cpu_off(pnode_t node);
217 
218 /*
219  * Set trap table
220  */
221 extern	void		prom_set_traptable(void *tba_addr);
222 
223 /*
224  * Power-off
225  */
226 extern	void		prom_power_off(void);
227 
228 /*
229  * sunfire attach/detach
230  */
231 extern	int		prom_sunfire_attach_board(uint_t board);
232 extern	int		prom_sunfire_detach_board(uint_t board);
233 
234 /*
235  * Serengeti console switch
236  */
237 extern	char		*prom_serengeti_set_console_input(char *new_value);
238 
239 /*
240  * Serengeti attach/detach
241  */
242 extern	int		prom_serengeti_attach_board(uint_t node, uint_t board);
243 extern	int		prom_serengeti_detach_board(uint_t node, uint_t board);
244 extern	int		prom_serengeti_tunnel_switch(uint_t node, uint_t board);
245 
246 /*
247  * Starcat-specific routines
248  */
249 extern	int		prom_starcat_switch_tunnel(uint_t portid,
250 			    uint_t msgtype);
251 extern	int		prom_starcat_iosram_read(uint32_t key, uint32_t offset,
252 			    uint32_t len, caddr_t buf);
253 extern	int		prom_starcat_iosram_write(uint32_t key, uint32_t offset,
254 			    uint32_t len, caddr_t buf);
255 
256 /*
257  * Starfire-specific routines
258  */
259 extern	int		prom_starfire_add_brd(uint_t cpuid);
260 extern	int		prom_starfire_rm_brd(uint_t brdnum);
261 extern	void		prom_starfire_add_cpu(uint_t cpuid);
262 extern	void		prom_starfire_rm_cpu(uint_t cpuid);
263 extern	int		prom_starfire_move_cpu0(uint_t cpuid);
264 extern	void		prom_starfire_init_console(uint_t cpuid);
265 
266 /*
267  * OPL-specific routines
268  */
269 extern	void		prom_opl_get_tod(time_t *time, int64_t *stickval);
270 extern	void		prom_opl_set_diff(int64_t diff);
271 extern	int		prom_attach_notice(int bn);
272 extern	int		prom_detach_notice(int bn);
273 extern	int		prom_opl_switch_console(int bn);
274 
275 /*
276  * The client program implementation is required to provide a wrapper
277  * to the client handler, for the 32 bit client program to 64 bit cell-sized
278  * client interface handler (switch stack, etc.).  This function is not
279  * to be used externally!
280  */
281 
282 extern	int		client_handler(void *cif_handler, void *arg_array);
283 
284 /*
285  * The 'format' of the "translations" property in the 'mmu' node ...
286  */
287 
288 struct translation {
289 	uint32_t virt_hi;	/* upper 32 bits of vaddr */
290 	uint32_t virt_lo;	/* lower 32 bits of vaddr */
291 	uint32_t size_hi;	/* upper 32 bits of size in bytes */
292 	uint32_t size_lo;	/* lower 32 bits of size in bytes */
293 	uint32_t tte_hi;	/* higher 32 bites of tte */
294 	uint32_t tte_lo;	/* lower 32 bits of tte */
295 };
296 
297 #ifdef	__cplusplus
298 }
299 #endif
300 
301 #endif /* _SYS_PROM_PLAT_H */
302