Mac-io cleanup (Laurent Vivier)

git-svn-id: svn://coreboot.org/openbios/openbios-devel@356 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Blue Swirl
2009-01-05 20:30:39 +00:00
parent 6eea2f277a
commit 49d3954458
10 changed files with 176 additions and 124 deletions

View File

@@ -27,9 +27,6 @@
#include "qemu/qemu.h"
#include <stdarg.h>
// FIXME
unsigned long virt_offset = 0;
//#define DUMP_NVRAM
void
@@ -52,11 +49,6 @@ panic( const char *err )
exit(0);
}
/************************************************************************/
/* print using OSI interface */
/************************************************************************/
static int do_indent;
int
@@ -82,94 +74,3 @@ printk( const char *fmt, ... )
}
return i;
}
/************************************************************************/
/* TTY iface */
/************************************************************************/
/************************************************************************/
/* briQ specific stuff */
/************************************************************************/
#define IO_NVRAM_SIZE 0x00020000
#define IO_NVRAM_OFFSET 0x00060000
static char *nvram;
void macio_nvram_init(const char *path, uint32_t addr)
{
phandle_t chosen, aliases;
phandle_t dnode;
int props[2];
char buf[64];
nvram = (char*)addr + IO_NVRAM_OFFSET;
snprintf(buf, sizeof(buf), "%s/nvram", path);
nvram_init(buf);
dnode = find_dev(buf);
set_int_property(dnode, "#bytes", IO_NVRAM_SIZE >> 4);
set_property(dnode, "compatible", "nvram,flash", 12);
props[0] = __cpu_to_be32(IO_NVRAM_OFFSET);
props[1] = __cpu_to_be32(IO_NVRAM_SIZE);
set_property(dnode, "reg", (char *)&props, sizeof(props));
set_property(dnode, "device_type", "nvram", 6);
chosen = find_dev("/chosen");
set_int_property(chosen, "nvram", dnode);
aliases = find_dev("/aliases");
set_property(aliases, "nvram", buf, strlen(buf) + 1);
}
#ifdef DUMP_NVRAM
static void
dump_nvram(void)
{
int i, j;
for (i = 0; i < 10; i++)
{
for (j = 0; j < 16; j++)
printk ("%02x ", nvram[(i*16+j)<<4]);
printk (" ");
for (j = 0; j < 16; j++)
if (isprint(nvram[(i*16+j)<<4]))
printk("%c", nvram[(i*16+j)<<4]);
else
printk(".");
printk ("\n");
}
}
#endif
int
arch_nvram_size( void )
{
return IO_NVRAM_SIZE>>4;
}
void
arch_nvram_put( char *buf )
{
int i;
for (i=0; i<IO_NVRAM_SIZE>>4; i++)
nvram[i<<4]=buf[i];
#ifdef DUMP_NVRAM
printk("new nvram:\n");
dump_nvram();
#endif
}
void
arch_nvram_get( char *buf )
{
int i;
for (i=0; i<IO_NVRAM_SIZE>>4; i++)
buf[i]=nvram[i<<4];
#ifdef DUMP_NVRAM
printk("current nvram:\n");
dump_nvram();
#endif
}

View File

@@ -73,5 +73,6 @@
<option name="CONFIG_DEBUG_IDE" type="boolean" value="false"/>
<option name="CONFIG_DRIVER_ADB" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_VGA" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_MACIO" type="boolean" value="true"/>
</config>

View File

@@ -73,5 +73,6 @@
<option name="CONFIG_DEBUG_IDE" type="boolean" value="false"/>
<option name="CONFIG_DRIVER_ADB" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_VGA" type="boolean" value="true"/>
<option name="CONFIG_DRIVER_MACIO" type="boolean" value="true"/>
</config>

View File

@@ -18,6 +18,7 @@
<object source="vga_load_regs.c" condition="DRIVER_VGA"/>
<object source="vga_set_mode.c" condition="DRIVER_VGA"/>
<object source="vga_vbe.c" condition="DRIVER_VGA"/>
<object source="macio.c" condition="DRIVER_MACIO"/>
</library>
<dictionary name="openbios" target="forth">

View File

@@ -3,7 +3,9 @@
#include "libc/byteorder.h"
#include "libc/vsprintf.h"
#include "macio.h"
#include "cuda.h"
//#define DEBUG_CUDA
#ifdef DEBUG_CUDA
#define CUDA_DPRINTF(fmt, args...) \

View File

@@ -14,6 +14,4 @@ enum {
CHARDEV_LAST,
};
extern phandle_t pic_handle;
cuda_t *cuda_init (const char *path, uint32_t base);

162
drivers/macio.c Normal file
View File

