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