Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1788 → Rev 1789

/trunk/boot/genarch/ofw.h
26,8 → 26,8
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __OFW_H__
#define __OFW_H__
#ifndef BOOT_OFW_H_
#define BOOT_OFW_H_
 
#include <types.h>
#include <stdarg.h>
38,7 → 38,7
 
#define MAX_OFW_ARGS 12
 
typedef unsigned long ofw_arg_t;
typedef unative_t ofw_arg_t;
typedef unsigned int ihandle;
typedef unsigned int phandle;
 
64,7 → 64,7
} memmap_t;
 
typedef struct {
uint32_t addr;
void *addr;
unsigned int width;
unsigned int height;
unsigned int bpp;
72,7 → 72,7
} screen_t;
 
typedef struct {
uint32_t addr;
void *addr;
unsigned int size;
} keyboard_t;
 
92,7 → 92,7
 
extern phandle ofw_aliases;
 
extern void init(void);
extern void ofw_init(void);
extern void ofw_write(const char *str, const int len);
 
extern int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen);
99,6 → 99,8
extern phandle ofw_find_device(const char *name);
 
extern int ofw(ofw_args_t *arg);
extern unsigned int ofw_get_address_cells(const phandle device);
extern unsigned int ofw_get_size_cells(const phandle device);
extern void *ofw_translate(const void *virt);
extern int ofw_translate_failed(ofw_arg_t flag);
extern void *ofw_claim(const void *virt, const int len);
/trunk/boot/genarch/ofw.c
26,7 → 26,8
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ofw.h"
#include <ofw.h>
#include <ofwarch.h>
#include <printf.h>
#include <asm.h>
#include <types.h>
40,6 → 41,40
phandle ofw_memory;
phandle ofw_aliases;
 
void ofw_init(void)
{
ofw_chosen = ofw_find_device("/chosen");
if (ofw_chosen == -1)
halt();
if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0)
ofw_stdout = 0;
ofw_root = ofw_find_device("/");
if (ofw_root == -1) {
puts("\r\nError: Unable to find / device, halted.\r\n");
halt();
}
if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
puts("\r\nError: Unable to get mmu property, halted.\r\n");
halt();
}
 
ofw_memory = ofw_find_device("/memory");
if (ofw_memory == -1) {
puts("\r\nError: Unable to find /memory device, halted.\r\n");
halt();
}
ofw_aliases = ofw_find_device("/aliases");
if (ofw_aliases == -1) {
puts("\r\nError: Unable to find /aliases device, halted.\r\n");
halt();
}
}
 
 
static unsigned long ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
{
va_list list;
79,25 → 114,25
}
 
 
static unsigned int ofw_get_address_cells(const phandle device)
unsigned int ofw_get_address_cells(const phandle device)
{
unsigned int ret;
unsigned int ret = 1;
if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
ret = 1;
ret = OFW_ADDRESS_CELLS;
return ret;
}
 
 
static unsigned int ofw_get_size_cells(const phandle device)
unsigned int ofw_get_size_cells(const phandle device)
{
unsigned int ret;
if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
ret = 1;
ret = OFW_SIZE_CELLS;
return ret;
}
109,40 → 144,6
}
 
 
void init(void)
{
ofw_chosen = ofw_find_device("/chosen");
if (ofw_chosen == -1)
halt();
if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0)
ofw_stdout = 0;
ofw_root = ofw_find_device("/");
if (ofw_root == -1) {
puts("\r\nError: Unable to find / device, halted.\r\n");
halt();
}
if (ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, sizeof(ofw_mmu)) <= 0) {
puts("\r\nError: Unable to get mmu property, halted.\r\n");
halt();
}
ofw_memory = ofw_find_device("/memory");
if (ofw_memory == -1) {
puts("\r\nError: Unable to find /memory device, halted.\r\n");
halt();
}
ofw_aliases = ofw_find_device("/aliases");
if (ofw_aliases == -1) {
puts("\r\nError: Unable to find /aliases device, halted.\r\n");
halt();
}
}
 
 
void ofw_write(const char *str, const int len)
{
if (ofw_stdout == 0)
169,7 → 170,7
shift = 32;
else
shift = 0;
 
return (void *) ((result[2]<<shift)|result[3]);
}
 
206,19 → 207,19
 
int ofw_memmap(memmap_t *map)
{
unsigned long buf[BUF_SIZE];
unsigned int ac = ofw_get_address_cells(ofw_memory);
unsigned int sc = ofw_get_size_cells(ofw_memory);
 
uint32_t buf[((ac+sc)*MEMMAP_MAX_RECORDS)];
int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(buf));
if (ret <= 0)
if (ret <= 0) /* ret is the number of written bytes */
return false;
unsigned int ac = ofw_get_address_cells(ofw_memory);
unsigned int sc = ofw_get_size_cells(ofw_memory);
 
int pos;
map->total = 0;
map->count = 0;
for (pos = 0; (pos < ret / sizeof(unsigned long)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
void * start = (void *) buf[pos + ac - 1];
for (pos = 0; (pos < ret / sizeof(uint32_t)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
void * start = (void *) ((uintptr_t) buf[pos + ac - 1]);
unsigned int size = buf[pos + ac + sc - 1];
if (size > 0) {
228,6 → 229,8
map->total += size;
}
}
return true;
}
 
 
234,6 → 237,7
int ofw_screen(screen_t *screen)
{
char device_name[BUF_SIZE];
uint32_t virtaddr;
if (ofw_get_property(ofw_aliases, "screen", device_name, sizeof(device_name)) <= 0)
return false;
242,9 → 246,11
if (device == -1)
return false;
if (ofw_get_property(device, "address", &screen->addr, sizeof(screen->addr)) <= 0)
if (ofw_get_property(device, "address", &virtaddr, sizeof(virtaddr)) <= 0)
return false;
 
screen->addr = (void *) ((uintptr_t) virtaddr);
 
if (ofw_get_property(device, "width", &screen->width, sizeof(screen->width)) <= 0)
return false;