Statistics
| Branch: | Revision:

root / hw / vmport.c @ 6e4ec3f9

History | View | Annotate | Download (4.4 kB)

1 0975c304 ths
/*
2 0975c304 ths
 * QEMU VMPort emulation
3 0975c304 ths
 *
4 bcc4e41f Stefan Weil
 * Copyright (C) 2007 Hervé Poussineau
5 0975c304 ths
 *
6 0975c304 ths
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 0975c304 ths
 * of this software and associated documentation files (the "Software"), to deal
8 0975c304 ths
 * in the Software without restriction, including without limitation the rights
9 0975c304 ths
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 0975c304 ths
 * copies of the Software, and to permit persons to whom the Software is
11 0975c304 ths
 * furnished to do so, subject to the following conditions:
12 0975c304 ths
 *
13 0975c304 ths
 * The above copyright notice and this permission notice shall be included in
14 0975c304 ths
 * all copies or substantial portions of the Software.
15 0975c304 ths
 *
16 0975c304 ths
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 0975c304 ths
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 0975c304 ths
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 0975c304 ths
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 0975c304 ths
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 0975c304 ths
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 0975c304 ths
 * THE SOFTWARE.
23 0975c304 ths
 */
24 87ecb68b pbrook
#include "hw.h"
25 87ecb68b pbrook
#include "isa.h"
26 87ecb68b pbrook
#include "pc.h"
27 03c63b94 Jan Kiszka
#include "kvm.h"
28 6872ef61 Blue Swirl
#include "qdev.h"
29 0975c304 ths
30 61ada15d aliguori
//#define VMPORT_DEBUG
31 61ada15d aliguori
32 0975c304 ths
#define VMPORT_CMD_GETVERSION 0x0a
33 0975c304 ths
#define VMPORT_CMD_GETRAMSIZE 0x14
34 0975c304 ths
35 0975c304 ths
#define VMPORT_ENTRIES 0x2c
36 0975c304 ths
#define VMPORT_MAGIC   0x564D5868
37 0975c304 ths
38 0975c304 ths
typedef struct _VMPortState
39 0975c304 ths
{
40 6872ef61 Blue Swirl
    ISADevice dev;
41 f75317b4 Richard Henderson
    MemoryRegion io;
42 0975c304 ths
    IOPortReadFunc *func[VMPORT_ENTRIES];
43 0975c304 ths
    void *opaque[VMPORT_ENTRIES];
44 0975c304 ths
} VMPortState;
45 0975c304 ths
46 e14da0af Marcelo Tosatti
static VMPortState *port_state;
47 0975c304 ths
48 0975c304 ths
void vmport_register(unsigned char command, IOPortReadFunc *func, void *opaque)
49 0975c304 ths
{
50 0975c304 ths
    if (command >= VMPORT_ENTRIES)
51 0975c304 ths
        return;
52 0975c304 ths
53 e14da0af Marcelo Tosatti
    port_state->func[command] = func;
54 e14da0af Marcelo Tosatti
    port_state->opaque[command] = opaque;
55 0975c304 ths
}
56 0975c304 ths
57 0975c304 ths
static uint32_t vmport_ioport_read(void *opaque, uint32_t addr)
58 0975c304 ths
{
59 0975c304 ths
    VMPortState *s = opaque;
60 26fb5e48 aurel32
    CPUState *env = cpu_single_env;
61 0975c304 ths
    unsigned char command;
62 6dab28d5 ths
    uint32_t eax;
63 0975c304 ths
64 03c63b94 Jan Kiszka
    cpu_synchronize_state(env);
65 03c63b94 Jan Kiszka
66 26fb5e48 aurel32
    eax = env->regs[R_EAX];
67 0975c304 ths
    if (eax != VMPORT_MAGIC)
68 0975c304 ths
        return eax;
69 0975c304 ths
70 26fb5e48 aurel32
    command = env->regs[R_ECX];
71 0975c304 ths
    if (command >= VMPORT_ENTRIES)
72 0975c304 ths
        return eax;
73 0975c304 ths
    if (!s->func[command])
74 0975c304 ths
    {
75 61ada15d aliguori
#ifdef VMPORT_DEBUG
76 61ada15d aliguori
        fprintf(stderr, "vmport: unknown command %x\n", command);
77 61ada15d aliguori
#endif
78 0975c304 ths
        return eax;
79 0975c304 ths
    }
80 0975c304 ths
81 0975c304 ths
    return s->func[command](s->opaque[command], addr);
82 0975c304 ths
}
83 0975c304 ths
84 e9396bde aliguori
static void vmport_ioport_write(void *opaque, uint32_t addr, uint32_t val)
85 e9396bde aliguori
{
86 e9396bde aliguori
    CPUState *env = cpu_single_env;
87 e9396bde aliguori
88 e9396bde aliguori
    env->regs[R_EAX] = vmport_ioport_read(opaque, addr);
89 e9396bde aliguori
}
90 e9396bde aliguori
91 0975c304 ths
static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
92 0975c304 ths
{
93 26fb5e48 aurel32
    CPUState *env = cpu_single_env;
94 0975c304 ths
    env->regs[R_EBX] = VMPORT_MAGIC;
95 0975c304 ths
    return 6;
96 0975c304 ths
}
97 0975c304 ths
98 0975c304 ths
static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr)
99 0975c304 ths
{
100 26fb5e48 aurel32
    CPUState *env = cpu_single_env;
101 0975c304 ths
    env->regs[R_EBX] = 0x1177;
102 0975c304 ths
    return ram_size;
103 0975c304 ths
}
104 0975c304 ths
105 86d86414 Blue Swirl
/* vmmouse helpers */
106 86d86414 Blue Swirl
void vmmouse_get_data(uint32_t *data)
107 86d86414 Blue Swirl
{
108 86d86414 Blue Swirl
    CPUState *env = cpu_single_env;
109 86d86414 Blue Swirl
110 86d86414 Blue Swirl
    data[0] = env->regs[R_EAX]; data[1] = env->regs[R_EBX];
111 86d86414 Blue Swirl
    data[2] = env->regs[R_ECX]; data[3] = env->regs[R_EDX];
112 86d86414 Blue Swirl
    data[4] = env->regs[R_ESI]; data[5] = env->regs[R_EDI];
113 86d86414 Blue Swirl
}
114 86d86414 Blue Swirl
115 86d86414 Blue Swirl
void vmmouse_set_data(const uint32_t *data)
116 86d86414 Blue Swirl
{
117 86d86414 Blue Swirl
    CPUState *env = cpu_single_env;
118 86d86414 Blue Swirl
119 86d86414 Blue Swirl
    env->regs[R_EAX] = data[0]; env->regs[R_EBX] = data[1];
120 86d86414 Blue Swirl
    env->regs[R_ECX] = data[2]; env->regs[R_EDX] = data[3];
121 86d86414 Blue Swirl
    env->regs[R_ESI] = data[4]; env->regs[R_EDI] = data[5];
122 86d86414 Blue Swirl
}
123 86d86414 Blue Swirl
124 f75317b4 Richard Henderson
static const MemoryRegionPortio vmport_portio[] = {
125 f75317b4 Richard Henderson
    {0, 1, 4, .read = vmport_ioport_read, .write = vmport_ioport_write },
126 f75317b4 Richard Henderson
    PORTIO_END_OF_LIST(),
127 f75317b4 Richard Henderson
};
128 f75317b4 Richard Henderson
129 f75317b4 Richard Henderson
static const MemoryRegionOps vmport_ops = {
130 f75317b4 Richard Henderson
    .old_portio = vmport_portio
131 f75317b4 Richard Henderson
};
132 f75317b4 Richard Henderson
133 6872ef61 Blue Swirl
static int vmport_initfn(ISADevice *dev)
134 0975c304 ths
{
135 6872ef61 Blue Swirl
    VMPortState *s = DO_UPCAST(VMPortState, dev, dev);
136 0975c304 ths
137 f75317b4 Richard Henderson
    memory_region_init_io(&s->io, &vmport_ops, s, "vmport", 1);
138 f75317b4 Richard Henderson
    isa_register_ioport(dev, &s->io, 0x5658);
139 f75317b4 Richard Henderson
140 e14da0af Marcelo Tosatti
    port_state = s;
141 0975c304 ths
    /* Register some generic port commands */
142 26fb5e48 aurel32
    vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
143 26fb5e48 aurel32
    vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
144 6872ef61 Blue Swirl
    return 0;
145 0975c304 ths
}
146 6872ef61 Blue Swirl
147 8f04ee08 Anthony Liguori
static void vmport_class_initfn(ObjectClass *klass, void *data)
148 8f04ee08 Anthony Liguori
{
149 8f04ee08 Anthony Liguori
    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
150 8f04ee08 Anthony Liguori
    ic->init = vmport_initfn;
151 8f04ee08 Anthony Liguori
}
152 8f04ee08 Anthony Liguori
153 8f04ee08 Anthony Liguori
static DeviceInfo vmport_info = {
154 8f04ee08 Anthony Liguori
    .name     = "vmport",
155 8f04ee08 Anthony Liguori
    .size     = sizeof(VMPortState),
156 8f04ee08 Anthony Liguori
    .no_user  = 1,
157 8f04ee08 Anthony Liguori
    .class_init          = vmport_class_initfn,
158 6872ef61 Blue Swirl
};
159 6872ef61 Blue Swirl
160 6872ef61 Blue Swirl
static void vmport_dev_register(void)
161 6872ef61 Blue Swirl
{
162 6872ef61 Blue Swirl
    isa_qdev_register(&vmport_info);
163 6872ef61 Blue Swirl
}
164 6872ef61 Blue Swirl
device_init(vmport_dev_register)