I'm trying to write a busmouse driver and I can't get it to compile.  It
seems like there's a header issue of some sort that I can't work out.

Of course, if someone has a working busmouse driver for qemu, that would
be great:  OpenStep won't work with the ps/2 emulation and even after
pounding on it for a few days I can't seem to narrow down why it OS
stops paying attention to it.  The consensus in 2006 was "fix the ps/2
emulation" but apparently nobody has been able to figure out how its
broken and this seems like a reasonable solution. 

My code is based on the pc98 busmouse driver by TAKEDA, toshiya and the
busmouse patches that floated around the list over the last few years.

Anyway, it seems like a typedef is wrong.  Did I miss something obvious?

Thanks
Brian

I'm getting:
==============================
In file included from /home/bdwheele/Projects/qemu/hw/pc.h:7,
                 from /home/bdwheele/Projects/qemu/hw/busmouse.c:30:
/home/bdwheele/Projects/qemu/hw/isa.h:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ 
or ‘__attribute__’ before ‘isa_mem_base’
/home/bdwheele/Projects/qemu/hw/isa.h:35: error: expected ‘)’ before ‘base’
In file included from /home/bdwheele/Projects/qemu/hw/pc.h:8,
                 from /home/bdwheele/Projects/qemu/hw/busmouse.c:30:
/home/bdwheele/Projects/qemu/hw/fdc.h:11: error: expected declaration 
specifiers or ‘...’ before ‘target_phys_addr_t’
/home/bdwheele/Projects/qemu/hw/fdc.h:12: error: expected declaration 
specifiers or ‘...’ before ‘target_phys_addr_t’
In file included from /home/bdwheele/Projects/qemu/hw/busmouse.c:30:
/home/bdwheele/Projects/qemu/hw/pc.h:15: error: expected ‘)’ before ‘base’
/home/bdwheele/Projects/qemu/hw/pc.h:26: error: expected ‘)’ before ‘base’
/home/bdwheele/Projects/qemu/hw/pc.h:78: error: expected declaration specifiers 
or ‘...’ before ‘target_phys_addr_t’
/home/bdwheele/Projects/qemu/hw/pc.h:78: error: expected declaration specifiers 
or ‘...’ before ‘ram_addr_t’
/home/bdwheele/Projects/qemu/hw/pc.h:79: error: expected declaration specifiers 
or ‘...’ before ‘target_phys_addr_t’
/home/bdwheele/Projects/qemu/hw/pc.h:91: error: expected ‘)’ before ‘ram_size’
/home/bdwheele/Projects/qemu/hw/pc.h:106: error: expected ‘)’ before ‘ram_size’
/home/bdwheele/Projects/qemu/hw/pc.h:141: error: expected declaration 
specifiers or ‘...’ before ‘ram_addr_t’
/home/bdwheele/Projects/qemu/hw/pc.h:159: error: expected ‘)’ before ‘vram_base’
=========================================

I've added it to Makefile.objs:
=========================================
diff --git a/Makefile.objs b/Makefile.objs
index 816194a..908c21f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -81,7 +81,7 @@ common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o 
bt-hci.o bt-hid.o u
 common-obj-y += bt-hci-csr.o
 common-obj-y += buffered_file.o migration.o migration-tcp.o qemu-sockets.o
 common-obj-y += qemu-char.o savevm.o #aio.o
-common-obj-y += msmouse.o ps2.o
+common-obj-y += msmouse.o ps2.o busmouse.o
 common-obj-y += qdev.o qdev-properties.o
 common-obj-y += block-migration.o
 common-obj-y += pflib.o
==================================================

and here's the source:
=========================
#include "hw.h"
#include "pc.h"
#include "isa.h"
#include "qdev.h"
#include "console.h"

struct mouse_t {
    int button;
    int dx, dy;
    uint8_t index;
    qemu_irq irq;
    int irq_pending;
};

typedef struct mouse_isabus_t {
    ISADevice busdev;
    struct mouse_t state;
} mouse_isabus_t;

typedef struct mouse_t mouse_t;

/* mouse */

static void mouse_event_handler(void *opaque,
                                int dx, int dy, int dz, int buttons_state)
{
    mouse_t *s = opaque;
    s->button = buttons_state;
    s->dx += dx;
    s->dy += dy;
    s->irq_pending = 1;
}


static void busmouse_update_irq(mouse_t *s)
{
    if (s->irq_pending) {
        qemu_set_irq(s->irq, 1);
    } else {
        qemu_set_irq(s->irq, 0);
    }
}


/* pio */

static void busmouse_pio_write(void *opaque, uint32_t addr, uint32_t val)
{
    mouse_t *s = opaque;
    switch(addr) {
    case 0:  //data
        break;
    case 1: // signature
        break;
    case 2: // control
        s->index = val;
        break;
    case 3: // config
        break;
    }
        

}

static uint32_t busmouse_pio_read(void *opaque, uint32_t addr)
{
    mouse_t *s = opaque;
    uint32_t val = 0;
    static int interrupt_val = 0x01;
    s->irq_pending = 0;
    switch(addr) {
    case 0: // data
        s->irq_pending = 0;
        val |= (s->button & 1)? 0x80 : 0x00;
        val |= (s->button & 2)? 0x40 : 0x00;
        val |= (s->button & 4)? 0x20 : 0x00;
        val |= ((s->index & 0x40? s->dy : s->dx) >> (s->index & 0x20? 4 : 0)) & 
0x0f;
        busmouse_update_irq(s);
        break;
    case 1: // signature
        val = 0xa5; 
        busmouse_update_irq(s);
        break;
    case 2: // control
        val = interrupt_val;
        interrupt_val = (interrupt_val << 1) && 0xff;
        if (interrupt_val == 0) interrupt_val = 1;
        break;
    case 3: // config?
        break;
    }
    return val;
}
/* interface */

static void busmouse_reset(void *opaque)
{
    mouse_t *s = opaque;

    s->button = 0;
    s->dx = s->dy = 0;
    s->index = 0xf0;
}

static int busmouse_pre_load(void *opaque)
{
    busmouse_reset(opaque);
    return 0;
}

static const VMStateDescription vmstate_mouse = {
    .name = "logitech-busmouse",
    .version_id = 1,
    .minimum_version_id = 1,
    .minimum_version_id_old = 1,
    .pre_load = busmouse_pre_load,
    .fields      = (VMStateField []) {
        VMSTATE_UINT8(index, mouse_t),
        VMSTATE_END_OF_LIST()
    }
};

static int busmouse_init1(ISADevice *dev)
{
    mouse_isabus_t *isa = DO_UPCAST(mouse_isabus_t, busdev, dev);
    mouse_t *s = &isa->state;
    register_ioport_read(0x23c, 4, 1, busmouse_pio_read, s);
    register_ioport_write(0x23c, 4, 1, busmouse_pio_write, s);

    isa_init_irq(&isa->busdev, &s->irq, 3);
    qemu_add_mouse_event_handler(mouse_event_handler, s, 0, "busmouse");

    //vmstate_register(-1, &vmstate_mouse, s);
    busmouse_reset(s);
    qemu_register_reset(busmouse_reset, s);
    return 0;
}

static ISADeviceInfo busmouse_info = {
    .init = busmouse_init1,
    .qdev.name  = "busmouse",
    .qdev.size  = sizeof(mouse_isabus_t),
};

static void busmouse_register_devices(void)
{
    isa_qdev_register(&busmouse_info);
}

device_init(busmouse_register_devices)
=========================


Reply via email to