1 #qemu-only -> submit upstream qemu
2 Index: kvm-83/qemu/Makefile.target
3 ===================================================================
4 --- kvm-83.orig/qemu/Makefile.target
5 +++ kvm-83/qemu/Makefile.target
6 @@ -703,7 +703,7 @@ ifeq ($(TARGET_BASE_ARCH), i386)
7 OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o
8 OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
9 OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o
10 -OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o lpc.o
11 +OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o lpc.o applesmc.o
14 OBJS+= virtio.o virtio-blk.o virtio-balloon.o
15 Index: kvm-83/qemu/hw/applesmc.c
16 ===================================================================
18 +++ kvm-83/qemu/hw/applesmc.c
21 + * Apple SMC controller
23 + * Copyright (c) 2007 Alexander Graf
25 + * This library is free software; you can redistribute it and/or
26 + * modify it under the terms of the GNU Lesser General Public
27 + * License as published by the Free Software Foundation; either
28 + * version 2 of the License, or (at your option) any later version.
30 + * This library is distributed in the hope that it will be useful,
31 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 + * Lesser General Public License for more details.
35 + * You should have received a copy of the GNU Lesser General Public
36 + * License along with this library; if not, write to the Free Software
37 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 + * *****************************************************************
41 + * In all Intel-based Apple hardware there is an SMC chip to control the
42 + * backlight, fans and several other generic device parameters. It also
43 + * contains the magic keys used to dongle Mac OS X to the device.
45 + * This driver was mostly created by looking at the Linux AppleSMC driver
46 + * implementation and does not support IRQ.
53 +#include "qemu-timer.h"
55 +/* data port used by Apple SMC */
56 +#define APPLESMC_DATA_PORT 0x300
57 +/* command/status port used by Apple SMC */
58 +#define APPLESMC_CMD_PORT 0x304
59 +#define APPLESMC_NR_PORTS 32 /* 0x300-0x31f */
60 +#define APPLESMC_MAX_DATA_LENGTH 32
62 +#define APPLESMC_READ_CMD 0x10
63 +#define APPLESMC_WRITE_CMD 0x11
64 +#define APPLESMC_GET_KEY_BY_INDEX_CMD 0x12
65 +#define APPLESMC_GET_KEY_TYPE_CMD 0x13
67 +static char osk[64] = "This is a dummy key. Enter the real key using the -osk parameter";
69 +struct AppleSMCData {
75 +static struct AppleSMCData data[] = {
76 + { .key = "REV ", .len=6, .data="\0x01\0x13\0x0f\0x00\0x00\0x03" },
77 + { .key = "OSK0", .len=32, .data=osk },
78 + { .key = "OSK1", .len=32, .data=osk+32 },
79 + { .key = "NATJ", .len=1, .data="\0" },
80 + { .key = "MSSP", .len=1, .data="\0" },
81 + { .key = "MSSD", .len=1, .data="\0x3" },
85 +struct AppleSMCStatus {
93 + uint8_t charactic[4];
96 +static void applesmc_io_cmd_writeb(void *opaque, uint32_t addr, uint32_t val)
98 + struct AppleSMCStatus *s = (struct AppleSMCStatus *)opaque;
99 + printf("APPLESMC: CMD Write B: %#x = %#x\n", addr, val);
101 + case APPLESMC_READ_CMD:
110 +static void applesmc_fill_data(struct AppleSMCStatus *s)
112 + struct AppleSMCData *d;
113 + for(d=data; d->len; d++) {
114 + uint32_t key_data = *((uint32_t*)d->key);
115 + uint32_t key_current = *((uint32_t*)s->key);
116 + if(key_data == key_current) {
117 + printf("APPLESMC: Key matched (%s Len=%d Data=%s)\n", d->key, d->len, d->data);
118 + memcpy(s->data, d->data, d->len);
124 +static void applesmc_io_data_writeb(void *opaque, uint32_t addr, uint32_t val)
126 + struct AppleSMCStatus *s = (struct AppleSMCStatus *)opaque;
127 + printf("APPLESMC: DATA Write B: %#x = %#x\n", addr, val);
129 + case APPLESMC_READ_CMD:
130 + if(s->read_pos < 4) {
131 + s->key[s->read_pos] = val;
133 + } else if(s->read_pos == 4) {
137 + printf("APPLESMC: Key = %c%c%c%c Len = %d\n", s->key[0], s->key[1], s->key[2], s->key[3], val);
138 + applesmc_fill_data(s);
145 +static uint32_t applesmc_io_data_readb(void *opaque, uint32_t addr1)
147 + struct AppleSMCStatus *s = (struct AppleSMCStatus *)opaque;
148 + uint8_t retval = 0;
150 + case APPLESMC_READ_CMD:
151 + if(s->data_pos < s->data_len) {
152 + retval = s->data[s->data_pos];
153 + printf("APPLESMC: READ_DATA[%d] = %#hhx\n", s->data_pos, retval);
155 + if(s->data_pos == s->data_len) {
157 + printf("APPLESMC: EOF\n");
162 + printf("APPLESMC: DATA Read b: %#x = %#x\n", addr1, retval);
166 +static uint32_t applesmc_io_cmd_readb(void *opaque, uint32_t addr1)
168 + printf("APPLESMC: CMD Read B: %#x\n", addr1);
169 + return ((struct AppleSMCStatus*)opaque)->status;
172 +void applesmc_setkey(char *key) {
173 + if(strlen(key) == 64) {
174 + memcpy(osk, key, 64);
178 +void applesmc_init() {
179 + struct ApleSMCStatus *s;
180 + s = qemu_mallocz(sizeof(struct AppleSMCStatus));
182 + if(osk[0] == 'T') {
183 + printf("WARNING: Using AppleSMC with invalid key\n");
185 + register_ioport_read(APPLESMC_DATA_PORT, 4, 1, applesmc_io_data_readb, s);
186 + register_ioport_read(APPLESMC_CMD_PORT, 4, 1, applesmc_io_cmd_readb, s);
187 + register_ioport_write(APPLESMC_DATA_PORT, 4, 1, applesmc_io_data_writeb, s);
188 + register_ioport_write(APPLESMC_CMD_PORT, 4, 1, applesmc_io_cmd_writeb, s);
191 Index: kvm-83/qemu/hw/pc.h
192 ===================================================================
193 --- kvm-83.orig/qemu/hw/pc.h
194 +++ kvm-83/qemu/hw/pc.h
195 @@ -172,6 +172,10 @@ void pci_piix4_ide_init(PCIBus *bus, Blo
197 void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd);
200 +void applesmc_init(void);
201 +void applesmc_setkey(char *key);
204 void lpc_init(PCIBus *bus, int devfn, qemu_irq *pic);
206 Index: kvm-83/qemu/vl.c
207 ===================================================================
208 --- kvm-83.orig/qemu/vl.c
210 @@ -4087,6 +4087,7 @@ static void help(int exitcode)
211 "-no-fd-bootchk disable boot signature checking for floppy disks\n"
212 "-no-acpi disable ACPI\n"
213 "-no-hpet disable HPET\n"
214 + "-osk key set AppleSMC key\n"
216 "Linux boot specific:\n"
217 "-kernel bzImage use 'bzImage' as kernel image\n"
218 @@ -4245,6 +4246,7 @@ enum {
219 QEMU_OPTION_no_fd_bootchk,
224 /* Linux boot specific: */
226 @@ -4379,6 +4381,7 @@ static const QEMUOption qemu_options[] =
227 { "no-fd-bootchk", 0, QEMU_OPTION_no_fd_bootchk },
228 { "no-acpi", 0, QEMU_OPTION_no_acpi },
229 { "no-hpet", 0, QEMU_OPTION_no_hpet },
230 + { "osk", HAS_ARG, QEMU_OPTION_osk },
233 /* Linux boot specific: */
234 @@ -5159,6 +5162,9 @@ int main(int argc, char **argv, char **e
235 case QEMU_OPTION_no_fd_bootchk:
238 + case QEMU_OPTION_osk:
239 + applesmc_setkey(optarg);
242 case QEMU_OPTION_net:
243 if (nb_net_clients >= MAX_NET_CLIENTS) {