Install keymaps from new location
[qemu] / hw / eepro100.c
index 975aeb1..fcb091c 100644 (file)
 # warning "PXE boot still not working!"
 #endif
 
-#include <assert.h>
 #include <stddef.h>             /* offsetof */
-#include "vl.h"
+#include "hw.h"
+#include "pci.h"
+#include "net.h"
 #include "eeprom93xx.h"
 
 /* Common declarations for all PCI devices. */
 
-#define PCI_VENDOR_ID           0x00    /* 16 bits */
-#define PCI_DEVICE_ID           0x02    /* 16 bits */
-#define PCI_COMMAND             0x04    /* 16 bits */
-#define PCI_STATUS              0x06    /* 16 bits */
-
-#define PCI_REVISION_ID         0x08    /* 8 bits  */
-#define PCI_CLASS_CODE          0x0b    /* 8 bits */
-#define PCI_SUBCLASS_CODE       0x0a    /* 8 bits */
-#define PCI_HEADER_TYPE         0x0e    /* 8 bits */
-
-#define PCI_BASE_ADDRESS_0      0x10    /* 32 bits */
-#define PCI_BASE_ADDRESS_1      0x14    /* 32 bits */
-#define PCI_BASE_ADDRESS_2      0x18    /* 32 bits */
-#define PCI_BASE_ADDRESS_3      0x1c    /* 32 bits */
-#define PCI_BASE_ADDRESS_4      0x20    /* 32 bits */
-#define PCI_BASE_ADDRESS_5      0x24    /* 32 bits */
-
 #define PCI_CONFIG_8(offset, value) \
     (pci_conf[offset] = (value))
 #define PCI_CONFIG_16(offset, value) \
@@ -75,9 +59,9 @@
 //~ #define DEBUG_EEPRO100
 
 #ifdef DEBUG_EEPRO100
-#define logout(fmt, args...) fprintf(stderr, "EE100\t%-24s" fmt, __func__, ##args)
+#define logout(fmt, ...) fprintf(stderr, "EE100\t%-24s" fmt, __func__, ## __VA_ARGS__)
 #else
-#define logout(fmt, args...) ((void)0)
+#define logout(fmt, ...) ((void)0)
 #endif
 
 /* Set flags to 0 to disable debug output. */
@@ -197,12 +181,6 @@ typedef enum {
     ru_ready = 4
 } ru_state_t;
 
-#if defined(__BIG_ENDIAN_BITFIELD)
-#define X(a,b) b,a
-#else
-#define X(a,b) a,b
-#endif
-
 typedef struct {
 #if 1
     uint8_t cmd;
@@ -420,9 +398,9 @@ static void pci_reset(EEPRO100State * s)
     logout("%p\n", s);
 
     /* PCI Vendor ID */
-    PCI_CONFIG_16(PCI_VENDOR_ID, 0x8086);
+    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
     /* PCI Device ID */
-    PCI_CONFIG_16(PCI_DEVICE_ID, 0x1209);
+    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82551IT);
     /* PCI Command */
     PCI_CONFIG_16(PCI_COMMAND, 0x0000);
     /* PCI Status */
@@ -431,8 +409,7 @@ static void pci_reset(EEPRO100State * s)
     PCI_CONFIG_8(PCI_REVISION_ID, 0x08);
     /* PCI Class Code */
     PCI_CONFIG_8(0x09, 0x00);
-    PCI_CONFIG_8(PCI_SUBCLASS_CODE, 0x00);      // ethernet network controller
-    PCI_CONFIG_8(PCI_CLASS_CODE, 0x02); // network controller
+    pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
     /* PCI Cache Line Size */
     /* check cache line size!!! */
     //~ PCI_CONFIG_8(0x0c, 0x00);
@@ -1390,7 +1367,6 @@ static void pci_map(PCIDevice * pci_dev, int region_num,
 static void pci_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    addr -= s->region[0];
     //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
     eepro100_write1(s, addr, val);
 }
@@ -1398,7 +1374,6 @@ static void pci_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
 static void pci_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    addr -= s->region[0];
     //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
     eepro100_write2(s, addr, val);
 }
@@ -1406,7 +1381,6 @@ static void pci_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 static void pci_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
     EEPRO100State *s = opaque;
-    addr -= s->region[0];
     //~ logout("addr=%s val=0x%02x\n", regname(addr), val);
     eepro100_write4(s, addr, val);
 }
@@ -1414,7 +1388,6 @@ static void pci_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 static uint32_t pci_mmio_readb(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    addr -= s->region[0];
     //~ logout("addr=%s\n", regname(addr));
     return eepro100_read1(s, addr);
 }
@@ -1422,7 +1395,6 @@ static uint32_t pci_mmio_readb(void *opaque, target_phys_addr_t addr)
 static uint32_t pci_mmio_readw(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    addr -= s->region[0];
     //~ logout("addr=%s\n", regname(addr));
     return eepro100_read2(s, addr);
 }
