1 /*        $NetBSD: prom.h,v 1.12 2009/03/14 14:46:02 dsl Exp $        */
2 
3 /*
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Wayne Knowles
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Entry points into PROM firmware functions for MIPS machines
34  */
35 
36 #ifndef _MIPSCO_PROM_H
37 #define _MIPSCO_PROM_H
38 
39 #ifndef _LOCORE
40 #include <sys/types.h>
41 #include <sys/cdefs.h>
42 
43 struct mips_prom {
44 
45           /*
46            * transferred to on hardware reset, configures MIPS boards,
47            * runs diags, check for appropriate auto boot action in
48            * "bootmode" environment variable and performs that action.
49            */
50           void      (*prom_reset)(void) __attribute__((__noreturn__));
51 
52           /*
53            * called to use prom to boot new image.  After the booted
54            * program returns control can either be returned to the
55            * original caller of the exec routine or to the prom monitor.
56            * (to return to the original caller, the new program must
57            * not destroy any text, data, or stack of the parent.  the
58            * new programs stack continues on the parents stack.
59            */
60           int       (*prom_exec)(void);
61 
62           /* re-enter the prom command parser, do not reset prom state          */
63           void      (*prom_restart)(void) __attribute__((__noreturn__));
64 
65           /* reinitialize prom state and re-enter the prom command parser */
66           void      (*prom_reinit)(void) __attribute__((__noreturn__));
67 
68           /* reboot machine using current bootmode setting.  No diags */
69           void      (*prom_reboot)(void) __attribute__((__noreturn__));
70 
71           /* perform an autoboot sequence, no configuration or diags run */
72           void      (*prom_autoboot)(void) __attribute__((__noreturn__));
73 
74           /*
75            * these routines access prom "saio" routines, and may be used
76            * by standalone programs that would like to use prom io
77            */
78           int       (*prom_open)(char *, int, ...);
79           int       (*prom_read)(int, void *, int);
80           int       (*prom_write)(int, void *, int);
81           int       (*prom_ioctl)(int, long, ...);
82           int       (*prom_close)(int);
83           int       (*prom_getchar)(void);
84           int       (*prom_putchar)(int c);
85           void      (*prom_showchar)(int c);
86           char *    (*prom_gets)(char *s);
87           void      (*prom_puts)(const char *);
88           int       (*prom_printf)(const char *, ...);
89 
90           /* prom protocol entry points */
91           void      (*prom_initproto)(void); /* ??? */
92           void      (*prom_protoenable)(void); /* ??? */
93           void      (*prom_protodisable)(void); /* ??? */
94           void      (*prom_getpkt)(void); /* ??? */
95           void      (*prom_putpkt)(void); /* ??? */
96 
97           /*
98            * read-modify-write routine use special CPU board circuitry to
99            * accomplish vme bus r-m-w cycles.
100            */
101           void      (*prom_orw_rmw)(void);
102           void      (*prom_orh_rmw)(void);
103           void      (*prom_orb_rmw)(void);
104           void      (*prom_andw_rmw)(void);
105           void      (*prom_andh_rmw)(void);
106           void      (*prom_andb_rmw)(void);
107 
108           /*
109            * cache control entry points
110            * flushcache is called without arguments and invalidates entire
111            *      contents of both i and d caches
112            * clearcache is called with a base address and length (where
113            *      address is either K0, K1, or physical) and clears both
114            *      i and d cache for entries that alias to specified address
115            *      range.
116            */
117           void      (*prom_flushcache)(void);
118           void      (*prom_clearcache)(void *, size_t);
119 
120           /*
121            * Libc compatible functions
122            */
123           void      (*prom_setjmp)(void);
124           void      (*prom_longjmp)(void);
125           void      (*prom_bevutlb)(void);
126           char *    (*prom_getenv)(const char *name);
127           int       (*prom_setenv)(char *name, char *val);
128           int       (*prom_atob)(char *s);
129           int       (*prom_strcmp)(char *s1, char *s2);
130           int       (*prom_strlen)(char *s);
131           char *    (*prom_strcpy)(char *s1, char *s2);
132           char *    (*prom_strcat)(char *s1, char *s2);
133 
134           /*
135            * command parser entry points
136            */
137           void      (*prom_parser)(void); /* ??? */
138           void      (*prom_range)(void); /* ??? */
139           void      (*prom_argvize)(void); /* ??? */
140           void      (*prom_help)(void);
141 
142           /*
143            * prom commands
144            */
145           void      (*prom_dumpcmd)(void);
146           void      (*prom_setenvcmd)(void);
147           void      (*prom_unsetenvcmd)(void);
148           void      (*prom_bevexcept)(void);
149           void      (*prom_enablecmd)(void);
150           void      (*prom_disablecmd)(void);
151 
152           /*
153            * clear existing fault handlers
154            * used by clients that link to prom on situations where client has
155            * interrupted out of prom code and wish to reenter without being
156            * tripped up by any pending prom timers set earlier.
157            */
158           void      (*prom_clearnofault)(void);
159 
160           void      (*prom_notimpl)(void);
161 
162           /*
163            * PROM_NVGET, PROM_NVSET will get/set information in the NVRAM.
164            * Both of these routines take indexes as opposed to addresses
165            * to guarantee portability between various platforms
166            */
167           int       (*prom_nvget)(int);
168           void      (*prom_nvset)(void);
169 };
170 
171 extern struct mips_prom *callv;
172 
173 extern void prom_init(void);
174 
175 #endif    /* _LOCORE */
176 
177 /*
178  * Macro to help call a prom function
179  */
180 #define MIPS_PROM(func)                 (callv->prom_##func)
181 
182 /*
183  * Return the address for a given prom function number
184  */
185 #define   MIPS_PROM_ENTRY(x)  (0xbfc00000+((x)*8))
186 
187 /*
188  * MIPS PROM firmware functions:
189  *
190  *        MIPS_PROM_RESET               Run diags, check bootmode, reinit.
191  *        MIPS_PROM_EXEC                Load new program image.
192  *        MIPS_PROM_RESTART   Re-enter monitor command loop.
193  *        MIPS_PROM_REINIT    Re-init monitor, then cmd loop.
194  *        MIPS_PROM_REBOOT    Check bootmode, no config.
195  *        MIPS_PROM_AUTOBOOT  Autoboot the system.
196  *
197  * The following routines access PROM saio routines and may be used by
198  * standalone programs that would like to use PROM I/O:
199  *
200  *        MIPS_PROM_OPEN                Open a file.
201  *        MIPS_PROM_READ                Read from a file.
202  *        MIPS_PROM_WRITE               Write to a file.
203  *        MIPS_PROM_IOCTL               Ioctl on a file.
204  *        MIPS_PROM_CLOSE               Close a file.
205  *        MIPS_PROM_GETCHAR   Read character from console.
206  *        MIPS_PROM_PUTCHAR   Put character on console.
207  *        MIPS_PROM_SHOWCHAR  Show a char visibly.
208  *        MIPS_PROM_GETS                gets with editing.
209  *        MIPS_PROM_PUTS                Put string to console.
210  *        MIPS_PROM_PRINTF    Kernel style printf to console.
211  *
212  *  PROM protocol entry points:
213  *
214  *        MIPS_PROM_INITPROTO Initialize protocol.
215  *        MIPS_PROM_PROTOENABLE         Enable protocol mode.
216  *        MIPS_PROM_PROTODISABLE        Disable protocol mode.
217  *        MIPS_PROM_GETPKT    Get protocol packet.
218  *        MIPS_PROM_PUTPKT    Put protocol packet.
219  *
220  *   Atomic Read-Modify-Write functions
221  *
222  *        MIPS_PROM_RMW_OR32  r-m-w OR word.
223  *        MIPS_PROM_RMW_OR16  r-m-w OR halfword.
224  *        MIPS_PROM_RMW_OR8   r-m-w OR or byte.
225  *        MIPS_PROM_RMW_AND32 r-m-w AND word.
226  *        MIPS_PROM_RMW_AND16 r-m-w AND halfword.
227  *        MIPS_PROM_RMW_AND8  r-m-w AND byte.
228  *
229  *        MIPS_PROM_FLUSHCACHE          Flush entire cache ().
230  *        MIPS_PROM_CLEARCACHE          Clear I & D cache in range (addr, len).
231  *        MIPS_PROM_SETJMP    Save registers in a buffer.
232  *        MIPS_PROM_LONGJMP   Get register back from buffer.
233  *        MIPS_PROM_BEVUTLB   utlbmiss boot exception vector
234  *        MIPS_PROM_GETENV    Gets a string from system environment.
235  *        MIPS_PROM_SETENV    Sets a string in system environment.
236  *        MIPS_PROM_ATOB                Converts ascii string to number.
237  *        MIPS_PROM_STRCMP    Compares strings (strcmp).
238  *        MIPS_PROM_STRLEN    Length of string (strlen).
239  *        MIPS_PROM_STRCPY    Copies string (strcpy).
240  *        MIPS_PROM_STRCAT    Appends string (strcat).
241  *        MIPS_PROM_PARSER    Command parser.
242  *        MIPS_PROM_RANGE               Address range parser
243  *        MIPS_PROM_ARGVIZE   Parses string to argc,argv.
244  *        MIPS_PROM_HELP                Help on prom commands.
245  *        MIPS_PROM_DUMP                Dump memory command.
246  *        MIPS_PROM_SETENVCMD Setenv command.
247  *        MIPS_PROM_UNSETENVCMD         Unsetenv command.
248  *        MIPS_PROM_PRINTENV  Print environment command.
249  *        MIPS_PROM_BEVEXCEPT General boot exception vector
250  *        MIPS_PROM_ENABLE    Performs prom enable command.
251  *        MIPS_PROM_DISABLE   Performs prom disable command.
252  *        MIPS_PROM_CLEARNOFAULT        Clear existing fault handlers.
253  *        MIPS_PROM_NOTIMPL   Guaranteed to be not implemented
254  *        MIPS_PROM_NVGET               Read bytes from NVRAM
255  *        MIPS_PROM_NVSET               Write bytes to NVRAM
256  */
257 
258 #define   MIPS_PROM_RESET               MIPS_PROM_ENTRY(0)
259 #define   MIPS_PROM_EXEC                MIPS_PROM_ENTRY(1)
260 #define   MIPS_PROM_RESTART   MIPS_PROM_ENTRY(2)
261 #define   MIPS_PROM_REINIT    MIPS_PROM_ENTRY(3)
262 #define   MIPS_PROM_REBOOT    MIPS_PROM_ENTRY(4)
263 #define   MIPS_PROM_AUTOBOOT  MIPS_PROM_ENTRY(5)
264 #define   MIPS_PROM_OPEN                MIPS_PROM_ENTRY(6)
265 #define   MIPS_PROM_READ                MIPS_PROM_ENTRY(7)
266 #define   MIPS_PROM_WRITE               MIPS_PROM_ENTRY(8)
267 #define   MIPS_PROM_IOCTL               MIPS_PROM_ENTRY(9)
268 #define   MIPS_PROM_CLOSE               MIPS_PROM_ENTRY(10)
269 #define   MIPS_PROM_GETCHAR   MIPS_PROM_ENTRY(11)
270 #define   MIPS_PROM_PUTCHAR   MIPS_PROM_ENTRY(12)
271 #define   MIPS_PROM_SHOWCHAR  MIPS_PROM_ENTRY(13)
272 #define   MIPS_PROM_GETS                MIPS_PROM_ENTRY(14)
273 #define   MIPS_PROM_PUTS                MIPS_PROM_ENTRY(15)
274 #define   MIPS_PROM_PRINTF    MIPS_PROM_ENTRY(16)
275 #define   MIPS_PROM_INITPROTO MIPS_PROM_ENTRY(17)
276 #define   MIPS_PROM_PROTOENABLE         MIPS_PROM_ENTRY(18)
277 #define   MIPS_PROM_PROTODISABLE        MIPS_PROM_ENTRY(19)
278 #define   MIPS_PROM_GETPKT    MIPS_PROM_ENTRY(20)
279 #define   MIPS_PROM_PUTPKT    MIPS_PROM_ENTRY(21)
280 #define   MIPS_PROM_ORW_RMW   MIPS_PROM_ENTRY(22)
281 #define   MIPS_PROM_ORH_RMW   MIPS_PROM_ENTRY(23)
282 #define   MIPS_PROM_ORB_RMW   MIPS_PROM_ENTRY(24)
283 #define   MIPS_PROM_ANDW_RMW  MIPS_PROM_ENTRY(25)
284 #define   MIPS_PROM_ANDH_RMW  MIPS_PROM_ENTRY(26)
285 #define   MIPS_PROM_ANDB_RMW  MIPS_PROM_ENTRY(27)
286 #define   MIPS_PROM_FLUSHCACHE          MIPS_PROM_ENTRY(28)
287 #define   MIPS_PROM_CLEARCACHE          MIPS_PROM_ENTRY(29)
288 #define   MIPS_PROM_SETJMP    MIPS_PROM_ENTRY(30)
289 #define   MIPS_PROM_LONGJMP   MIPS_PROM_ENTRY(31)
290 #define   MIPS_PROM_BEVUTLB   MIPS_PROM_ENTRY(32)
291 #define   MIPS_PROM_GETENV    MIPS_PROM_ENTRY(33)
292 #define   MIPS_PROM_SETENV    MIPS_PROM_ENTRY(34)
293 #define   MIPS_PROM_ATOB                MIPS_PROM_ENTRY(35)
294 #define   MIPS_PROM_STRCMP    MIPS_PROM_ENTRY(36)
295 #define   MIPS_PROM_STRLEN    MIPS_PROM_ENTRY(37)
296 #define   MIPS_PROM_STRCPY    MIPS_PROM_ENTRY(38)
297 #define   MIPS_PROM_STRCAT    MIPS_PROM_ENTRY(39)
298 #define   MIPS_PROM_PARSER    MIPS_PROM_ENTRY(40)
299 #define   MIPS_PROM_RANGE               MIPS_PROM_ENTRY(41)
300 #define   MIPS_PROM_ARGVIZE   MIPS_PROM_ENTRY(42)
301 #define   MIPS_PROM_HELP                MIPS_PROM_ENTRY(43)
302 #define   MIPS_PROM_DUMP                MIPS_PROM_ENTRY(44)
303 #define   MIPS_PROM_SETENVCMD MIPS_PROM_ENTRY(45)
304 #define   MIPS_PROM_UNSETENVCMD         MIPS_PROM_ENTRY(46)
305 #define   MIPS_PROM_PRINTENV  MIPS_PROM_ENTRY(47)
306 #define   MIPS_PROM_BEVEXCEPT MIPS_PROM_ENTRY(48)
307 #define   MIPS_PROM_ENABLE    MIPS_PROM_ENTRY(49)
308 #define   MIPS_PROM_DISABLE   MIPS_PROM_ENTRY(50)
309 #define   MIPS_PROM_CLEARNOFAULT        MIPS_PROM_ENTRY(51)
310 #define   MIPS_PROM_NOTIMPLEMENT        MIPS_PROM_ENTRY(52)
311 #define MIPS_PROM_NVGET                 MIPS_PROM_ENTRY(53)
312 #define MIPS_PROM_NVSET                 MIPS_PROM_ENTRY(54)
313 
314 #if defined(_KERNEL) && !defined(__ASSEMBLER__)
315 extern void prom_init (void);
316 extern int prom_getconsole (void);
317 #endif
318 
319 #endif /* ! _MIPSCO_PROM_H */
320