~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to hw/usb-uhci.c

Tags: upstream-0.9.0+20070816
ImportĀ upstreamĀ versionĀ 0.9.0+20070816

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
//#define DEBUG
27
27
//#define DEBUG_PACKET
28
28
 
 
29
#define UHCI_CMD_FGR      (1 << 4)
 
30
#define UHCI_CMD_EGSM     (1 << 3)
29
31
#define UHCI_CMD_GRESET   (1 << 2)
30
32
#define UHCI_CMD_HCRESET  (1 << 1)
31
33
#define UHCI_CMD_RS       (1 << 0)
117
119
    } else {
118
120
        level = 0;
119
121
    }
120
 
    pci_set_irq(&s->dev, 3, level);
 
122
    qemu_set_irq(s->dev.irq[3], level);
121
123
}
122
124
 
123
125
static void uhci_reset(UHCIState *s)
327
329
    return val;
328
330
}
329
331
 
 
332
/* signal resume if controller suspended */
 
333
static void uhci_resume (void *opaque)
 
334
{
 
335
    UHCIState *s = (UHCIState *)opaque;
 
336
 
 
337
    if (!s)
 
338
        return;
 
339
 
 
340
    if (s->cmd & UHCI_CMD_EGSM) {
 
341
        s->cmd |= UHCI_CMD_FGR;
 
342
        s->status |= UHCI_STS_RD;
 
343
        uhci_update_irq(s);
 
344
    }
 
345
}
 
346
 
330
347
static void uhci_attach(USBPort *port1, USBDevice *dev)
331
348
{
332
349
    UHCIState *s = port1->opaque;
344
361
            port->ctrl |= UHCI_PORT_LSDA;
345
362
        else
346
363
            port->ctrl &= ~UHCI_PORT_LSDA;
 
364
 
 
365
        uhci_resume(s);
 
366
 
347
367
        port->port.dev = dev;
348
368
        /* send the attach message */
349
369
        usb_send_msg(dev, USB_MSG_ATTACH);
358
378
            port->ctrl &= ~UHCI_PORT_EN;
359
379
            port->ctrl |= UHCI_PORT_ENC;
360
380
        }
 
381
 
 
382
        uhci_resume(s);
 
383
 
361
384
        dev = port->port.dev;
362
385
        if (dev) {
363
386
            /* send the detach message */
760
783
    register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
761
784
}
762
785
 
763
 
void usb_uhci_init(PCIBus *bus, int devfn)
 
786
void usb_uhci_piix3_init(PCIBus *bus, int devfn)
764
787
{
765
788
    UHCIState *s;
766
789
    uint8_t *pci_conf;
794
817
    pci_register_io_region(&s->dev, 4, 0x20, 
795
818
                           PCI_ADDRESS_SPACE_IO, uhci_map);
796
819
}
 
820
 
 
821
void usb_uhci_piix4_init(PCIBus *bus, int devfn)
 
822
{
 
823
    UHCIState *s;
 
824
    uint8_t *pci_conf;
 
825
    int i;
 
826
 
 
827
    s = (UHCIState *)pci_register_device(bus,
 
828
                                        "USB-UHCI", sizeof(UHCIState),
 
829
                                        devfn, NULL, NULL);
 
830
    pci_conf = s->dev.config;
 
831
    pci_conf[0x00] = 0x86;
 
832
    pci_conf[0x01] = 0x80;
 
833
    pci_conf[0x02] = 0x12;
 
834
    pci_conf[0x03] = 0x71;
 
835
    pci_conf[0x08] = 0x01; // revision number
 
836
    pci_conf[0x09] = 0x00;
 
837
    pci_conf[0x0a] = 0x03;
 
838
    pci_conf[0x0b] = 0x0c;
 
839
    pci_conf[0x0e] = 0x00; // header_type
 
840
    pci_conf[0x3d] = 4; // interrupt pin 3
 
841
    pci_conf[0x60] = 0x10; // release number
 
842
 
 
843
    for(i = 0; i < NB_PORTS; i++) {
 
844
        qemu_register_usb_port(&s->ports[i].port, s, i, uhci_attach);
 
845
    }
 
846
    s->frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s);
 
847
 
 
848
    uhci_reset(s);
 
849
 
 
850
    /* Use region 4 for consistency with real hardware.  BSD guests seem
 
851
       to rely on this.  */
 
852
    pci_register_io_region(&s->dev, 4, 0x20,
 
853
                           PCI_ADDRESS_SPACE_IO, uhci_map);
 
854
}
 
855