Changeset 38fe9d0 in mainline for arch/ppc32/loader/ofw.c
- Timestamp:
- 2006-04-02T15:10:41Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 89343aac
- Parents:
- 730de779
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
arch/ppc32/loader/ofw.c
r730de779 r38fe9d0 32 32 33 33 #define MAX_OFW_ARGS 10 34 #define STRING_SIZE 102434 #define BUF_SIZE 1024 35 35 36 36 typedef unsigned int ofw_arg_t; … … 54 54 55 55 phandle ofw_chosen; 56 ihandle ofw_stdout; 57 phandle ofw_root; 58 ihandle ofw_mmu; 59 phandle ofw_memory; 56 60 phandle ofw_aliases; 57 ihandle ofw_mmu; 58 ihandle ofw_stdout; 59 60 61 static int ofw_call(const char *service, const int nargs, const int nret, ...) 61 62 63 static int ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...) 62 64 { 63 65 va_list list; … … 69 71 args.nret = nret; 70 72 71 va_start(list, nret);73 va_start(list, rets); 72 74 for (i = 0; i < nargs; i++) 73 75 args.args[i] = va_arg(list, ofw_arg_t); … … 79 81 ofw(&args); 80 82 83 for (i = 1; i < nret; i++) 84 rets[i - 1] = args.args[i + nargs]; 85 81 86 return args.args[nargs]; 82 87 } … … 85 90 static phandle ofw_find_device(const char *name) 86 91 { 87 return ofw_call("finddevice", 1, 1, name);92 return ofw_call("finddevice", 1, 1, NULL, name); 88 93 } 89 94 … … 91 96 static int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen) 92 97 { 93 return ofw_call("getprop", 4, 1, device, name, buf, buflen); 94 } 98 return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen); 99 } 100 101 102 static unsigned int ofw_get_address_cells(const phandle device) 103 { 104 unsigned int ret; 105 106 if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0) 107 if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0) 108 ret = 1; 109 110 return ret; 111 } 112 113 114 static unsigned int ofw_get_size_cells(const phandle device) 115 { 116 unsigned int ret; 117 118 if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0) 119 if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0) 120 ret = 1; 121 122 return ret; 123 } 124 95 125 96 126 static ihandle ofw_open(const char *name) 97 127 { 98 return ofw_call("open", 1, 1, name);128 return ofw_call("open", 1, 1, NULL, name); 99 129 } 100 130 … … 106 136 halt(); 107 137 108 if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) 138 if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) 109 139 ofw_stdout = 0; 140 141 ofw_root = ofw_find_device("/"); 142 if (ofw_root == -1) { 143 puts("\r\nError: Unable to find / device, halted.\r\n"); 144 halt(); 145 } 146 147 if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) { 148 puts("\r\nError: Unable to get mmu property, halted.\r\n"); 149 halt(); 150 } 151 152 ofw_memory = ofw_find_device("/memory"); 153 if (ofw_memory == -1) { 154 puts("\r\nError: Unable to find /memory device, halted.\r\n"); 155 halt(); 156 } 110 157 111 158 ofw_aliases = ofw_find_device("/aliases"); 112 159 if (ofw_aliases == -1) { 113 puts("\nUnable to find /aliases device\n"); 114 halt(); 115 } 116 117 ofw_mmu = ofw_open("/mmu"); 118 if (ofw_mmu == -1) { 119 puts("\nUnable to open /mmu node\n"); 160 puts("\r\nError: Unable to find /aliases device, halted.\r\n"); 120 161 halt(); 121 162 } … … 128 169 return; 129 170 130 ofw_call("write", 3, 1, ofw_stdout, str, len);171 ofw_call("write", 3, 1, NULL, ofw_stdout, str, len); 131 172 } 132 173 … … 134 175 void *ofw_translate(const void *virt) 135 176 { 136 return (void *) ofw_call("call-method", 7, 1, "translate", ofw_mmu, virt, 0, 0, 0, 0); 177 ofw_arg_t result[3]; 178 179 if (ofw_call("call-method", 4, 4, result, "translate", ofw_mmu, virt, 1) != 0) { 180 puts("Error: MMU method translate() failed, halting.\n"); 181 halt(); 182 } 183 return (void *) result[2]; 137 184 } 138 185 … … 140 187 int ofw_map(const void *phys, const void *virt, const int size, const int mode) 141 188 { 142 return ofw_call("call-method", 6, 1, "map", ofw_mmu, mode, size, virt, phys);189 return ofw_call("call-method", 6, 1, NULL, "map", ofw_mmu, mode, size, virt, phys); 143 190 } 144 191 … … 146 193 int ofw_memmap(memmap_t *map) 147 194 { 148 int i; 149 int ret; 150 151 phandle handle = ofw_find_device("/memory"); 152 if (handle == -1) 153 return false; 154 155 ret = ofw_get_property(handle, "reg", &map->zones, sizeof(map->zones)); 156 if (ret == -1) 157 return false; 158 195 unsigned int buf[BUF_SIZE]; 196 int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned int) * BUF_SIZE); 197 if (ret <= 0) 198 return false; 199 200 unsigned int ac = ofw_get_address_cells(ofw_memory); 201 unsigned int sc = ofw_get_size_cells(ofw_memory); 202 203 int pos; 159 204 map->total = 0; 160 205 map->count = 0; 161 for (i = 0; i < MEMMAP_MAX_RECORDS; i++) { 162 if (map->zones[i].size == 0) 163 break; 164 map->count++; 165 map->total += map->zones[i].size; 206 for (pos = 0; (pos < ret / sizeof(unsigned int)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) { 207 void * start = (void *) buf[pos + ac - 1]; 208 unsigned int size = buf[pos + ac + sc - 1]; 209 210 if (size > 0) { 211 map->zones[map->count].start = start; 212 map->zones[map->count].size = size; 213 map->count++; 214 map->total += size; 215 } 166 216 } 167 217 } … … 170 220 int ofw_screen(screen_t *screen) 171 221 { 172 char device_name[ STRING_SIZE];173 174 if (ofw_get_property(ofw_aliases, "screen", device_name, STRING_SIZE) <= 0)222 char device_name[BUF_SIZE]; 223 224 if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(char) * BUF_SIZE) <= 0) 175 225 return false; 176 226
Note:
See TracChangeset
for help on using the changeset viewer.