mirror of
https://gitlab.com/qemu-project/openbios.git
synced 2024-02-13 08:34:06 +08:00
ADB/CUDA fixes
git-svn-id: svn://coreboot.org/openbios/openbios-devel@259 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
extern void unexpected_excep( int vector );
|
||||
extern void ob_ide_init( void );
|
||||
extern void ob_pci_init( void );
|
||||
extern void ob_adb_init( void );
|
||||
extern void setup_timers( void );
|
||||
|
||||
void
|
||||
@@ -113,9 +112,6 @@ arch_of_init( void )
|
||||
#ifdef CONFIG_DRIVER_IDE
|
||||
ob_ide_init();
|
||||
#endif
|
||||
#ifdef CONFIG_DRIVER_ADB
|
||||
ob_adb_init();
|
||||
#endif
|
||||
|
||||
node_methods_init();
|
||||
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
|
||||
\ preopen device nodes (and store the ihandles under /chosen)
|
||||
:noname
|
||||
" rtc" " /pci/isa/rtc" preopen
|
||||
" rtc" " rtc" preopen
|
||||
" memory" " /memory" preopen
|
||||
" mmu" " /cpu@0" preopen
|
||||
\ " stdout" " /packages/terminal-emulator" preopen
|
||||
" stdout" " /pci/pci6666,6666" preopen
|
||||
" stdin" " /pci/via-cuda/adb" preopen
|
||||
" stdout" " screen" preopen
|
||||
" stdin" " adb-keyboard" preopen
|
||||
|
||||
; SYSTEM-initializer
|
||||
|
||||
@@ -93,8 +93,8 @@
|
||||
\ use the tty interface if available
|
||||
: activate-tty-interface
|
||||
" /packages/terminal-emulator" find-dev if drop
|
||||
" /pci/via-cuda/adb" " input-device" $setenv
|
||||
" /pci/pci6666,6666" " output-device" $setenv
|
||||
" adb-keyboard" " input-device" $setenv
|
||||
" screen" " output-device" $setenv
|
||||
then
|
||||
;
|
||||
|
||||
|
||||
150
drivers/adb.c
150
drivers/adb.c
@@ -27,8 +27,10 @@
|
||||
#include "adb.h"
|
||||
#include "kbd.h"
|
||||
#include "cuda.h"
|
||||
#include "libc/byteorder.h"
|
||||
#include "libc/vsprintf.h"
|
||||
|
||||
#define DEBUG_ADB 1
|
||||
//#define DEBUG_ADB 1
|
||||
|
||||
#ifdef DEBUG_ADB
|
||||
#define ADB_DPRINTF(fmt, args...) \
|
||||
@@ -37,7 +39,28 @@ do { printk("ADB - %s: " fmt, __func__ , ##args); } while (0)
|
||||
#define ADB_DPRINTF(fmt, args...) do { } while (0)
|
||||
#endif
|
||||
|
||||
DECLARE_NODE( adb, INSTALL_OPEN, 0, "/pci/via-cuda/adb" );
|
||||
static void adb_read(void);
|
||||
|
||||
DECLARE_UNNAMED_NODE( keyboard, INSTALL_OPEN, sizeof(int));
|
||||
|
||||
static void
|
||||
keyboard_open(int *idx)
|
||||
{
|
||||
RET(-1);
|
||||
}
|
||||
|
||||
static void
|
||||
keyboard_close(int *idx)
|
||||
{
|
||||
}
|
||||
|
||||
static void keyboard_read(void);
|
||||
|
||||
NODE_METHODS( keyboard ) = {
|
||||
{ "open", keyboard_open },
|
||||
{ "close", keyboard_close },
|
||||
{ "read", keyboard_read },
|
||||
};
|
||||
|
||||
/* ADB US keyboard translation map
|
||||
* XXX: for now, only shift modifier is defined
|
||||
@@ -424,13 +447,8 @@ struct adb_kbd_t {
|
||||
int next_key;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static adb_kbd_t *my_adb_kbd;
|
||||
adb_dev_t *my_adb_dev;
|
||||
//={ NULL, NULL, 2, 1, (unsigned int)0x80816000 };
|
||||
static adb_kbd_t *my_adb_kbd = NULL;
|
||||
static adb_dev_t *my_adb_dev = NULL;
|
||||
|
||||
static int adb_kbd_read (void *private)
|
||||
{
|
||||
@@ -441,7 +459,6 @@ static int adb_kbd_read (void *private)
|
||||
int ret;
|
||||
|
||||
kbd = (void *)dev->state;
|
||||
//ADB_DPRINTF("enter\n");
|
||||
/* Get saved state */
|
||||
ret = -1;
|
||||
for (key = -1; key == -1; ) {
|
||||
@@ -449,9 +466,8 @@ static int adb_kbd_read (void *private)
|
||||
key = kbd->next_key;
|
||||
kbd->next_key = -1;
|
||||
} else {
|
||||
if (adb_reg_get(dev, 0, buffer) != 2) {
|
||||
goto out;
|
||||
}
|
||||
if (adb_reg_get(dev, 0, buffer) != 2)
|
||||
break;
|
||||
kbd->next_key = buffer[1] == 0xFF ? -1 : buffer[1];
|
||||
key = buffer[0];
|
||||
}
|
||||
@@ -459,42 +475,99 @@ static int adb_kbd_read (void *private)
|
||||
ADB_DPRINTF("Translated %d (%02x) into %d (%02x)\n",
|
||||
key, key, ret, ret);
|
||||
}
|
||||
out:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void *adb_kbd_new (void *private)
|
||||
void *adb_kbd_new (char *path, void *private)
|
||||
{
|
||||
adb_kbd_t *kbd=my_adb_kbd;
|
||||
|
||||
char buf[64];
|
||||
int props[1];
|
||||
phandle_t ph, aliases;
|
||||
adb_kbd_t *kbd;
|
||||
adb_dev_t *dev = private;
|
||||
kbd = (adb_kbd_t*)malloc(sizeof(adb_kbd_t));
|
||||
if (kbd != NULL) {
|
||||
memset(kbd, 0, sizeof(adb_kbd_t));
|
||||
kbd_set_keymap(&kbd->kbd, sizeof(ADB_kbd_us) / sizeof(keymap_t), ADB_kbd_us);
|
||||
kbd_set_keymap(&kbd->kbd, sizeof(ADB_kbd_us) / sizeof(keymap_t),
|
||||
ADB_kbd_us);
|
||||
kbd->next_key = -1;
|
||||
dev->state = (int32_t)kbd;
|
||||
my_adb_dev = dev;
|
||||
}
|
||||
|
||||
//my_adb_dev.state=(unsigned int)my_adb_kbd;
|
||||
my_adb_dev=private;
|
||||
return NULL;
|
||||
sprintf(buf, "%s/keyboard", path);
|
||||
REGISTER_NAMED_NODE( keyboard, buf);
|
||||
|
||||
ph = find_dev(buf);
|
||||
|
||||
set_property(ph, "device_type", "keyboard", 9);
|
||||
props[0] = __cpu_to_be32(dev->addr);
|
||||
set_property(ph, "reg", &props, sizeof(props));
|
||||
|
||||
aliases = find_dev("/aliases");
|
||||
set_property(aliases, "adb-keyboard", buf, strlen(buf) + 1);
|
||||
|
||||
return kbd;
|
||||
}
|
||||
|
||||
/* ( addr len -- actual ) */
|
||||
void adb_read(void)
|
||||
static void keyboard_read(void)
|
||||
{
|
||||
char *addr;
|
||||
int len, key;
|
||||
int len, key, i;
|
||||
len=POP();
|
||||
addr=(char *)POP();
|
||||
|
||||
if(len!=1) printk("adb_read: %x %x\n", (unsigned int)addr , len);
|
||||
for (i = 0; i < len; i++) {
|
||||
key = adb_kbd_read(my_adb_dev);
|
||||
if (key == -1 || key == -2)
|
||||
break;
|
||||
*addr++ = (char)key;
|
||||
}
|
||||
PUSH(i);
|
||||
}
|
||||
|
||||
key=adb_kbd_read(my_adb_dev);
|
||||
//key=-1;
|
||||
if (key!=-1) {
|
||||
*addr=(char)key;
|
||||
PUSH(1);
|
||||
} else
|
||||
PUSH(0);
|
||||
DECLARE_UNNAMED_NODE( mouse, INSTALL_OPEN, sizeof(int));
|
||||
|
||||
static void
|
||||
mouse_open(int *idx)
|
||||
{
|
||||
RET(-1);
|
||||
}
|
||||
|
||||
static void
|
||||
mouse_close(int *idx)
|
||||
{
|
||||
}
|
||||
|
||||
static void mouse_read(void);
|
||||
|
||||
NODE_METHODS( mouse ) = {
|
||||
{ "open", mouse_open },
|
||||
{ "close", mouse_close },
|
||||
};
|
||||
|
||||
void *adb_mouse_new (char *path, void *private)
|
||||
{
|
||||
char buf[64];
|
||||
int props[1];
|
||||
phandle_t ph, aliases;
|
||||
adb_dev_t *dev = private;
|
||||
|
||||
sprintf(buf, "%s/mouse", path);
|
||||
REGISTER_NAMED_NODE( mouse, buf);
|
||||
|
||||
ph = find_dev(buf);
|
||||
|
||||
set_property(ph, "device_type", "mouse", 6);
|
||||
props[0] = __cpu_to_be32(dev->addr);
|
||||
set_property(ph, "reg", &props, sizeof(props));
|
||||
set_int_property(ph, "#buttons", 3);
|
||||
|
||||
aliases = find_dev("/aliases");
|
||||
set_property(aliases, "adb-mouse", buf, strlen(buf) + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -561,18 +634,3 @@ int adb_cmd (adb_dev_t *dev, uint8_t cmd, uint8_t reg,
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
NODE_METHODS( adb ) = {
|
||||
{ "read", adb_read },
|
||||
};
|
||||
|
||||
int ob_adb_init(void)
|
||||
{
|
||||
printk("Initializing ADB driver\n");
|
||||
cuda_init(0x80800000 + 0x16000);
|
||||
REGISTER_NODE( adb );
|
||||
//adb_kbd_new();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
[IFDEF] CONFIG_DRIVER_ADB
|
||||
|
||||
dev /pci
|
||||
\ simple pci bus node
|
||||
new-device
|
||||
" via-cuda" device-name
|
||||
" via-cuda" encode-string " device_type" property
|
||||
" cuda" encode-string " compatible" property
|
||||
|
||||
external
|
||||
: open ( ." opening CUDA" cr ) true ;
|
||||
: close ;
|
||||
: decode-unit 0 decode-unit-pci-bus ;
|
||||
: encode-unit encode-unit-pci ;
|
||||
finish-device
|
||||
|
||||
dev /pci/via-cuda
|
||||
|
||||
new-device
|
||||
" adb" device-name
|
||||
" adb" encode-string " device_type" property
|
||||
0 encode-int " #size-cells" property
|
||||
1 encode-int " #address-cells" property
|
||||
|
||||
external
|
||||
: open ( ." opening ADB" cr ) true ;
|
||||
: close ;
|
||||
finish-device
|
||||
|
||||
device-end
|
||||
|
||||
[THEN]
|
||||
|
||||
@@ -71,7 +71,7 @@ void adb_bus_reset (adb_bus_t *bus);
|
||||
adb_bus_t *adb_bus_new (void *host,
|
||||
int (*req)(void *host, const uint8_t *snd_buf,
|
||||
int len, uint8_t *rcv_buf));
|
||||
int adb_bus_init (adb_bus_t *bus);
|
||||
int adb_bus_init (char *path, adb_bus_t *bus);
|
||||
|
||||
static inline int adb_reset (adb_bus_t *bus)
|
||||
{
|
||||
@@ -99,7 +99,7 @@ static inline int adb_reg_set (adb_dev_t *dev, uint8_t reg,
|
||||
return adb_cmd(dev, ADB_LISTEN, reg, buf, len);
|
||||
}
|
||||
|
||||
void *adb_kbd_new (void *private);
|
||||
void *adb_kbd_new (char *path, void *private);
|
||||
|
||||
|
||||
#endif /* !defined(__OHW_ADB_H__) */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<object source="timer.c" condition="DRIVER_IDE"/>
|
||||
<object source="kbd.c" condition="DRIVER_ADB"/>
|
||||
<object source="adb.c" condition="DRIVER_ADB"/>
|
||||
<object source="cuda.c" condition="DRIVER_ADB"/>
|
||||
<object source="cuda.c" condition="DRIVER_PCI"/>
|
||||
<object source="floppy.c" condition="DRIVER_FLOPPY"/>
|
||||
<object source="iommu.c" condition="DRIVER_SBUS"/>
|
||||
<object source="sbus.c" condition="DRIVER_SBUS"/>
|
||||
@@ -20,7 +20,6 @@
|
||||
<dictionary name="openbios" target="forth">
|
||||
<object source="pci.fs" condition="DRIVER_PCI"/>
|
||||
<object source="ide.fs" condition="DRIVER_IDE"/>
|
||||
<object source="adb.fs" condition="DRIVER_ADB"/>
|
||||
<object source="sbus.fs" condition="DRIVER_SBUS"/>
|
||||
<object source="esp.fs" condition="DRIVER_ESP"/>
|
||||
</dictionary>
|
||||
|
||||
156
drivers/cuda.c
156
drivers/cuda.c
@@ -1,10 +1,13 @@
|
||||
#include "openbios/config.h"
|
||||
#include "openbios/bindings.h"
|
||||
#include "libc/byteorder.h"
|
||||
#include "libc/vsprintf.h"
|
||||
|
||||
#include "adb.h"
|
||||
|
||||
|
||||
#include "cuda.h"
|
||||
#define DEBUG_CUDA
|
||||
//#define DEBUG_CUDA
|
||||
#ifdef DEBUG_CUDA
|
||||
#define CUDA_DPRINTF(fmt, args...) \
|
||||
do { printk("CUDA - %s: " fmt, __func__ , ##args); } while (0)
|
||||
@@ -13,6 +16,9 @@
|
||||
#endif
|
||||
#define ADB_DPRINTF CUDA_DPRINTF
|
||||
|
||||
#define IO_CUDA_OFFSET 0x00016000
|
||||
#define IO_CUDA_SIZE 0x00002000
|
||||
|
||||
/* VIA registers - spaced 0x200 bytes apart */
|
||||
#define RS 0x200 /* skip between registers */
|
||||
#define B 0 /* B-side data */
|
||||
@@ -145,26 +151,157 @@ static int cuda_adb_req (void *host, const uint8_t *snd_buf, int len,
|
||||
}
|
||||
|
||||
|
||||
cuda_t *cuda_init (uint32_t base)
|
||||
DECLARE_UNNAMED_NODE(ob_cuda, INSTALL_OPEN, sizeof(int));
|
||||
|
||||
static void
|
||||
ob_cuda_initialize (int *idx)
|
||||
{
|
||||
extern phandle_t pic_handle;
|
||||
phandle_t ph=get_cur_dev();
|
||||
int props[2];
|
||||
|
||||
push_str("via-cuda");
|
||||
fword("device-type");
|
||||
|
||||
set_int_property(ph, "#address-cells", 1);
|
||||
set_int_property(ph, "#size-cells", 0);
|
||||
|
||||
set_property(ph, "compatible", "cuda", 5);
|
||||
|
||||
props[0] = __cpu_to_be32(IO_CUDA_OFFSET);
|
||||
props[1] = __cpu_to_be32(IO_CUDA_SIZE);
|
||||
|
||||
set_property(ph, "reg", &props, sizeof(props));
|
||||
set_int_property(ph, "interrupt-parent", pic_handle);
|
||||
// HEATHROW
|
||||
set_int_property(ph, "interrupts", 0x12);
|
||||
}
|
||||
|
||||
static void
|
||||
ob_cuda_open(int *idx)
|
||||
{
|
||||
RET(-1);
|
||||
}
|
||||
|
||||
static void
|
||||
ob_cuda_close(int *idx)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
ob_cuda_decode_unit(void *private)
|
||||
{
|
||||
PUSH(0);
|
||||
fword("decode-unit-pci-bus");
|
||||
}
|
||||
|
||||
static void
|
||||
ob_cuda_encode_unit(void *private)
|
||||
{
|
||||
fword("encode-unit-pci");
|
||||
}
|
||||
|
||||
NODE_METHODS(ob_cuda) = {
|
||||
{ NULL, ob_cuda_initialize },
|
||||
{ "open", ob_cuda_open },
|
||||
{ "close", ob_cuda_close },
|
||||
{ "decode-unit", ob_cuda_decode_unit },
|
||||
{ "encode-unit", ob_cuda_encode_unit },
|
||||
};
|
||||
|
||||
DECLARE_UNNAMED_NODE(rtc, INSTALL_OPEN, sizeof(int));
|
||||
|
||||
static void
|
||||
rtc_open(int *idx)
|
||||
{
|
||||
RET(-1);
|
||||
}
|
||||
|
||||
NODE_METHODS(rtc) = {
|
||||
{ "open", rtc_open },
|
||||
};
|
||||
|
||||
static void
|
||||
rtc_init(char *path)
|
||||
{
|
||||
phandle_t ph, aliases;
|
||||
char buf[64];
|
||||
|
||||
sprintf(buf, "%s/rtc", path);
|
||||
REGISTER_NAMED_NODE(rtc, buf);
|
||||
|
||||
ph = find_dev(buf);
|
||||
set_property(ph, "device_type", "rtc", 4);
|
||||
set_property(ph, "compatible", "rtc", 4);
|
||||
|
||||
aliases = find_dev("/aliases");
|
||||
set_property(aliases, "rtc", buf, strlen(buf) + 1);
|
||||
|
||||
}
|
||||
|
||||
cuda_t *cuda_init (char *path, uint32_t base)
|
||||
{
|
||||
cuda_t *cuda;
|
||||
char buf[64];
|
||||
|
||||
//CUDA_DPRINTF(" base=%08x\n", base);
|
||||
base += IO_CUDA_OFFSET;
|
||||
CUDA_DPRINTF(" base=%08x\n", base);
|
||||
cuda = malloc(sizeof(cuda_t));
|
||||
if (cuda == NULL)
|
||||
return NULL;
|
||||
|
||||
sprintf(buf, "%s/via-cuda", path);
|
||||
REGISTER_NAMED_NODE(ob_cuda, buf);
|
||||
|
||||
cuda->base = base;
|
||||
cuda_writeb(cuda, B, cuda_readb(cuda, B) | TREQ | TIP);
|
||||
#ifdef CONFIG_DRIVER_ADB
|
||||
cuda->adb_bus = adb_bus_new(cuda, &cuda_adb_req);
|
||||
if (cuda->adb_bus == NULL) {
|
||||
free(cuda);
|
||||
return NULL;
|
||||
}
|
||||
adb_bus_init(cuda->adb_bus);
|
||||
adb_bus_init(buf, cuda->adb_bus);
|
||||
#endif
|
||||
|
||||
rtc_init(buf);
|
||||
|
||||
return cuda;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DRIVER_ADB
|
||||
|
||||
DECLARE_UNNAMED_NODE( adb, INSTALL_OPEN, sizeof(int));
|
||||
|
||||
static void
|
||||
adb_initialize (int *idx)
|
||||
{
|
||||
phandle_t ph=get_cur_dev();
|
||||
|
||||
push_str("adb");
|
||||
fword("device-type");
|
||||
|
||||
set_property(ph, "compatible", "adb", 4);
|
||||
set_int_property(ph, "#address-cells", 1);
|
||||
set_int_property(ph, "#size-cells", 0);
|
||||
}
|
||||
|
||||
static void
|
||||
adb_open(int *idx)
|
||||
{
|
||||
RET(-1);
|
||||
}
|
||||
|
||||
static void
|
||||
adb_close(int *idx)
|
||||
{
|
||||
}
|
||||
|
||||
NODE_METHODS( adb ) = {
|
||||
{ NULL, adb_initialize },
|
||||
{ "open", adb_open },
|
||||
{ "close", adb_close },
|
||||
};
|
||||
|
||||
adb_bus_t *adb_bus_new (void *host,
|
||||
int (*req)(void *host, const uint8_t *snd_buf,
|
||||
@@ -184,8 +321,9 @@ adb_bus_t *adb_bus_new (void *host,
|
||||
/* Check and relocate all ADB devices as suggested in
|
||||
* * ADB_manager Apple documentation
|
||||
* */
|
||||
int adb_bus_init (adb_bus_t *bus)
|
||||
int adb_bus_init (char *path, adb_bus_t *bus)
|
||||
{
|
||||
char buf[64];
|
||||
uint8_t buffer[ADB_BUF_SIZE];
|
||||
uint8_t adb_addresses[16] =
|
||||
{ 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, 0, };
|
||||
@@ -194,6 +332,8 @@ int adb_bus_init (adb_bus_t *bus)
|
||||
int reloc = 0, next_free = 7;
|
||||
int keep;
|
||||
|
||||
sprintf(buf, "%s/adb", path);
|
||||
REGISTER_NAMED_NODE( adb, buf);
|
||||
/* Reset the bus */
|
||||
// ADB_DPRINTF("\n");
|
||||
adb_reset(bus);
|
||||
@@ -258,11 +398,11 @@ int adb_bus_init (adb_bus_t *bus)
|
||||
break;
|
||||
case ADB_KEYBD:
|
||||
ADB_DPRINTF("Found one keyboard on address %d\n", address);
|
||||
adb_kbd_new(*cur);
|
||||
adb_kbd_new(buf, *cur);
|
||||
break;
|
||||
case ADB_MOUSE:
|
||||
ADB_DPRINTF("Found one mouse on address %d\n", address);
|
||||
//chardev_register(CHARDEV_MOUSE, &adb_mouse_ops, *cur);
|
||||
adb_mouse_new(buf, *cur);
|
||||
break;
|
||||
case ADB_ABS:
|
||||
ADB_DPRINTF("Found one absolute positioning device\n");
|
||||
@@ -294,4 +434,4 @@ int adb_bus_init (adb_bus_t *bus)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,6 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
cuda_t *cuda_init (uint32_t base);
|
||||
cuda_t *cuda_init (char *path, uint32_t base);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user