Changeset 63cda71 in mainline for boot/genarch/ofw.c
- Timestamp:
- 2006-07-13T14:58:57Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 94d614e
- Parents:
- eda7bf81
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/genarch/ofw.c
reda7bf81 r63cda71 27 27 */ 28 28 29 #include "ofw.h" 29 #include <ofw.h> 30 #include <ofwarch.h> 30 31 #include <printf.h> 31 32 #include <asm.h> … … 41 42 phandle ofw_aliases; 42 43 44 void ofw_init(void) 45 { 46 ofw_chosen = ofw_find_device("/chosen"); 47 if (ofw_chosen == -1) 48 halt(); 49 50 if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) 51 ofw_stdout = 0; 52 53 ofw_root = ofw_find_device("/"); 54 if (ofw_root == -1) { 55 puts("\r\nError: Unable to find / device, halted.\r\n"); 56 halt(); 57 } 58 59 if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) { 60 puts("\r\nError: Unable to get mmu property, halted.\r\n"); 61 halt(); 62 } 63 64 ofw_memory = ofw_find_device("/memory"); 65 if (ofw_memory == -1) { 66 puts("\r\nError: Unable to find /memory device, halted.\r\n"); 67 halt(); 68 } 69 70 ofw_aliases = ofw_find_device("/aliases"); 71 if (ofw_aliases == -1) { 72 puts("\r\nError: Unable to find /aliases device, halted.\r\n"); 73 halt(); 74 } 75 } 76 77 43 78 static unsigned long ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...) 44 79 { … … 80 115 81 116 82 staticunsigned int ofw_get_address_cells(const phandle device)83 { 84 unsigned int ret ;117 unsigned int ofw_get_address_cells(const phandle device) 118 { 119 unsigned int ret = 1; 85 120 86 121 if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0) 87 122 if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0) 88 ret = 1;123 ret = OFW_ADDRESS_CELLS; 89 124 90 125 return ret; … … 92 127 93 128 94 staticunsigned int ofw_get_size_cells(const phandle device)129 unsigned int ofw_get_size_cells(const phandle device) 95 130 { 96 131 unsigned int ret; … … 98 133 if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0) 99 134 if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0) 100 ret = 1;135 ret = OFW_SIZE_CELLS; 101 136 102 137 return ret; … … 107 142 { 108 143 return ofw_call("open", 1, 1, NULL, name); 109 }110 111 112 void init(void)113 {114 ofw_chosen = ofw_find_device("/chosen");115 if (ofw_chosen == -1)116 halt();117 118 if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0)119 ofw_stdout = 0;120 121 ofw_root = ofw_find_device("/");122 if (ofw_root == -1) {123 puts("\r\nError: Unable to find / device, halted.\r\n");124 halt();125 }126 127 if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) {128 puts("\r\nError: Unable to get mmu property, halted.\r\n");129 halt();130 }131 132 ofw_memory = ofw_find_device("/memory");133 if (ofw_memory == -1) {134 puts("\r\nError: Unable to find /memory device, halted.\r\n");135 halt();136 }137 138 ofw_aliases = ofw_find_device("/aliases");139 if (ofw_aliases == -1) {140 puts("\r\nError: Unable to find /aliases device, halted.\r\n");141 halt();142 }143 144 } 144 145 … … 170 171 else 171 172 shift = 0; 172 173 173 174 return (void *) ((result[2]<<shift)|result[3]); 174 175 } … … 207 208 int ofw_memmap(memmap_t *map) 208 209 { 209 unsigned long buf[BUF_SIZE];210 int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf));211 if (ret <= 0)212 return false;213 214 210 unsigned int ac = ofw_get_address_cells(ofw_memory); 215 211 unsigned int sc = ofw_get_size_cells(ofw_memory); 216 212 213 uint32_t buf[((ac+sc)*MEMMAP_MAX_RECORDS)]; 214 int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf)); 215 if (ret <= 0) /* ret is the number of written bytes */ 216 return false; 217 217 218 int pos; 218 219 map->total = 0; 219 220 map->count = 0; 220 for (pos = 0; (pos < ret / sizeof(u nsigned long)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {221 void * start = (void *) buf[pos + ac - 1];221 for (pos = 0; (pos < ret / sizeof(uint32_t)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) { 222 void * start = (void *) ((uintptr_t) buf[pos + ac - 1]); 222 223 unsigned int size = buf[pos + ac + sc - 1]; 223 224 … … 229 230 } 230 231 } 232 233 return true; 231 234 } 232 235 … … 235 238 { 236 239 char device_name[BUF_SIZE]; 240 uint32_t virtaddr; 237 241 238 242 if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0) … … 243 247 return false; 244 248 245 if (ofw_get_property(device, "address", &screen->addr, sizeof(screen->addr)) <= 0) 246 return false; 247 249 if (ofw_get_property(device, "address", &virtaddr, sizeof(virtaddr)) <= 0) 250 return false; 251 252 screen->addr = (void *) ((uintptr_t) virtaddr); 253 248 254 if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0) 249 255 return false;
Note:
See TracChangeset
for help on using the changeset viewer.