ieee1275: block-size deblocker support method
[grub.git] / include / grub / ieee1275 / ieee1275.h
1 /* ieee1275.h - Access the Open Firmware client interface.  */
2 /*
3  *  GRUB  --  GRand Unified Bootloader
4  *  Copyright (C) 2003,2004,2005,2007,2008,2009  Free Software Foundation, Inc.
5  *
6  *  GRUB is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  GRUB is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef GRUB_IEEE1275_HEADER
21 #define GRUB_IEEE1275_HEADER    1
22
23 #include <grub/err.h>
24 #include <grub/types.h>
25 #include <grub/machine/ieee1275.h>
26
27 struct grub_ieee1275_mem_region
28 {
29   unsigned int start;
30   unsigned int size;
31 };
32
33 #define IEEE1275_MAX_PROP_LEN   8192
34 #define IEEE1275_MAX_PATH_LEN   256
35
36 #ifndef IEEE1275_CALL_ENTRY_FN
37 #define IEEE1275_CALL_ENTRY_FN(args) (*grub_ieee1275_entry_fn) (args)
38 #endif
39
40 /* All backcalls to the firmware is done by calling an entry function
41    which was passed to us from the bootloader.  When doing the backcall,
42    a structure is passed which specifies what the firmware should do.
43    NAME is the requested service.  NR_INS and NR_OUTS is the number of
44    passed arguments and the expected number of return values, resp. */
45 struct grub_ieee1275_common_hdr
46 {
47   grub_ieee1275_cell_t name;
48   grub_ieee1275_cell_t nr_ins;
49   grub_ieee1275_cell_t nr_outs;
50 };
51
52 #define INIT_IEEE1275_COMMON(p, xname, xins, xouts) \
53   (p)->name = (grub_ieee1275_cell_t) xname; \
54   (p)->nr_ins = (grub_ieee1275_cell_t) xins; \
55   (p)->nr_outs = (grub_ieee1275_cell_t) xouts
56
57 typedef grub_uint32_t grub_ieee1275_ihandle_t;
58 typedef grub_uint32_t grub_ieee1275_phandle_t;
59
60 #define GRUB_IEEE1275_PHANDLE_INVALID  ((grub_ieee1275_phandle_t) -1)
61
62 struct grub_ieee1275_devalias
63 {
64   char *name;
65   char *path;
66   char *type;
67   char *parent_path;
68   grub_ieee1275_phandle_t phandle;
69   grub_ieee1275_phandle_t parent_dev;
70 };
71
72 extern void (*EXPORT_VAR(grub_ieee1275_net_config)) (const char *dev,
73                                                      char **device,
74                                                      char **path,
75                                                      char *bootargs);
76
77 /* Maps a device alias to a pathname.  */
78 extern grub_ieee1275_phandle_t EXPORT_VAR(grub_ieee1275_chosen);
79 extern grub_ieee1275_ihandle_t EXPORT_VAR(grub_ieee1275_mmu);
80 #ifdef __i386__
81 #define GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE  __attribute__ ((regparm(3)))
82 #else
83 #define GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE
84 #endif
85
86 extern int (* EXPORT_VAR(grub_ieee1275_entry_fn)) (void *) GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE;
87
88 /* Static heap, used only if FORCE_CLAIM is set,
89    happens on Open Hack'Ware. Should be in platform-specific
90    header but is used only on PPC anyway.
91 */
92 #define GRUB_IEEE1275_STATIC_HEAP_START 0x1000000
93 #define GRUB_IEEE1275_STATIC_HEAP_LEN   0x1000000
94
95
96 enum grub_ieee1275_flag
97 {
98   /* Old World Macintosh firmware fails seek when "dev:0" is opened.  */
99   GRUB_IEEE1275_FLAG_NO_PARTITION_0,
100
101   /* Apple firmware runs in translated mode and requires use of the "map"
102      method.  Other firmware runs in untranslated mode and doesn't like "map"
103      calls.  */
104   GRUB_IEEE1275_FLAG_REAL_MODE,
105
106   /* CHRP specifies partitions are numbered from 1 (partition 0 refers to the
107      whole disk). However, CodeGen firmware numbers partitions from 0.  */
108   GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS,
109
110   /* CodeGen firmware does not correctly implement "output-device output" */
111   GRUB_IEEE1275_FLAG_BROKEN_OUTPUT,
112
113   /* OLPC / XO firmware hangs when accessing USB devices.  */
114   GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY,
115
116   /* Open Hack'Ware stops when trying to set colors */
117   GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS,
118
119   /* Open Hack'Ware stops when grub_ieee1275_interpret is used.  */
120   GRUB_IEEE1275_FLAG_CANNOT_INTERPRET,
121
122   /* Open Hack'Ware has no memory map, just claim what we need.  */
123   GRUB_IEEE1275_FLAG_FORCE_CLAIM,
124
125   /* Open Hack'Ware don't support the ANSI sequence.  */
126   GRUB_IEEE1275_FLAG_NO_ANSI,
127
128   /* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB.  */
129   GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM,
130
131   /* OLPC / XO firmware has the cursor ON/OFF routines.  */
132   GRUB_IEEE1275_FLAG_HAS_CURSORONOFF,
133
134   /* Some PowerMacs claim to use 2 address cells but in fact use only 1. 
135      Other PowerMacs claim to use only 1 and really do so. Always assume
136      1 address cell is used on PowerMacs.
137    */
138   GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS,
139
140   GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS,
141
142   GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX,
143
144   GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN,
145
146   GRUB_IEEE1275_FLAG_BROKEN_REPEAT,
147
148   GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN,
149 };
150
151 extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);
152 extern void EXPORT_FUNC(grub_ieee1275_set_flag) (enum grub_ieee1275_flag flag);
153
154 \f
155
156
157 void EXPORT_FUNC(grub_ieee1275_init) (void);
158 int EXPORT_FUNC(grub_ieee1275_finddevice) (const char *name,
159                                            grub_ieee1275_phandle_t *phandlep);
160 int EXPORT_FUNC(grub_ieee1275_get_property) (grub_ieee1275_phandle_t phandle,
161                                              const char *property, void *buf,
162                                              grub_size_t size,
163                                              grub_ssize_t *actual);
164 int EXPORT_FUNC(grub_ieee1275_get_integer_property) (grub_ieee1275_phandle_t phandle,
165                                                      const char *property, grub_uint32_t *buf,
166                                                      grub_size_t size,
167                                                      grub_ssize_t *actual);
168 int EXPORT_FUNC(grub_ieee1275_next_property) (grub_ieee1275_phandle_t phandle,
169                                               char *prev_prop, char *prop);
170 int EXPORT_FUNC(grub_ieee1275_get_property_length)
171      (grub_ieee1275_phandle_t phandle, const char *prop, grub_ssize_t *length);
172 int EXPORT_FUNC(grub_ieee1275_instance_to_package)
173      (grub_ieee1275_ihandle_t ihandle, grub_ieee1275_phandle_t *phandlep);
174 int EXPORT_FUNC(grub_ieee1275_package_to_path) (grub_ieee1275_phandle_t phandle,
175                                                 char *path, grub_size_t len,
176                                                 grub_ssize_t *actual);
177 int EXPORT_FUNC(grub_ieee1275_instance_to_path)
178      (grub_ieee1275_ihandle_t ihandle, char *path, grub_size_t len,
179       grub_ssize_t *actual);
180 int EXPORT_FUNC(grub_ieee1275_write) (grub_ieee1275_ihandle_t ihandle,
181                                       const void *buffer, grub_size_t len,
182                                       grub_ssize_t *actualp);
183 int EXPORT_FUNC(grub_ieee1275_read) (grub_ieee1275_ihandle_t ihandle,
184                                      void *buffer, grub_size_t len,
185                                      grub_ssize_t *actualp);
186 int EXPORT_FUNC(grub_ieee1275_seek) (grub_ieee1275_ihandle_t ihandle,
187                                      grub_disk_addr_t pos,
188                                      grub_ssize_t *result);
189 int EXPORT_FUNC(grub_ieee1275_peer) (grub_ieee1275_phandle_t node,
190                                      grub_ieee1275_phandle_t *result);
191 int EXPORT_FUNC(grub_ieee1275_child) (grub_ieee1275_phandle_t node,
192                                       grub_ieee1275_phandle_t *result);
193 int EXPORT_FUNC(grub_ieee1275_parent) (grub_ieee1275_phandle_t node,
194                                        grub_ieee1275_phandle_t *result);
195 int EXPORT_FUNC(grub_ieee1275_interpret) (const char *command,
196                                           grub_ieee1275_cell_t *catch);
197 int EXPORT_FUNC(grub_ieee1275_enter) (void);
198 void EXPORT_FUNC(grub_ieee1275_exit) (void) __attribute__ ((noreturn));
199 int EXPORT_FUNC(grub_ieee1275_open) (const char *node,
200                                      grub_ieee1275_ihandle_t *result);
201 int EXPORT_FUNC(grub_ieee1275_close) (grub_ieee1275_ihandle_t ihandle);
202 int EXPORT_FUNC(grub_ieee1275_claim) (grub_addr_t addr, grub_size_t size,
203                                       unsigned int align, grub_addr_t *result);
204 int EXPORT_FUNC(grub_ieee1275_release) (grub_addr_t addr, grub_size_t size);
205 int EXPORT_FUNC(grub_ieee1275_set_property) (grub_ieee1275_phandle_t phandle,
206                                              const char *propname,
207                                              const void *buf,
208                                              grub_size_t size,
209                                              grub_ssize_t *actual);
210 int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle,
211                                           int index, int r, int g, int b);
212 int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs);
213 int EXPORT_FUNC(grub_ieee1275_set_address) (grub_ieee1275_ihandle_t ihandle,
214                                             grub_uint32_t target,
215                                             grub_uint32_t lun);
216 int EXPORT_FUNC(grub_ieee1275_no_data_command) (grub_ieee1275_ihandle_t ihandle,
217                                                 const void *cmd_addr,
218                                                 grub_ssize_t *result);
219 int EXPORT_FUNC(grub_ieee1275_decode_unit4) (grub_ieee1275_ihandle_t ihandle,
220                                              void *addr, grub_size_t size,
221                                              grub_uint32_t *phy_lo,
222                                              grub_uint32_t *phy_hi,
223                                              grub_uint32_t *lun_lo,
224                                              grub_uint32_t *lun_hi);
225 char *EXPORT_FUNC(grub_ieee1275_encode_uint4) (grub_ieee1275_ihandle_t ihandle,
226                                              grub_uint32_t phy_lo,
227                                              grub_uint32_t phy_hi,
228                                              grub_uint32_t lun_lo,
229                                              grub_uint32_t lun_hi,
230                                              grub_size_t *size);
231 int EXPORT_FUNC(grub_ieee1275_get_block_size) (grub_ieee1275_ihandle_t ihandle);
232
233 grub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);
234
235 int
236 EXPORT_FUNC(grub_ieee1275_map) (grub_addr_t phys, grub_addr_t virt,
237                                 grub_size_t size, grub_uint32_t mode);
238
239 char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path);
240 char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);
241 int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook)
242                                                 (struct grub_ieee1275_devalias *
243                                                  alias));
244 char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path);
245 char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path);
246 char *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path);
247 char *EXPORT_FUNC(grub_ieee1275_get_devname) (const char *path);
248
249 void EXPORT_FUNC(grub_ieee1275_devalias_init_iterator) (struct grub_ieee1275_devalias *alias);
250 void EXPORT_FUNC(grub_ieee1275_devalias_free) (struct grub_ieee1275_devalias *alias);
251 int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *alias);
252 void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
253 void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
254                                                 struct grub_ieee1275_devalias *alias);
255
256 #define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)
257
258 #define FOR_IEEE1275_DEVCHILDREN(devpath, alias) for (grub_ieee1275_children_first ((devpath), &(alias)); \
259                                                       (alias).name;     \
260                                                       grub_ieee1275_children_peer (&(alias)))
261
262 #endif /* ! GRUB_IEEE1275_HEADER */