Subversion Repositories HelenOS-historic

Rev

Rev 1166 | Rev 1401 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1166 Rev 1395
Line 31... Line 31...
31
#include "printf.h"
31
#include "printf.h"
32
 
32
 
33
#define MAX_OFW_ARGS    10
33
#define MAX_OFW_ARGS    10
34
#define BUF_SIZE        1024
34
#define BUF_SIZE        1024
35
 
35
 
36
typedef unsigned long ofw_arg_t;
36
typedef unsigned int ofw_arg_t;
37
typedef unsigned long ihandle;
37
typedef unsigned int ihandle;
38
typedef unsigned long phandle;
38
typedef unsigned int phandle;
39
 
39
 
40
/** OpenFirmware command structure
40
/** OpenFirmware command structure
41
 *
41
 *
42
 */
42
 */
43
typedef struct {
43
typedef struct {
44
    const char *service;          /**< Command name */
44
    const char *service;          /**< Command name */
45
    unsigned long nargs;           /**< Number of in arguments */
45
    unsigned int nargs;           /**< Number of in arguments */
46
    unsigned long nret;            /**< Number of out arguments */
46
    unsigned int nret;            /**< Number of out arguments */
47
    ofw_arg_t args[MAX_OFW_ARGS]; /**< List of arguments */
47
    ofw_arg_t args[MAX_OFW_ARGS]; /**< List of arguments */
48
} ofw_args_t;
48
} ofw_args_t;
49
 
49
 
50
typedef void (*ofw_entry)(ofw_args_t *);
50
typedef void (*ofw_entry)(ofw_args_t *);
51
 
51
 
Line 58... Line 58...
58
ihandle ofw_mmu;
58
ihandle ofw_mmu;
59
phandle ofw_memory;
59
phandle ofw_memory;
60
phandle ofw_aliases;
60
phandle ofw_aliases;
61
 
61
 
62
 
62
 
63
static long ofw_call(const char *service, const long nargs, const long nret, ofw_arg_t *rets, ...)
63
static int ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
64
{
64
{
65
    va_list list;
65
    va_list list;
66
    ofw_args_t args;
66
    ofw_args_t args;
67
    long i;
67
    int i;
68
   
68
   
69
    args.service = service;
69
    args.service = service;
70
    args.nargs = nargs;
70
    args.nargs = nargs;
71
    args.nret = nret;
71
    args.nret = nret;
72
   
72
   
Line 91... Line 91...
91
{
91
{
92
    return ofw_call("finddevice", 1, 1, NULL, name);
92
    return ofw_call("finddevice", 1, 1, NULL, name);
93
}
93
}
94
 
94
 
95
 
95
 
96
static long ofw_get_property(const phandle device, const char *name, const void *buf, const long buflen)
96
static int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen)
97
{
97
{
98
    return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
98
    return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
99
}
99
}
100
 
100
 
101
 
101
 
102
static unsigned long ofw_get_address_cells(const phandle device)
102
static unsigned int ofw_get_address_cells(const phandle device)
103
{
103
{
104
    unsigned long ret;
104
    unsigned int ret;
105
   
105
   
106
    if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
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)
107
        if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
108
            ret = 1;
108
            ret = 1;
109
   
109
   
110
    return ret;
110
    return ret;
111
}
111
}
112
 
112
 
113
 
113
 
114
static unsigned long ofw_get_size_cells(const phandle device)
114
static unsigned int ofw_get_size_cells(const phandle device)
115
{
115
{
116
    unsigned long ret;
116
    unsigned int ret;
117
   
117
   
118
    if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
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)
119
        if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
120
            ret = 1;
120
            ret = 1;
121
   
121
   
Line 182... Line 182...
182
    }
182
    }
183
    return (void *) result[2];
183
    return (void *) result[2];
184
}
184
}
185
 
185
 
186
 
186
 
187
long ofw_map(const void *phys, const void *virt, const long size, const long mode)
187
int ofw_map(const void *phys, const void *virt, const int size, const int mode)
188
{
188
{
189
    return ofw_call("call-method", 6, 1, NULL, "map", ofw_mmu, mode, size, virt, phys);
189
    return ofw_call("call-method", 6, 1, NULL, "map", ofw_mmu, mode, size, virt, phys);
190
}
190
}
191
 
191
 
192
 
192
 
193
long ofw_memmap(memmap_t *map)
193
int ofw_memmap(memmap_t *map)
194
{
194
{
195
    unsigned long buf[BUF_SIZE];
195
    unsigned int buf[BUF_SIZE];
196
    long ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned long) * BUF_SIZE);
196
    int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned int) * BUF_SIZE);
197
    if (ret <= 0)
197
    if (ret <= 0)
198
        return false;
198
        return false;
199
       
199
       
200
    unsigned long ac = ofw_get_address_cells(ofw_memory);
200
    unsigned int ac = ofw_get_address_cells(ofw_memory);
201
    unsigned long sc = ofw_get_size_cells(ofw_memory);
201
    unsigned int sc = ofw_get_size_cells(ofw_memory);
202
   
202
   
203
    long pos;
203
    int pos;
204
    map->total = 0;
204
    map->total = 0;
205
    map->count = 0;
205
    map->count = 0;
206
    for (pos = 0; (pos < ret / sizeof(unsigned long)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
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];
207
        void * start = (void *) buf[pos + ac - 1];
208
        unsigned long size = buf[pos + ac + sc - 1];
208
        unsigned int size = buf[pos + ac + sc - 1];
209
       
209
       
210
        if (size > 0) {
210
        if (size > 0) {
211
            map->zones[map->count].start = start;
211
            map->zones[map->count].start = start;
212
            map->zones[map->count].size = size;
212
            map->zones[map->count].size = size;
213
            map->count++;
213
            map->count++;
Line 215... Line 215...
215
        }
215
        }
216
    }
216
    }
217
}
217
}
218
 
218
 
219
 
219
 
220
long ofw_screen(screen_t *screen)
220
int ofw_screen(screen_t *screen)
221
{
221
{
222
    char device_name[BUF_SIZE];
222
    char device_name[BUF_SIZE];
223
   
223
   
224
    if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(char) * BUF_SIZE) <= 0)
224
    if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(char) * BUF_SIZE) <= 0)
225
        return false;
225
        return false;