xref: /illumos-gate/usr/src/uts/sun4u/sys/prom_plat.h (revision 1f4c6dbc)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
525cf1a30Sjl  * Common Development and Distribution License (the "License").
625cf1a30Sjl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22986fd29aSsetje  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25*2a1fd0ffSPeter Tribble /*
26*2a1fd0ffSPeter Tribble  * Copyright 2019 Peter Tribble.
27*2a1fd0ffSPeter Tribble  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_SYS_PROM_PLAT_H
307c478bd9Sstevel@tonic-gate #define	_SYS_PROM_PLAT_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
337c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #if !defined(_LONGLONG_TYPE)
407c478bd9Sstevel@tonic-gate #error "This header won't work without long long support"
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * This file contains external platform-specific promif interface definitions.
457c478bd9Sstevel@tonic-gate  * There may be none.  This file is included by reference in <sys/promif.h>
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  * This version of the file is for the IEEE 1275-1994 compliant sun4u prom.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * Memory allocation plus memory/mmu interfaces:
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  * Routines with fine-grained memory and MMU control are platform-dependent.
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * MMU node virtualized "mode" arguments and results for Spitfire MMU:
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * The default virtualized "mode" for client program mappings created
587c478bd9Sstevel@tonic-gate  * by the firmware is as follows:
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * G (global)		Clear
617c478bd9Sstevel@tonic-gate  * L (locked)		Clear
627c478bd9Sstevel@tonic-gate  * W (write)		Set
637c478bd9Sstevel@tonic-gate  * R (read - soft)	Set (Prom is not required to implement soft bits)
647c478bd9Sstevel@tonic-gate  * X (exec - soft)	Set (Prom is not required to implement soft bits)
657c478bd9Sstevel@tonic-gate  * CV,CP (Cacheable)	Set if memory page, Clear if IO page
667c478bd9Sstevel@tonic-gate  * E (side effects)	Clear if memory page; Set if IO page
677c478bd9Sstevel@tonic-gate  * IE (Invert endian.)	Clear
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * The following fields are initialized as follows in the TTE-data for any
707c478bd9Sstevel@tonic-gate  * mappings created by the firmware on behalf of the client program:
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * P (Priviledged)	Set
737c478bd9Sstevel@tonic-gate  * V (Valid)		Set
747c478bd9Sstevel@tonic-gate  * NFO (No Fault Only)	Clear
757c478bd9Sstevel@tonic-gate  * Context		0
767c478bd9Sstevel@tonic-gate  * Soft bits		< private to the firmware implementation >
777c478bd9Sstevel@tonic-gate  *
787c478bd9Sstevel@tonic-gate  * Page size of Prom mappings are typically 8k, "modify" cannot change
797c478bd9Sstevel@tonic-gate  * page sizes. Mappings created by "map" are 8k pages.
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  * If the virtualized "mode" is -1, the defaults as shown above are used,
827c478bd9Sstevel@tonic-gate  * otherwise the virtualized "mode" is set (and returned) based on the
837c478bd9Sstevel@tonic-gate  * following virtualized "mode" abstractions. The mmu node "translations"
847c478bd9Sstevel@tonic-gate  * property contains the actual tte-data, not the virtualized "mode".
857c478bd9Sstevel@tonic-gate  *
867c478bd9Sstevel@tonic-gate  * Note that client programs may not create locked mappings by setting
877c478bd9Sstevel@tonic-gate  * the LOCKED bit. There are Spitfire specific client interfaces to create
887c478bd9Sstevel@tonic-gate  * and remove locked mappings. (SUNW,{i,d}tlb-load).
897c478bd9Sstevel@tonic-gate  * The LOCKED bit is defined here since it may be returned by the
907c478bd9Sstevel@tonic-gate  * "translate" method.
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  * The PROM is not required to implement the Read and eXecute soft bits,
937c478bd9Sstevel@tonic-gate  * and is not required to track them for the client program. They may be
947c478bd9Sstevel@tonic-gate  * set on calls to "map" and "modfify" and may be ignored by the firmware,
957c478bd9Sstevel@tonic-gate  * and are not necessarily returned from "translate".
967c478bd9Sstevel@tonic-gate  *
977c478bd9Sstevel@tonic-gate  * The TTE soft bits are private to the firmware.  No assumptions may
987c478bd9Sstevel@tonic-gate  * be made regarding the contents of the TTE soft bits.
997c478bd9Sstevel@tonic-gate  *
1007c478bd9Sstevel@tonic-gate  * Changing a mapping from cacheable to non-cacheable implies a flush
1017c478bd9Sstevel@tonic-gate  * or invalidate operation, if necessary.
1027c478bd9Sstevel@tonic-gate  *
1037c478bd9Sstevel@tonic-gate  * NB: The "map" MMU node method should NOT be used to create IO device
1047c478bd9Sstevel@tonic-gate  * mappings. The correct way to do this is to call the device's parent
1057c478bd9Sstevel@tonic-gate  * "map-in" method using the CALL-METHOD client interface service.
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_DEFAULT	((int)-1)	/* Default "mode", see above */
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * NB: These are not implemented in PROM version P1.0 ...
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_WRITE	0x0001	/* Translation is Writable */
1147c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_READ	0x0002	/* Soft: Readable, See above */
1157c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_EXEC	0x0004	/* Soft: eXecutable, See above */
1167c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_RWX_MASK	0x0007	/* Mask for R-W-X bits */
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_LOCKED	0x0010	/* Read-only: Locked; see above */
1197c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_CACHED	0x0020	/* Set means both CV,CP bits */
1207c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_EFFECTS	0x0040	/* side Effects bit in MMU */
1217c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_GLOBAL	0x0080	/* Global bit */
1227c478bd9Sstevel@tonic-gate #define	PROM_MMU_MODE_INVERT	0x0100	/* Invert Endianness */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * resource allocation group: OBP only. (mapping functions are platform
1267c478bd9Sstevel@tonic-gate  * dependent because they use physical address arguments.)
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate extern	caddr_t		prom_map(caddr_t virthint,
1297c478bd9Sstevel@tonic-gate 			    unsigned long long physaddr, uint_t size);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * prom_alloc is platform dependent and has historical semantics
1337c478bd9Sstevel@tonic-gate  * associated with the align argument and the return value.
1347c478bd9Sstevel@tonic-gate  * prom_malloc is the generic memory allocator.
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate extern	caddr_t		prom_malloc(caddr_t virt, size_t size, uint_t align);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate extern	caddr_t		prom_allocate_virt(uint_t align, size_t size);
1397c478bd9Sstevel@tonic-gate extern	caddr_t		prom_claim_virt(size_t size, caddr_t virt);
1407c478bd9Sstevel@tonic-gate extern	void		prom_free_virt(size_t size, caddr_t virt);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate extern	int		prom_allocate_phys(size_t size, uint_t align,
1437c478bd9Sstevel@tonic-gate 			    unsigned long long *physaddr);
1447c478bd9Sstevel@tonic-gate extern	int		prom_claim_phys(size_t size,
1457c478bd9Sstevel@tonic-gate 			    unsigned long long physaddr);
1467c478bd9Sstevel@tonic-gate extern	void		prom_free_phys(size_t size,
1477c478bd9Sstevel@tonic-gate 			    unsigned long long physaddr);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate extern	int		prom_map_phys(int mode, size_t size, caddr_t virt,
1507c478bd9Sstevel@tonic-gate 			    unsigned long long physaddr);
1517c478bd9Sstevel@tonic-gate extern	void		prom_unmap_phys(size_t size, caddr_t virt);
1527c478bd9Sstevel@tonic-gate extern	void		prom_unmap_virt(size_t size, caddr_t virt);
1537c478bd9Sstevel@tonic-gate 
154986fd29aSsetje extern	int		prom_phys_installed_len(void);
155986fd29aSsetje extern	int		prom_phys_avail_len(void);
156986fd29aSsetje extern	int		prom_virt_avail_len(void);
157986fd29aSsetje 
158986fd29aSsetje extern	int		prom_phys_installed(caddr_t);
159986fd29aSsetje extern	int		prom_phys_avail(caddr_t);
160986fd29aSsetje extern	int		prom_virt_avail(caddr_t);
161986fd29aSsetje 
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * prom_retain allocates or returns retained physical memory
1647c478bd9Sstevel@tonic-gate  * identified by the arguments of name string "id", "size" and "align".
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate extern	int		prom_retain(char *id, size_t size, uint_t align,
1677c478bd9Sstevel@tonic-gate 			    unsigned long long *physaddr);
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * prom_translate_virt returns the physical address and virtualized "mode"
1717c478bd9Sstevel@tonic-gate  * for the given virtual address. After the call, if *valid is non-zero,
1727c478bd9Sstevel@tonic-gate  * a mapping to 'virt' exists and the physical address and virtualized
1737c478bd9Sstevel@tonic-gate  * "mode" were returned to the caller.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate extern	int		prom_translate_virt(caddr_t virt, int *valid,
1767c478bd9Sstevel@tonic-gate 			    unsigned long long *physaddr, int *mode);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate  * prom_modify_mapping changes the "mode" of an existing mapping or
1807c478bd9Sstevel@tonic-gate  * repeated mappings. virt is the virtual address whose "mode" is to
1817c478bd9Sstevel@tonic-gate  * be changed; size is some multiple of the fundamental pagesize.
1827c478bd9Sstevel@tonic-gate  * This method cannot be used to change the pagesize of an MMU mapping,
1837c478bd9Sstevel@tonic-gate  * nor can it be used to Lock a translation into the i or d tlb.
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate extern	int	prom_modify_mapping(caddr_t virt, size_t size, int mode);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * Client interfaces for managing the {i,d}tlb handoff to client programs.
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate extern	int		prom_itlb_load(int index,
1917c478bd9Sstevel@tonic-gate 			    unsigned long long tte_data, caddr_t virt);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate extern	int		prom_dtlb_load(int index,
1947c478bd9Sstevel@tonic-gate 			    unsigned long long tte_data, caddr_t virt);
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate  * Administrative group: OBP only and SMCC platform specific.
1987c478bd9Sstevel@tonic-gate  * XXX: IDPROM related stuff should be replaced with specific data-oriented
1997c478bd9Sstevel@tonic-gate  * XXX: functions.
2007c478bd9Sstevel@tonic-gate  */
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate extern	int		prom_heartbeat(int msecs);
2037c478bd9Sstevel@tonic-gate extern	int		prom_get_unum(int syn_code, unsigned long long physaddr,
2047c478bd9Sstevel@tonic-gate 				char *buf, uint_t buflen, int *ustrlen);
2057c478bd9Sstevel@tonic-gate extern	int		prom_serengeti_get_ecacheunum(int cpuid,
2067c478bd9Sstevel@tonic-gate 				unsigned long long physaddr, char *buf,
2077c478bd9Sstevel@tonic-gate 				uint_t buflen, int *ustrlen);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate extern	int		prom_getidprom(caddr_t addr, int size);
2107c478bd9Sstevel@tonic-gate extern	int		prom_getmacaddr(ihandle_t hd, caddr_t ea);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate  * CPU Control Group: MP's only.
2147c478bd9Sstevel@tonic-gate  */
215fa9e4066Sahrens extern	int		prom_startcpu(pnode_t node, caddr_t pc, int arg);
2167c478bd9Sstevel@tonic-gate extern	int		prom_startcpu_bycpuid(int cpuid, caddr_t pc, int arg);
2177c478bd9Sstevel@tonic-gate extern	int		prom_stopcpu_bycpuid(int);
2187c478bd9Sstevel@tonic-gate extern	int		prom_sunfire_cpu_off(void);	/* SunFire only */
219fa9e4066Sahrens extern	int		prom_wakeupcpu(pnode_t node);
220fa9e4066Sahrens extern	int		prom_serengeti_wakeupcpu(pnode_t node);
2217c478bd9Sstevel@tonic-gate extern	int		prom_hotaddcpu(int cpuid);
2227c478bd9Sstevel@tonic-gate extern	int		prom_hotremovecpu(int cpuid);
2237c478bd9Sstevel@tonic-gate extern	void		promsafe_pause_cpus(void);
2247c478bd9Sstevel@tonic-gate extern	void		promsafe_xc_attention(cpuset_t cpuset);
225fa9e4066Sahrens extern	int		prom_serengeti_cpu_off(pnode_t node);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate  * Set trap table
2297c478bd9Sstevel@tonic-gate  */
2307c478bd9Sstevel@tonic-gate extern	void		prom_set_traptable(void *tba_addr);
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate  * Power-off
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate extern	void		prom_power_off(void);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /*
2387c478bd9Sstevel@tonic-gate  * sunfire attach/detach
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate extern	int		prom_sunfire_attach_board(uint_t board);
2417c478bd9Sstevel@tonic-gate extern	int		prom_sunfire_detach_board(uint_t board);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * Serengeti console switch
2457c478bd9Sstevel@tonic-gate  */
2467c478bd9Sstevel@tonic-gate extern	char		*prom_serengeti_set_console_input(char *new_value);
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate /*
2497c478bd9Sstevel@tonic-gate  * Serengeti attach/detach
2507c478bd9Sstevel@tonic-gate  */
2517c478bd9Sstevel@tonic-gate extern	int		prom_serengeti_attach_board(uint_t node, uint_t board);
2527c478bd9Sstevel@tonic-gate extern	int		prom_serengeti_detach_board(uint_t node, uint_t board);
2537c478bd9Sstevel@tonic-gate extern	int		prom_serengeti_tunnel_switch(uint_t node, uint_t board);
2547c478bd9Sstevel@tonic-gate 
25525cf1a30Sjl /*
25625cf1a30Sjl  * OPL-specific routines
25725cf1a30Sjl  */
25825cf1a30Sjl extern	void		prom_opl_get_tod(time_t *time, int64_t *stickval);
25925cf1a30Sjl extern	void		prom_opl_set_diff(int64_t diff);
26025cf1a30Sjl extern	int		prom_attach_notice(int bn);
26125cf1a30Sjl extern	int		prom_detach_notice(int bn);
26225cf1a30Sjl extern	int		prom_opl_switch_console(int bn);
26325cf1a30Sjl 
2647c478bd9Sstevel@tonic-gate /*
2657c478bd9Sstevel@tonic-gate  * The client program implementation is required to provide a wrapper
2667c478bd9Sstevel@tonic-gate  * to the client handler, for the 32 bit client program to 64 bit cell-sized
2677c478bd9Sstevel@tonic-gate  * client interface handler (switch stack, etc.).  This function is not
2687c478bd9Sstevel@tonic-gate  * to be used externally!
2697c478bd9Sstevel@tonic-gate  */
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate extern	int		client_handler(void *cif_handler, void *arg_array);
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * The 'format' of the "translations" property in the 'mmu' node ...
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate struct translation {
2787c478bd9Sstevel@tonic-gate 	uint32_t virt_hi;	/* upper 32 bits of vaddr */
2797c478bd9Sstevel@tonic-gate 	uint32_t virt_lo;	/* lower 32 bits of vaddr */
2807c478bd9Sstevel@tonic-gate 	uint32_t size_hi;	/* upper 32 bits of size in bytes */
2817c478bd9Sstevel@tonic-gate 	uint32_t size_lo;	/* lower 32 bits of size in bytes */
2827c478bd9Sstevel@tonic-gate 	uint32_t tte_hi;	/* higher 32 bites of tte */
2837c478bd9Sstevel@tonic-gate 	uint32_t tte_lo;	/* lower 32 bits of tte */
2847c478bd9Sstevel@tonic-gate };
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate #endif
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate #endif /* _SYS_PROM_PLAT_H */
291