Subversion Repositories HelenOS

Rev

Rev 2071 | Rev 3678 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2071 Rev 2250
Line 36... Line 36...
36
 
36
 
37
phandle ofw_chosen;
37
phandle ofw_chosen;
38
ihandle ofw_stdout;
38
ihandle ofw_stdout;
39
phandle ofw_root;
39
phandle ofw_root;
40
ihandle ofw_mmu;
40
ihandle ofw_mmu;
-
 
41
ihandle ofw_memory_prop;
41
phandle ofw_memory;
42
phandle ofw_memory;
42
phandle ofw_aliases;
43
phandle ofw_aliases;
43
 
44
 
44
void ofw_init(void)
45
void ofw_init(void)
45
{
46
{
46
    ofw_chosen = ofw_find_device("/chosen");
47
    ofw_chosen = ofw_find_device("/chosen");
47
    if (ofw_chosen == -1)
48
    if (ofw_chosen == -1)
48
        halt();
49
        halt();
49
   
50
   
50
    if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
51
    if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0)
51
        ofw_stdout = 0;
52
        ofw_stdout = 0;
52
   
53
   
53
    ofw_root = ofw_find_device("/");
54
    ofw_root = ofw_find_device("/");
54
    if (ofw_root == -1) {
55
    if (ofw_root == -1) {
55
        puts("\r\nError: Unable to find / device, halted.\r\n");
56
        puts("\r\nError: Unable to find / device, halted.\r\n");
56
        halt();
57
        halt();
57
    }
58
    }
58
   
59
   
59
    if (ofw_get_property(ofw_chosen, "mmu",  &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
60
    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
        puts("\r\nError: Unable to get mmu property, halted.\r\n");
61
        halt();
62
        halt();
62
    }
63
    }
-
 
64
    if (ofw_get_property(ofw_chosen, "memory", &ofw_memory_prop, sizeof(ofw_memory_prop)) <= 0) {
-
 
65
        puts("\r\nError: Unable to get memory property, halted.\r\n");
-
 
66
        halt();
-
 
67
    }
63
 
68
 
64
    ofw_memory = ofw_find_device("/memory");
69
    ofw_memory = ofw_find_device("/memory");
65
    if (ofw_memory == -1) {
70
    if (ofw_memory == -1) {
66
        puts("\r\nError: Unable to find /memory device, halted.\r\n");
71
        puts("\r\nError: Unable to find /memory device, halted.\r\n");
67
        halt();
72
        halt();
Line 198... Line 203...
198
    if (sizeof(unative_t) == 8)
203
    if (sizeof(unative_t) == 8)
199
        shift = 32;
204
        shift = 32;
200
    else
205
    else
201
        shift = 0;
206
        shift = 0;
202
 
207
 
203
    return (void *) ((result[2]<<shift)|result[3]);
208
    return (void *) ((result[2] << shift) | result[3]);
204
}
209
}
205
 
210
 
206
void *ofw_claim(const void *virt, const int len)
211
void *ofw_claim_virt(const void *virt, const int len)
207
{
212
{
208
    ofw_arg_t retaddr;
213
    ofw_arg_t retaddr;
209
    int shift;
-
 
210
 
214
 
211
    if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len, virt) != 0) {
215
    if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len, virt) != 0) {
212
        puts("Error: MMU method claim() failed, halting.\n");
216
        puts("Error: MMU method claim() failed, halting.\n");
213
        halt();
217
        halt();
214
    }
218
    }
215
 
219
 
216
    return (void *) retaddr;
220
    return (void *) retaddr;
217
}
221
}
218
 
222
 
-
 
223
void *ofw_claim_phys(const void *phys, const int len)
-
 
224
{
-
 
225
    ofw_arg_t retaddr[2];
-
 
226
    int shift;
-
 
227
 
-
 
228
    if (sizeof(unative_t) == 8) {
-
 
229
        shift = 32;
-
 
230
        if (ofw_call("call-method", 6, 3, retaddr, "claim",
-
 
231
            ofw_memory_prop, 0, len, ((uintptr_t) phys) >> shift,
-
 
232
            ((uintptr_t) phys) & ((uint32_t) -1)) != 0) {
-
 
233
            /*
-
 
234
             * Note that this will help us to discover
-
 
235
             * conflicts between OpenFirmware allocations
-
 
236
             * and our use of physical memory.
-
 
237
             * It is better to detect collisions here
-
 
238
             * than to cope with weird errors later.
-
 
239
             *
-
 
240
             * So this is really not to make the loader
-
 
241
             * more generic; it is here for debugging
-
 
242
             * purposes.
-
 
243
             */
-
 
244
            puts("Error: memory method claim() failed, halting.\n");
-
 
245
            halt();
-
 
246
        }
-
 
247
    } else {
-
 
248
        shift = 0;
-
 
249
        /*
-
 
250
         * FIXME: the number of arguments is probably different...
-
 
251
         */
-
 
252
        puts("Error: 32-bit ofw_claim_phys not implemented.\n");
-
 
253
        halt();
-
 
254
    }
-
 
255
 
-
 
256
    return (void *) ((retaddr[0] << shift) | retaddr[1]);
-
 
257
}
-
 
258
 
219
int ofw_map(const void *phys, const void *virt, const int size, const int mode)
259
int ofw_map(const void *phys, const void *virt, const int size, const int mode)
220
{
260
{
221
    uintptr_t phys_hi, phys_lo;
261
    uintptr_t phys_hi, phys_lo;
222
 
262
 
223
    if (sizeof(unative_t) == 8) {
263
    if (sizeof(unative_t) == 8) {
Line 228... Line 268...
228
        phys_hi = 0;
268
        phys_hi = 0;
229
        phys_lo = (uintptr_t) phys;
269
        phys_lo = (uintptr_t) phys;
230
    }
270
    }
231
 
271
 
232
    return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size, virt,
272
    return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size, virt,
233
        phys_hi, phys_lo);
273
        phys_hi, phys_lo);
234
}
274
}
235
 
275
 
236
/** Save OpenFirmware physical memory map.
276
/** Save OpenFirmware physical memory map.
237
 *
277
 *
238
 * @param map Memory map structure where the map will be saved.
278
 * @param map Memory map structure where the map will be saved.
Line 250... Line 290...
250
        return false;
290
        return false;
251
 
291
 
252
    int pos;
292
    int pos;
253
    map->total = 0;
293
    map->total = 0;
254
    map->count = 0;
294
    map->count = 0;
255
    for (pos = 0; (pos < ret / sizeof(uint32_t)) && (map->count <
295
    for (pos = 0; (pos < ret / sizeof(uint32_t)) &&
256
        MEMMAP_MAX_RECORDS); pos += ac + sc) {
296
        (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
257
        void * start = (void *) ((uintptr_t) buf[pos + ac - 1]);
297
        void * start = (void *) ((uintptr_t) buf[pos + ac - 1]);
258
        unsigned int size = buf[pos + ac + sc - 1];
298
        unsigned int size = buf[pos + ac + sc - 1];
259
       
299
       
260
        if (size > 0) {
300
        if (size > 0) {
261
            map->zones[map->count].start = start;
301
            map->zones[map->count].start = start;