updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / kvm-opensuse / kvm-qemu-applesmc.patch
blobc10a6575891cc42602e339486358a09e40c85aec
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
12 OBJS+= extboot.o
13 # virtio support
14 OBJS+= virtio.o virtio-blk.o virtio-balloon.o
15 Index: kvm-83/qemu/hw/applesmc.c
16 ===================================================================
17 --- /dev/null
18 +++ kvm-83/qemu/hw/applesmc.c
19 @@ -0,0 +1,171 @@
20 +/*
21 + * Apple SMC controller
22 + *
23 + * Copyright (c) 2007 Alexander Graf
24 + *
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.
29 + *
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.
34 + *
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
38 + *
39 + * *****************************************************************
40 + *
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.
44 + *
45 + * This driver was mostly created by looking at the Linux AppleSMC driver
46 + * implementation and does not support IRQ.
47 + *
48 + */
50 +#include "hw.h"
51 +#include "pci.h"
52 +#include "console.h"
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 {
70 + uint8_t len;
71 + char *key;
72 + char *data;
73 +};
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" },
82 + { .len=0 }
83 +};
85 +struct AppleSMCStatus {
86 + uint8_t cmd;
87 + uint8_t status;
88 + uint8_t key[4];
89 + uint8_t read_pos;
90 + uint8_t data_len;
91 + uint8_t data_pos;
92 + uint8_t data[255];
93 + uint8_t charactic[4];
94 +};
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);
100 + switch(val) {
101 + case APPLESMC_READ_CMD:
102 + s->status = 0x0c;
103 + break;
105 + s->cmd = val;
106 + s->read_pos = 0;
107 + s->data_pos = 0;
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);
119 + return;
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);
128 + switch(s->cmd) {
129 + case APPLESMC_READ_CMD:
130 + if(s->read_pos < 4) {
131 + s->key[s->read_pos] = val;
132 + s->status = 0x04;
133 + } else if(s->read_pos == 4) {
134 + s->data_len = val;
135 + s->status = 0x05;
136 + s->data_pos = 0;
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);
140 + s->read_pos++;
141 + break;
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;
149 + switch(s->cmd) {
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);
154 + s->data_pos++;
155 + if(s->data_pos == s->data_len) {
156 + s->status = 0x00;
157 + printf("APPLESMC: EOF\n");
158 + } else
159 + s->status = 0x05;
162 + printf("APPLESMC: DATA Read b: %#x = %#x\n", addr1, retval);
163 + return 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);
199 +/* applesmc.c */
200 +void applesmc_init(void);
201 +void applesmc_setkey(char *key);
203 /* lpc.c */
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
209 +++ kvm-83/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"
215 #endif
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,
220 QEMU_OPTION_no_acpi,
221 QEMU_OPTION_no_hpet,
222 + QEMU_OPTION_osk,
224 /* Linux boot specific: */
225 QEMU_OPTION_kernel,
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 },
231 #endif
233 /* Linux boot specific: */
234 @@ -5159,6 +5162,9 @@ int main(int argc, char **argv, char **e
235 case QEMU_OPTION_no_fd_bootchk:
236 fd_bootchk = 0;
237 break;
238 + case QEMU_OPTION_osk:
239 + applesmc_setkey(optarg);
240 + break;
241 #endif
242 case QEMU_OPTION_net:
243 if (nb_net_clients >= MAX_NET_CLIENTS) {