@@ -0,0 +1,162 @@
/*
* derived from mol/mol.c,
* Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2
*
*/
#include "openbios/config.h"
#include "openbios/nvram.h"
#include "openbios/bindings.h"
#include "libc/byteorder.h"
#include "libc/vsprintf.h"
#include "macio.h"
#include "cuda.h"
#define IO_NVRAM_SIZE 0x00020000
#define IO_NVRAM_OFFSET 0x00060000
static char *nvram;
int
arch_nvram_size( void )
{
return IO_NVRAM_SIZE>>4;
}
void macio_nvram_init(const char *path, uint32_t addr)
{
phandle_t chosen, aliases;
phandle_t dnode;
int props[2];
char buf[64];
nvram = (char*)addr + IO_NVRAM_OFFSET;
snprintf(buf, sizeof(buf), "%s/nvram", path);
nvram_init(buf);
dnode = find_dev(buf);
set_int_property(dnode, "#bytes", arch_nvram_size() );
props[0] = __cpu_to_be32(IO_NVRAM_OFFSET);
props[1] = __cpu_to_be32(IO_NVRAM_SIZE);
set_property(dnode, "reg", (char *)&props, sizeof(props));
set_property(dnode, "device_type", "nvram", 6);
chosen = find_dev("/chosen");
push_str(buf);
fword("open-dev");
set_int_property(chosen, "nvram", POP());
aliases = find_dev("/aliases");
set_property(aliases, "nvram", buf, strlen(buf) + 1);
}
#ifdef DUMP_NVRAM
static void
dump_nvram(void)
{
int i, j;
for (i = 0; i < 10; i++)
{
for (j = 0; j < 16; j++)
printk ("%02x ", nvram[(i*16+j)<<4]);
printk (" ");
for (j = 0; j < 16; j++)
if (isprint(nvram[(i*16+j)<<4]))
printk("%c", nvram[(i*16+j)<<4]);
else
printk(".");
printk ("\n");
}
}
#endif
void
arch_nvram_put( char *buf )
{
int i;
for (i=0; i< arch_nvram_size() ; i++)
nvram[i<<4]=buf[i];
#ifdef DUMP_NVRAM
printk("new nvram:\n");
dump_nvram();
#endif
}
void
arch_nvram_get( char *buf )
{
int i;
for (i=0; i< arch_nvram_size(); i++)
buf[i]=nvram[i<<4];
#ifdef DUMP_NVRAM
printk("current nvram:\n");
dump_nvram();
#endif
}
DECLARE_UNNAMED_NODE( ob_intctrl_node, INSTALL_OPEN, 2*sizeof(int) );
static void
ob_intctrl_open(int *idx)
{
int ret=1;
RET ( -ret );
}
static void
ob_intctrl_close(int *idx)
{
}
static void
ob_intctrl_initialize(int *idx)
{
}
NODE_METHODS(ob_intctrl_node) = {
{ NULL, ob_intctrl_initialize },
{ "open", ob_intctrl_open },
{ "close", ob_intctrl_close },
};
phandle_t pic_handle;
void
ob_macio_init(const char *path, uint32_t addr)
{
char buf[64];
phandle_t ph, chosen, aliases;
cell props[2];
aliases = find_dev("/aliases");
set_property(aliases, "mac-io", path, strlen(path) + 1);
snprintf(buf, sizeof(buf), "%s/interrupt-controller", path);
REGISTER_NAMED_NODE(ob_intctrl_node, buf);
ph = find_dev(buf);
set_property(ph, "device_type", "interrupt-controller", 21);
set_property(ph, "compatible", "heathrow\0mac-risc", 18);
set_int_property(ph, "#interrupt-cells", 1);
props[0]= 0x00000010;
props[1]= 0x00000020;
set_property(ph, "reg", (char *)&props, 2 * sizeof(props));
set_property(ph, "interrupt-controller", NULL, 0);
chosen = find_dev("/chosen");
push_str(buf);
fword("open-dev");
ph = POP();
set_int_property(chosen, "interrupt-controller", ph);
pic_handle = ph;
cuda_init(path, addr);
macio_nvram_init(path, addr);
}

4
drivers/macio.h Normal file
View File

@@ -0,0 +1,4 @@
extern phandle_t pic_handle;
void ob_macio_init(const char *path, uint32_t addr);
void macio_nvram_init(const char *path, uint32_t addr);

View File

@@ -27,7 +27,10 @@
#include "timer.h"
#include "pci.h"
#include "pci_database.h"
#ifdef CONFIG_DRIVER_MACIO
#include "cuda.h"
#include "macio.h"
#endif
#define set_bool_property(ph, name) set_property(ph, name, NULL, 0);
@@ -93,28 +96,10 @@ int eth_config_cb (const pci_config_t *config)
return 0;
}
phandle_t pic_handle;
int macio_config_cb (const pci_config_t *config)
{
#ifdef CONFIG_PPC
char buf[64];
phandle_t ph;
cell props[2];
snprintf(buf, sizeof(buf), "%s/interrupt-controller", config->path);
REGISTER_NAMED_NODE(ob_pci_node, buf);
ph = find_dev(buf);
set_property(ph, "device_type", "interrupt-controller", 21);
set_property(ph, "compatible", "heathrow\0mac-risc", 18);
set_int_property(ph, "#interrupt-cells", 1);
props[0]= 0x10;
props[1]= 0x20;
set_property(ph, "reg", (char *)&props, sizeof(props));
pic_handle = ph;
cuda_init(config->path, config->regions[0]);
macio_nvram_init(config->path, config->regions[0]);
#ifdef CONFIG_DRIVER_MACIO
ob_macio_init(config->path, config->regions[0] & ~0x0000000F);
#endif
return 0;
}

View File

@@ -16,9 +16,6 @@
#ifdef CONFIG_DRIVER_PCI
/* drivers/pci.c */
int ob_pci_init(void);
/* arch/ppc/qemu/qemu.c */
void macio_nvram_init(const char *path, uint32_t addr);
#endif
#ifdef CONFIG_DRIVER_SBUS
/* drivers/sbus.c */