Subversion Repositories HelenOS

Rev

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

Rev 3618 Rev 3742
Line 46... Line 46...
46
{
46
{
47
    ofw_chosen = ofw_find_device("/chosen");
47
    ofw_chosen = ofw_find_device("/chosen");
48
    if (ofw_chosen == -1)
48
    if (ofw_chosen == -1)
49
        halt();
49
        halt();
50
   
50
   
51
    if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0)
51
    if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout,
-
 
52
        sizeof(ofw_stdout)) <= 0)
52
        ofw_stdout = 0;
53
        ofw_stdout = 0;
53
   
54
   
54
    ofw_root = ofw_find_device("/");
55
    ofw_root = ofw_find_device("/");
55
    if (ofw_root == -1) {
56
    if (ofw_root == -1) {
56
        puts("\r\nError: Unable to find / device, halted.\r\n");
57
        puts("\r\nError: Unable to find / device, halted.\r\n");
57
        halt();
58
        halt();
58
    }
59
    }
59
   
60
   
60
    if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
61
    if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu,
-
 
62
        sizeof(ofw_mmu)) <= 0) {
61
        puts("\r\nError: Unable to get mmu property, halted.\r\n");
63
        puts("\r\nError: Unable to get mmu property, halted.\r\n");
62
        halt();
64
        halt();
63
    }
65
    }
64
    if (ofw_get_property(ofw_chosen, "memory", &ofw_memory_prop, sizeof(ofw_memory_prop)) <= 0) {
66
    if (ofw_get_property(ofw_chosen, "memory", &ofw_memory_prop,
-
 
67
        sizeof(ofw_memory_prop)) <= 0) {
65
        puts("\r\nError: Unable to get memory property, halted.\r\n");
68
        puts("\r\nError: Unable to get memory property, halted.\r\n");
66
        halt();
69
        halt();
67
    }
70
    }
68
 
71
 
69
    ofw_memory = ofw_find_device("/memory");
72
    ofw_memory = ofw_find_device("/memory");
Line 79... Line 82...
79
    }
82
    }
80
}
83
}
81
 
84
 
82
/** Perform a call to OpenFirmware client interface.
85
/** Perform a call to OpenFirmware client interface.
83
 *
86
 *
84
 * @param service String identifying the service requested.
87
 * @param service   String identifying the service requested.
85
 * @param nargs Number of input arguments.
88
 * @param nargs     Number of input arguments.
86
 * @param nret Number of output arguments. This includes the return value.
89
 * @param nret      Number of output arguments. This includes the return
-
 
90
 *          value.
87
 * @param rets Buffer for output arguments or NULL. The buffer must accommodate nret - 1 items.
91
 * @param rets      Buffer for output arguments or NULL. The buffer must
-
 
92
 *          accommodate nret - 1 items.
88
 *
93
 *
89
 * @return Return value returned by the client interface.
94
 * @return      Return value returned by the client interface.
90
 */
95
 */
-
 
96
unsigned long
91
unsigned long ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
97
ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets,
-
 
98
    ...)
