Rev 1764 | Rev 1772 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1764 | Rev 1771 | ||
|---|---|---|---|
| Line 29... | Line 29... | ||
| 29 | #include "ofw.h" |
29 | #include "ofw.h" |
| 30 | #include <printf.h> |
30 | #include <printf.h> |
| 31 | #include <asm.h> |
31 | #include <asm.h> |
| 32 | 32 | ||
| 33 | #define MAX_OFW_ARGS 10 |
33 | #define MAX_OFW_ARGS 10 |
| 34 | #define BUF_SIZE 1024 |
- | |
| 35 | - | ||
| 36 | typedef unsigned int ofw_arg_t; |
- | |
| 37 | typedef unsigned int ihandle; |
- | |
| 38 | typedef unsigned int phandle; |
- | |
| 39 | 34 | ||
| 40 | /** OpenFirmware command structure |
35 | /** OpenFirmware command structure |
| 41 | * |
36 | * |
| 42 | */ |
37 | */ |
| 43 | typedef struct { |
38 | typedef struct { |
| Line 47... | Line 42... | ||
| 47 | ofw_arg_t args[MAX_OFW_ARGS]; /**< List of arguments */ |
42 | ofw_arg_t args[MAX_OFW_ARGS]; /**< List of arguments */ |
| 48 | } ofw_args_t; |
43 | } ofw_args_t; |
| 49 | 44 | ||
| 50 | typedef void (*ofw_entry)(ofw_args_t *); |
45 | typedef void (*ofw_entry)(ofw_args_t *); |
| 51 | 46 | ||
| 52 | - | ||
| 53 | typedef struct { |
- | |
| 54 | unsigned int info; |
- | |
| 55 | unsigned int addr_hi; |
- | |
| 56 | unsigned int addr_lo; |
- | |
| 57 | } pci_addr_t; |
- | |
| 58 | - | ||
| 59 | typedef struct { |
- | |
| 60 | pci_addr_t addr; |
- | |
| 61 | unsigned int size_hi; |
- | |
| 62 | unsigned int size_lo; |
- | |
| 63 | } pci_reg_t; |
- | |
| 64 | - | ||
| 65 | - | ||
| 66 | ofw_entry ofw; |
47 | ofw_entry ofw; |
| 67 | 48 | ||
| 68 | phandle ofw_chosen; |
49 | phandle ofw_chosen; |
| 69 | ihandle ofw_stdout; |
50 | ihandle ofw_stdout; |
| 70 | phandle ofw_root; |
51 | phandle ofw_root; |
| Line 97... | Line 78... | ||
| 97 | 78 | ||
| 98 | return args.args[nargs]; |
79 | return args.args[nargs]; |
| 99 | } |
80 | } |
| 100 | 81 | ||
| 101 | 82 | ||
| 102 | static phandle ofw_find_device(const char *name) |
83 | phandle ofw_find_device(const char *name) |
| 103 | { |
84 | { |
| 104 | return ofw_call("finddevice", 1, 1, NULL, name); |
85 | return ofw_call("finddevice", 1, 1, NULL, name); |
| 105 | } |
86 | } |
| 106 | 87 | ||
| 107 | 88 | ||
| 108 | static int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen) |
89 | int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen) |
| 109 | { |
90 | { |
| 110 | return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen); |
91 | return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen); |
| 111 | } |
92 | } |
| 112 | 93 | ||
| 113 | 94 | ||
| Line 202... | Line 183... | ||
| 202 | } |
183 | } |
| 203 | 184 | ||
| 204 | 185 | ||
| 205 | int ofw_memmap(memmap_t *map) |
186 | int ofw_memmap(memmap_t *map) |
| 206 | { |
187 | { |
| 207 | unsigned int buf[BUF_SIZE]; |
188 | unsigned long buf[BUF_SIZE]; |
| 208 | int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned int) * BUF_SIZE); |
189 | int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf)); |
| 209 | if (ret <= 0) |
190 | if (ret <= 0) |
| 210 | return false; |
191 | return false; |
| 211 | 192 | ||
| 212 | unsigned int ac = ofw_get_address_cells(ofw_memory); |
193 | unsigned int ac = ofw_get_address_cells(ofw_memory); |
| 213 | unsigned int sc = ofw_get_size_cells(ofw_memory); |
194 | unsigned int sc = ofw_get_size_cells(ofw_memory); |
| 214 | 195 | ||
| 215 | int pos; |
196 | int pos; |
| 216 | map->total = 0; |
197 | map->total = 0; |
| 217 | map->count = 0; |
198 | map->count = 0; |
| 218 | for (pos = 0; (pos < ret / sizeof(unsigned int)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) { |
199 | for (pos = 0; (pos < ret / sizeof(unsigned long)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) { |
| 219 | void * start = (void *) buf[pos + ac - 1]; |
200 | void * start = (void *) buf[pos + ac - 1]; |
| 220 | unsigned int size = buf[pos + ac + sc - 1]; |
201 | unsigned int size = buf[pos + ac + sc - 1]; |
| 221 | 202 | ||
| 222 | if (size > 0) { |
203 | if (size > 0) { |
| 223 | map->zones[map->count].start = start; |
204 | map->zones[map->count].start = start; |
| Line 231... | Line 212... | ||
| 231 | 212 | ||
| 232 | int ofw_screen(screen_t *screen) |
213 | int ofw_screen(screen_t *screen) |
| 233 | { |
214 | { |
| 234 | char device_name[BUF_SIZE]; |
215 | char device_name[BUF_SIZE]; |
| 235 | 216 | ||
| 236 | if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(char) * BUF_SIZE) <= 0) |
217 | if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0) |
| 237 | return false; |
218 | return false; |
| 238 | 219 | ||
| 239 | phandle device = ofw_find_device(device_name); |
220 | phandle device = ofw_find_device(device_name); |
| 240 | if (device == -1) |
221 | if (device == -1) |
| 241 | return false; |
222 | return false; |
| Line 256... | Line 237... | ||
| 256 | return false; |
237 | return false; |
| 257 | 238 | ||
| 258 | return true; |
239 | return true; |
| 259 | } |
240 | } |
| 260 | 241 | ||
| 261 | - | ||
| 262 | int ofw_keyboard(keyboard_t *keyboard) |
- | |
| 263 | { |
- | |
| 264 | char device_name[BUF_SIZE]; |
- | |
| 265 | - | ||
| 266 | if (ofw_get_property(ofw_aliases, "macio", device_name, sizeof(char) * BUF_SIZE) <= 0) |
- | |
| 267 | return false; |
- | |
| 268 | - | ||
| 269 | phandle device = ofw_find_device(device_name); |
- | |
| 270 | if (device == -1) |
- | |
| 271 | return false; |
- | |
| 272 | - | ||
| 273 | pci_reg_t macio; |
- | |
| 274 | if (ofw_get_property(device, "assigned-addresses", &macio, sizeof(macio)) <= 0) |
- | |
| 275 | return false; |
- | |
| 276 | - | ||
| 277 | keyboard->addr = (void *) macio.addr.addr_lo; |
- | |
| 278 | keyboard->size = macio.size_lo; |
- | |
| 279 | - | ||
| 280 | return true; |
- | |
| 281 | } |
- | |