@@ -1430,7 +1402,6 @@ static uint32_t pci_mmio_readw(void *opaque, target_phys_addr_t addr)
 static uint32_t pci_mmio_readl(void *opaque, target_phys_addr_t addr)
 {
     EEPRO100State *s = opaque;
-    addr -= s->region[0];
     //~ logout("addr=%s\n", regname(addr));
     return eepro100_read4(s, addr);
 }
@@ -1470,8 +1441,6 @@ static int nic_can_receive(void *opaque)
     //~ return !eepro100_buffer_full(s);
 }
 
-#define MIN_BUF_SIZE 60
-
 static void nic_receive(void *opaque, const uint8_t * buf, int size)
 {
     /* TODO:
@@ -1740,17 +1709,33 @@ static void nic_save(QEMUFile * f, void *opaque)
     qemu_put_buffer(f, s->configuration, sizeof(s->configuration));
 }
 
-static void nic_init(PCIBus * bus, NICInfo * nd,
-                     const char *name, uint32_t device)
+static void nic_cleanup(VLANClientState *vc)
+{
+    EEPRO100State *s = vc->opaque;
+
+    unregister_savevm(vc->model, s);
+
+    eeprom93xx_free(s->eeprom);
+}
+
+static int pci_nic_uninit(PCIDevice *dev)
 {
-    PCIEEPRO100State *d;
+    PCIEEPRO100State *d = (PCIEEPRO100State *) dev;
+    EEPRO100State *s = &d->eepro100;
+
+    cpu_unregister_io_memory(s->mmio_index);
+
+    return 0;
+}
+
+static void nic_init(PCIDevice *pci_dev, uint32_t device)
+{
+    PCIEEPRO100State *d = (PCIEEPRO100State *)pci_dev;
     EEPRO100State *s;
 
     logout("\n");
 
-    d = (PCIEEPRO100State *) pci_register_device(bus, name,
-                                                 sizeof(PCIEEPRO100State), -1,
-                                                 NULL, NULL);
+    d->dev.unregister = pci_nic_uninit;
 
     s = &d->eepro100;
     s->device = device;
@@ -1774,40 +1759,46 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
     pci_register_io_region(&d->dev, 2, PCI_FLASH_SIZE, PCI_ADDRESS_SPACE_MEM,
                            pci_mmio_map);
 
-    memcpy(s->macaddr, nd->macaddr, 6);
+    qdev_get_macaddr(&d->dev.qdev, s->macaddr);
     logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6));
     assert(s->region[1] == 0);
 
     nic_reset(s);
 
-    s->vc = qemu_new_vlan_client(nd->vlan, nic_receive, nic_can_receive, s);
+    s->vc = qdev_get_vlan_client(&d->dev.qdev,
+                                 nic_receive, nic_can_receive,
+                                 nic_cleanup, s);
 
-    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
-             "eepro100 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-             s->macaddr[0],
-             s->macaddr[1],
-             s->macaddr[2], s->macaddr[3], s->macaddr[4], s->macaddr[5]);
+    qemu_format_nic_info_str(s->vc, s->macaddr);
 
-    qemu_register_reset(nic_reset, s);
+    qemu_register_reset(nic_reset, 0, s);
 
-    /* XXX: instance number ? */
-    register_savevm(name, 0, 3, nic_save, nic_load, s);
+    register_savevm(s->vc->model, -1, 3, nic_save, nic_load, s);
+}
+
+static void pci_i82551_init(PCIDevice *dev)
+{
+    nic_init(dev, i82551);
 }
 
-void pci_i82551_init(PCIBus * bus, NICInfo * nd, int devfn)
+static void pci_i82557b_init(PCIDevice *dev)
 {
-    nic_init(bus, nd, "i82551", i82551);
-    //~ uint8_t *pci_conf = d->dev.config;
+    nic_init(dev, i82557B);
 }
 
-void pci_i82557b_init(PCIBus * bus, NICInfo * nd, int devfn)
+static void pci_i82559er_init(PCIDevice *dev)
 {
-    nic_init(bus, nd, "i82557b", i82557B);
+    nic_init(dev, i82559ER);
 }
 
-void pci_i82559er_init(PCIBus * bus, NICInfo * nd, int devfn)
+static void eepro100_register_devices(void)
 {
-    nic_init(bus, nd, "i82559er", i82559ER);
+    pci_qdev_register("i82551", sizeof(PCIEEPRO100State),
+                      pci_i82551_init);
+    pci_qdev_register("i82557b", sizeof(PCIEEPRO100State),
+                      pci_i82557b_init);
+    pci_qdev_register("i82559er", sizeof(PCIEEPRO100State),
+                      pci_i82559er_init);
 }
 
-/* eof */
+device_init(eepro100_register_devices)