92
{
99
{
93
    va_list list;
100
    va_list list;
94
    ofw_args_t args;
101
    ofw_args_t args;
95
    int i;
102
    int i;
96
   
103
   
Line 117... Line 124...
117
phandle ofw_find_device(const char *name)
124
phandle ofw_find_device(const char *name)
118
{
125
{
119
    return ofw_call("finddevice", 1, 1, NULL, name);
126
    return ofw_call("finddevice", 1, 1, NULL, name);
120
}
127
}
121
 
128
 
-
 
129
int
122
int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen)
130
ofw_get_property(const phandle device, const char *name, void *buf,
-
 
131
    const int buflen)
123
{
132
{
124
    return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
133
    return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
125
}
134
}
126
 
135
 
127
int ofw_get_proplen(const phandle device, const char *name)
136
int ofw_get_proplen(const phandle device, const char *name)
Line 142... Line 151...
142
unsigned int ofw_get_address_cells(const phandle device)
151
unsigned int ofw_get_address_cells(const phandle device)
143
{
152
{
144
    unsigned int ret = 1;
153
    unsigned int ret = 1;
145
   
154
   
146
    if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
155
    if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
147
        if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
156
        if (ofw_get_property(ofw_root, "#address-cells", &ret,
-
 
157
            sizeof(ret)) <= 0)
148
            ret = OFW_ADDRESS_CELLS;
158
            ret = OFW_ADDRESS_CELLS;
149
   
159
   
150
    return ret;
160
    return ret;
151
}
161
}
152
 
162
 
Line 154... Line 164...
154
unsigned int ofw_get_size_cells(const phandle device)
164
unsigned int ofw_get_size_cells(const phandle device)
155
{
165
{
156
    unsigned int ret;
166
    unsigned int ret;
157
   
167
   
158
    if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
168
    if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
159
        if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
169
        if (ofw_get_property(ofw_root, "#size-cells", &ret,
-
 
170
            sizeof(ret)) <= 0)
160
            ret = OFW_SIZE_CELLS;
171
            ret = OFW_SIZE_CELLS;
161
   
172
   
162
    return ret;
173
    return ret;
163
}
174
}
164
 
175
 
Line 190... Line 201...
190
void *ofw_translate(const void *virt)
201
void *ofw_translate(const void *virt)
191
{
202
{
192
    ofw_arg_t result[4];
203
    ofw_arg_t result[4];
193
    int shift;
204
    int shift;
194
 
205
 
195
    if (ofw_call("call-method", 3, 5, result, "translate", ofw_mmu, virt) != 0) {
206
    if (ofw_call("call-method", 3, 5, result, "translate", ofw_mmu,
-
 
207
        virt) != 0) {
196
        puts("Error: MMU method translate() failed, halting.\n");
208
        puts("Error: MMU method translate() failed, halting.\n");
197
        halt();
209
        halt();
198
    }
210
    }
199
 
211
 
200
    if (ofw_translate_failed(result[0]))
212
    if (ofw_translate_failed(result[0]))
Line 210... Line 222...
210
 
222
 
211
void *ofw_claim_virt(const void *virt, const int len)
223
void *ofw_claim_virt(const void *virt, const int len)
212
{
224
{
213
    ofw_arg_t retaddr;
225
    ofw_arg_t retaddr;
214
 
226
 
215
    if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len, virt) != 0) {
227
    if (ofw_call("call-method", 5, 2, &retaddr, "claim", ofw_mmu, 0, len,
-
 
228
        virt) != 0) {
216
        puts("Error: MMU method claim() failed, halting.\n");
229
        puts("Error: MMU method claim() failed, halting.\n");
217
        halt();
230
        halt();
218
    }
231
    }
219
 
232
 
220
    return (void *) retaddr;
233
    return (void *) retaddr;
Line 267... Line 280...
267
    } else {
280
    } else {
268
        phys_hi = 0;
281
        phys_hi = 0;
269
        phys_lo = (uintptr_t) phys;
282
        phys_lo = (uintptr_t) phys;
270
    }
283
    }
271
 
284
 
272
    return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size, virt,
285
    return ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, size,
273
        phys_hi, phys_lo);
286
        virt, phys_hi, phys_lo);
274
}
287
}
275
 
288
 
276
/** Save OpenFirmware physical memory map.
289
/** Save OpenFirmware physical memory map.
277
 *
290
 *
278
 * @param map Memory map structure where the map will be saved.
291
 * @param map Memory map structure where the map will be saved.
Line 280... Line 293...
280
 * @return Zero on failure, non-zero on success.
293
 * @return Zero on failure, non-zero on success.
281
 */
294
 */
282
int ofw_memmap(memmap_t *map)
295
int ofw_memmap(memmap_t *map)
283
{
296
{
284
    unsigned int ac = ofw_get_address_cells(ofw_memory) /
297
    unsigned int ac = ofw_get_address_cells(ofw_memory) /
285
        (sizeof(uintptr_t) / sizeof(uint32_t));
298
        (sizeof(uintptr_t) / sizeof(uint32_t));
286
    unsigned int sc = ofw_get_size_cells(ofw_memory) /
299
    unsigned int sc = ofw_get_size_cells(ofw_memory) /
287
        (sizeof(uintptr_t) / sizeof(uint32_t));
300
        (sizeof(uintptr_t) / sizeof(uint32_t));
288
    printf("address cells: %d, size cells: %d. ", ac, sc);
-
 
289
 
301
 
290
    uintptr_t buf[((ac + sc) * MEMMAP_MAX_RECORDS)];
302
    uintptr_t buf[((ac + sc) * MEMMAP_MAX_RECORDS)];
291
    int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf));
303
    int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf));
292
    if (ret <= 0)       /* ret is the number of written bytes */
304
    if (ret <= 0)       /* ret is the number of written bytes */
293
        return false;
305
        return false;
Line 305... Line 317...
305
         * where there are holes in the physical memory (such as
317
         * where there are holes in the physical memory (such as
306
         * SunBlade 1500). Should we detect a hole in the physical
318
         * SunBlade 1500). Should we detect a hole in the physical
307
         * memory, we will ignore any memory detected behind
319
         * memory, we will ignore any memory detected behind
308
         * the hole and pretend the hole does not exist.
320
         * the hole and pretend the hole does not exist.
309
         */
321
         */
310
        if ((map->count > 0) &&
322
        if ((map->count > 0) && (map->zones[map->count - 1].start +
311
            (map->zones[map->count - 1].start + map->zones[map->count - 1].size
323
            map->zones[map->count - 1].size < start))
312
                < start))
-
 
313
            break;
324
            break;
314
 
325
 
