1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/* $NetBSD: promlib.h,v 1.27 2022/01/22 11:49:16 thorpej Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* OPENPROM functions. These are here mainly to hide the OPENPROM interface
* from the rest of the kernel.
*/
#ifndef _SPARC_PROMLIB_H_
#define _SPARC_PROMLIB_H_
#ifdef _KERNEL_OPT
#include "opt_multiprocessor.h"
#endif
#include <sys/device.h> /* for devhandle_t */
#include <machine/idprom.h>
#include <machine/bsd_openprom.h>
#include <machine/openfirm.h>
/*
* A set of methods to access the firmware.
* We use this to support various versions of Open Boot Prom
* or Open Firmware implementations.
*/
struct promops {
int po_version; /* PROM version number */
#define PROM_OLDMON 0
#define PROM_OBP_V0 1
#define PROM_OBP_V2 2
#define PROM_OBP_V3 3
#define PROM_OPENFIRM 4
int po_revision; /* revision level */
int po_stdin; /* stdio handles */
int po_stdout; /* */
void *po_bootcookie;
/* Access to boot arguments */
const char *(*po_bootpath)(void);
const char *(*po_bootfile)(void);
const char *(*po_bootargs)(void);
/* I/O functions */
int (*po_getchar)(void);
int (*po_peekchar)(void);
void (*po_putchar)(int);
void (*po_putstr)(const char *, int);
int (*po_open)(const char *);
void (*po_close)(int);
int (*po_read)(int, void *, int);
int (*po_write)(int, const void *, int);
int (*po_seek)(int, u_quad_t);
int (*po_instance_to_package)(int);
/* Misc functions (common in OBP 0,2,3) */
void (*po_halt)(void) __attribute__((__noreturn__));
void (*po_reboot)(const char *) __attribute__((__noreturn__));
void (*po_abort)(void);
void (*po_interpret)(const char *);
void (*po_setcallback)(void (*)(void));
int (*po_ticks)(void);
void *po_tickdata;
/* sun4/sun4c only */
void (*po_setcontext)(int ctxt, void *va, int pmeg);
/* MP functions (OBP v3 only) */
int (*po_cpustart)(int, struct openprom_addr *, int, void *);
int (*po_cpustop)(int);
int (*po_cpuidle)(int);
int (*po_cpuresume)(int);
/* Device node traversal (OBP v0, v2, v3; but not sun4) */
int (*po_firstchild)(int);
int (*po_nextsibling)(int);
/* Device node properties */
int (*po_getproplen)(int, const char *);
int (*po_getprop)(int, const char *, void *, int);
int (*po_setprop)(int, const char *, const void *, int);
char *(*po_nextprop)(int, const char *);
int (*po_finddevice)(const char *);
/* devhandle_t interface */
devhandle_t (*po_node_to_devhandle)(devhandle_t, int);
int (*po_devhandle_to_node)(devhandle_t);
};
extern struct promops promops;
/*
* Memory description array.
* Same as version 2 rom meminfo property.
*/
struct memarr {
long zero;
u_long addr;
u_long len;
};
int prom_makememarr(struct memarr *, int, int);
#define MEMARR_AVAILPHYS 0
#define MEMARR_TOTALPHYS 1
struct idprom *prom_getidprom(void);
void prom_getether(int, u_char *);
bool prom_get_node_ether(int, u_char*);
const char *prom_pa_location(u_int, u_int);
void prom_init(void); /* To setup promops */
/* Utility routines */
int prom_getprop(int, const char *, size_t, int *, void *);
int prom_getpropint(int, const char *, int);
uint64_t prom_getpropuint64(int, const char *, uint64_t);
char *prom_getpropstring(int, const char *);
char *prom_getpropstringA(int, const char *, char *, size_t);
void prom_printf(const char *, ...);
int prom_findroot(void);
int prom_findnode(int, const char *);
int prom_search(int, const char *);
int prom_opennode(const char *);
int prom_node_has_property(int, const char *);
int prom_getoptionsnode(void);
int prom_getoption(const char *, char *, int);
#define findroot() prom_findroot()
#define findnode(node,name) prom_findnode(node,name)
#define opennode(name) prom_opennode(name)
#define node_has_property(node,prop) prom_node_has_property(node,prop)
void prom_halt(void) __attribute__((__noreturn__));
void prom_boot(char *) __attribute__((__noreturn__));
#if defined(MULTIPROCESSOR)
#define callrom() do { \
mp_pause_cpus(); \
prom_abort(); \
mp_resume_cpus(); \
} while (0)
#else
#define callrom() prom_abort()
#endif
#define prom_version() (promops.po_version)
#define prom_revision() (promops.po_revision)
#define prom_stdin() (promops.po_stdin)
#define prom_stdout() (promops.po_stdout)
#define _prom_halt() ((*promops.po_halt)(/*void*/))
#define _prom_boot(a) ((*promops.po_reboot)(a))
#define prom_abort() ((*promops.po_abort)(/*void*/))
#define prom_interpret(a) ((*promops.po_interpret)(a))
#define prom_setcallback(f) ((*promops.po_setcallback)(f))
#define prom_setcontext(c,a,p) ((*promops.po_setcontext)(c,a,p))
#define prom_getbootpath() ((*promops.po_bootpath)(/*void*/))
#define prom_getbootfile() ((*promops.po_bootfile)(/*void*/))
#define prom_getbootargs() ((*promops.po_bootargs)(/*void*/))
#define prom_ticks() ((*promops.po_ticks)(/*void*/))
#define prom_open(name) ((*promops.po_open)(name))
#define prom_close(fd) ((*promops.po_close)(fd))
#define prom_instance_to_package(fd) \
((*promops.po_instance_to_package)(fd))
#define prom_read(fd,b,n) ((*promops.po_read)(fd,b,n))
#define prom_write(fd,b,n) ((*promops.po_write)(fd,b,n))
#define prom_seek(fd,o) ((*promops.po_seek)(fd,o))
#define prom_getchar() ((*promops.po_getchar)(/*void*/))
#define prom_peekchar() ((*promops.po_peekchar)(/*void*/))
#define prom_putchar(c) ((*promops.po_putchar)(c))
#define prom_putstr(b,n) ((*promops.po_putstr)(b,n))
/* Node traversal */
#define prom_firstchild(node) ((*promops.po_firstchild)(node))
#define prom_nextsibling(node) ((*promops.po_nextsibling)(node))
#define prom_proplen(node,name) ((*promops.po_getproplen)(node, name))
#define _prom_getprop(node, name, buf, len) \
((*promops.po_getprop)(node, name, buf, len))
#define prom_setprop(node, name, value, len) \
((*promops.po_setprop)(node, name, value, len))
#define prom_nextprop(node,name) ((*promops.po_nextprop)(node, name))
#define prom_finddevice(name) ((*promops.po_finddevice)(name))
#define firstchild(node) prom_firstchild(node)
#define nextsibling(node) prom_nextsibling(node)
#define prom_getproplen(node,name) prom_proplen(node, name)
/* devhandle_t interface */
#define prom_node_to_devhandle(s, n) ((*promops.po_node_to_devhandle)((s), (n)))
#define prom_devhandle_to_node(dh) ((*promops.po_devhandle_to_node)(dh))
/* MP stuff - not currently used */
#define prom_cpustart(m,a,c,pc) ((*promops.po_cpustart)(m,a,c,pc))
#define prom_cpustop(m) ((*promops.po_cpustop)(m))
#define prom_cpuidle(m) ((*promops.po_cpuidle)(m))
#define prom_cpuresume(m) ((*promops.po_cpuresume)(m))
extern void *romp; /* PROM-supplied argument (see locore) */
#ifdef _KERNEL
#define OBP_DEVICE_CALL_REGISTER(_n_, _c_) \
DEVICE_CALL_REGISTER(obp_device_calls, _n_, _c_)
#endif /* _KERNEL */
#endif /* _SPARC_PROMLIB_H_ */
|