315
        if (size > 0) {
326
        if (size > 0) {
316
            map->zones[map->count].start = start;
327
            map->zones[map->count].start = start;
317
            map->zones[map->count].size = size;
328
            map->zones[map->count].size = size;
Line 326... Line 337...
326
int ofw_screen(screen_t *screen)
337
int ofw_screen(screen_t *screen)
327
{
338
{
328
    char device_name[BUF_SIZE];
339
    char device_name[BUF_SIZE];
329
    uint32_t virtaddr;
340
    uint32_t virtaddr;
330
   
341
   
331
    if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0)
342
    if (ofw_get_property(ofw_aliases, "screen", device_name,
-
 
343
        sizeof(device_name)) <= 0)
332
        return false;
344
        return false;
333
   
345
   
334
    phandle device = ofw_find_device(device_name);
346
    phandle device = ofw_find_device(device_name);
335
    if (device == -1)
347
    if (device == -1)
336
        return false;
348
        return false;
337
   
349
   
338
    if (ofw_get_property(device, "address", &virtaddr, sizeof(virtaddr)) <= 0)
350
    if (ofw_get_property(device, "address", &virtaddr,
-
 
351
        sizeof(virtaddr)) <= 0)
339
        return false;
352
        return false;
340
 
353
 
341
    screen->addr = (void *) ((uintptr_t) virtaddr);
354
    screen->addr = (void *) ((uintptr_t) virtaddr);
342
 
355
 
343
    if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0)
356
    if (ofw_get_property(device, "width", &screen->width,
-
 
357
        sizeof(screen->width)) <= 0)
344
        return false;
358
        return false;
345
   
359
   
346
    if (ofw_get_property(device, "height", &screen->height, sizeof(screen->height)) <= 0)
360
    if (ofw_get_property(device, "height", &screen->height,
-
 
361
        sizeof(screen->height)) <= 0)
347
        return false;
362
        return false;
348
   
363
   
349
    if (ofw_get_property(device, "depth", &screen->bpp, sizeof(screen->bpp)) <= 0)
364
    if (ofw_get_property(device, "depth", &screen->bpp,
-
 
365
        sizeof(screen->bpp)) <= 0)
350
        return false;
366
        return false;
351
   
367
   
352
    if (ofw_get_property(device, "linebytes", &screen->scanline, sizeof(screen->scanline)) <= 0)
368
    if (ofw_get_property(device, "linebytes", &screen->scanline,
-
 
369
        sizeof(screen->scanline)) <= 0)
353
        return false;
370
        return false;
354
   
371
   
355
    return true;
372
    return true;
356
}
373
}
357
 
374
 
-
 
375
/**
-
 
376
 * Sets up the palette for the 8-bit color depth configuration so that the
-
 
377
 * 3:2:3 color scheme can be used. Checks that setting the palette makes sense
-
 
378
 * (appropriate nodes exist in the OBP tree and the color depth is not greater
-
 
379
 * than 8).
-
 
380
 *
-
 
381
 * @return  true if the palette has been set, false otherwise
-
 
382
 */
-
 
383
int setup_palette(void)
-
 
384
{
-
 
385
    char device_name[BUF_SIZE];
-
 
386
   
-
 
387
    /* resolve alias */
-
 
388
    if (ofw_get_property(ofw_aliases, "screen", device_name,
-
 
389
        sizeof(device_name)) <= 0)
-
 
390
        return false;
-
 
391
 
-
 
392
    /* for depth greater than 8 it makes no sense to set up the palette */
-
 
393
    uint32_t depth;
-
 
394
    phandle device = ofw_find_device(device_name);
-
 
395
    if (device == -1)
-
 
396
        return false;
-
 
397
    if (ofw_get_property(device, "depth", &depth, sizeof(uint32_t)) <= 0)
-
 
398
        return false;
-
 
399
    if (depth != 8)
-
 
400
        return false;
-
 
401
   
-
 
402
    /* required in order to be able to make a method call */
-
 
403
    ihandle screen = ofw_open(device_name);
-
 
404
    if (screen == -1)
-
 
405
        return false;
-
 
406
 
-
 
407
    /* setup the palette so that the (inverted) 3:2:3 scheme is usable */
-
 
408
    unsigned int i;
-
 
409
    for (i = 0; i < 256; i++)
-
 
410
        if (ofw_call("call-method", 6, 1, NULL, "color!", screen,
-
 
411
            255 - i,
-
 
412
            i << 5,
-
 
413
            (i >> 3) << 6,
-
 
414
            (i >> 5) << 5) != 0);
-
 
415
    return true;
-
 
416
}
358
 
417
 
359
void ofw_quiesce(void)
418
void ofw_quiesce(void)
360
{
419
{
361
    ofw_call("quiesce", 0, 0, NULL);
420
    ofw_call("quiesce", 0, 0, NULL);
362
}
421
}