blob: 01f151682802e3e8349c8a38f84c23cdce67a4cf [file] [log] [blame]
Eddie Dong85f455f2007-07-06 12:20:49 +03001/*
2 * 8259 interrupt controller emulation
3 *
4 * Copyright (c) 2003-2004 Fabrice Bellard
5 * Copyright (c) 2007 Intel Corporation
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 * Authors:
25 * Yaozu (Eddie) Dong <Eddie.dong@intel.com>
26 * Port from Qemu.
27 */
28#include <linux/mm.h>
Avi Kivity3f353852008-12-21 22:48:32 +020029#include <linux/bitops.h>
Eddie Dong85f455f2007-07-06 12:20:49 +030030#include "irq.h"
Avi Kivityedf88412007-12-16 11:02:48 +020031
32#include <linux/kvm_host.h>
Gleb Natapov1000ff82009-07-07 16:00:57 +030033#include "trace.h"
Eddie Dong85f455f2007-07-06 12:20:49 +030034
Avi Kivity7edd0ce2008-07-07 14:45:39 +030035static void pic_clear_isr(struct kvm_kpic_state *s, int irq)
36{
37 s->isr &= ~(1 << irq);
Marcelo Tosattie4825802008-09-24 20:28:34 -030038 s->isr_ack |= (1 << irq);
Gleb Natapov938396a2009-08-04 15:30:28 +030039 if (s != &s->pics_state->pics[0])
40 irq += 8;
41 kvm_notify_acked_irq(s->pics_state->kvm, SELECT_PIC(irq), irq);
Marcelo Tosattie4825802008-09-24 20:28:34 -030042}
43
44void kvm_pic_clear_isr_ack(struct kvm *kvm)
45{
46 struct kvm_pic *s = pic_irqchip(kvm);
Gleb Natapov88ba63c2009-08-04 15:30:29 +030047 spin_lock(&s->lock);
Marcelo Tosattie4825802008-09-24 20:28:34 -030048 s->pics[0].isr_ack = 0xff;
49 s->pics[1].isr_ack = 0xff;
Gleb Natapov88ba63c2009-08-04 15:30:29 +030050 spin_unlock(&s->lock);
Avi Kivity7edd0ce2008-07-07 14:45:39 +030051}
52
Eddie Dong85f455f2007-07-06 12:20:49 +030053/*
54 * set irq level. If an edge is detected, then the IRR is set to 1
55 */
Gleb Natapov49256632009-02-04 17:28:14 +020056static inline int pic_set_irq1(struct kvm_kpic_state *s, int irq, int level)
Eddie Dong85f455f2007-07-06 12:20:49 +030057{
Gleb Natapov49256632009-02-04 17:28:14 +020058 int mask, ret = 1;
Eddie Dong85f455f2007-07-06 12:20:49 +030059 mask = 1 << irq;
60 if (s->elcr & mask) /* level triggered */
61 if (level) {
Gleb Natapov49256632009-02-04 17:28:14 +020062 ret = !(s->irr & mask);
Eddie Dong85f455f2007-07-06 12:20:49 +030063 s->irr |= mask;
64 s->last_irr |= mask;
65 } else {
66 s->irr &= ~mask;
67 s->last_irr &= ~mask;
68 }
69 else /* edge triggered */
70 if (level) {
Gleb Natapov49256632009-02-04 17:28:14 +020071 if ((s->last_irr & mask) == 0) {
72 ret = !(s->irr & mask);
Eddie Dong85f455f2007-07-06 12:20:49 +030073 s->irr |= mask;
Gleb Natapov49256632009-02-04 17:28:14 +020074 }
Eddie Dong85f455f2007-07-06 12:20:49 +030075 s->last_irr |= mask;
76 } else
77 s->last_irr &= ~mask;
Gleb Natapov49256632009-02-04 17:28:14 +020078
79 return (s->imr & mask) ? -1 : ret;
Eddie Dong85f455f2007-07-06 12:20:49 +030080}
81
82/*
83 * return the highest priority found in mask (highest = smallest
84 * number). Return 8 if no irq
85 */
86static inline int get_priority(struct kvm_kpic_state *s, int mask)
87{
88 int priority;
89 if (mask == 0)
90 return 8;
91 priority = 0;
92 while ((mask & (1 << ((priority + s->priority_add) & 7))) == 0)
93 priority++;
94 return priority;
95}
96
97/*
98 * return the pic wanted interrupt. return -1 if none
99 */
100static int pic_get_irq(struct kvm_kpic_state *s)
101{
102 int mask, cur_priority, priority;
103
104 mask = s->irr & ~s->imr;
105 priority = get_priority(s, mask);
106 if (priority == 8)
107 return -1;
108 /*
109 * compute current priority. If special fully nested mode on the
110 * master, the IRQ coming from the slave is not taken into account
111 * for the priority computation.
112 */
113 mask = s->isr;
114 if (s->special_fully_nested_mode && s == &s->pics_state->pics[0])
115 mask &= ~(1 << 2);
116 cur_priority = get_priority(s, mask);
117 if (priority < cur_priority)
118 /*
119 * higher priority found: an irq should be generated
120 */
121 return (priority + s->priority_add) & 7;
122 else
123 return -1;
124}
125
126/*
127 * raise irq to CPU if necessary. must be called every time the active
128 * irq may change
129 */
130static void pic_update_irq(struct kvm_pic *s)
131{
132 int irq2, irq;
133
134 irq2 = pic_get_irq(&s->pics[1]);
135 if (irq2 >= 0) {
136 /*
137 * if irq request by slave pic, signal master PIC
138 */
139 pic_set_irq1(&s->pics[0], 2, 1);
140 pic_set_irq1(&s->pics[0], 2, 0);
141 }
142 irq = pic_get_irq(&s->pics[0]);
143 if (irq >= 0)
144 s->irq_request(s->irq_request_opaque, 1);
145 else
146 s->irq_request(s->irq_request_opaque, 0);
147}
148
He, Qing6ceb9d72007-07-26 11:05:18 +0300149void kvm_pic_update_irq(struct kvm_pic *s)
150{
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300151 spin_lock(&s->lock);
He, Qing6ceb9d72007-07-26 11:05:18 +0300152 pic_update_irq(s);
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300153 spin_unlock(&s->lock);
He, Qing6ceb9d72007-07-26 11:05:18 +0300154}
155
Gleb Natapov49256632009-02-04 17:28:14 +0200156int kvm_pic_set_irq(void *opaque, int irq, int level)
Eddie Dong85f455f2007-07-06 12:20:49 +0300157{
158 struct kvm_pic *s = opaque;
Gleb Natapov49256632009-02-04 17:28:14 +0200159 int ret = -1;
Eddie Dong85f455f2007-07-06 12:20:49 +0300160
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300161 spin_lock(&s->lock);
Ben-Ami Yassourc65bbfa2008-07-06 17:15:07 +0300162 if (irq >= 0 && irq < PIC_NUM_PINS) {
Gleb Natapov49256632009-02-04 17:28:14 +0200163 ret = pic_set_irq1(&s->pics[irq >> 3], irq & 7, level);
Ben-Ami Yassourc65bbfa2008-07-06 17:15:07 +0300164 pic_update_irq(s);
Gleb Natapov1000ff82009-07-07 16:00:57 +0300165 trace_kvm_pic_set_irq(irq >> 3, irq & 7, s->pics[irq >> 3].elcr,
166 s->pics[irq >> 3].imr, ret == 0);
Ben-Ami Yassourc65bbfa2008-07-06 17:15:07 +0300167 }
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300168 spin_unlock(&s->lock);
Gleb Natapov49256632009-02-04 17:28:14 +0200169
170 return ret;
Eddie Dong85f455f2007-07-06 12:20:49 +0300171}
172
173/*
174 * acknowledge interrupt 'irq'
175 */
176static inline void pic_intack(struct kvm_kpic_state *s, int irq)
177{
Avi Kivity7edd0ce2008-07-07 14:45:39 +0300178 s->isr |= 1 << irq;
Eddie Dong85f455f2007-07-06 12:20:49 +0300179 if (s->auto_eoi) {
180 if (s->rotate_on_auto_eoi)
181 s->priority_add = (irq + 1) & 7;
Avi Kivity7edd0ce2008-07-07 14:45:39 +0300182 pic_clear_isr(s, irq);
183 }
Eddie Dong85f455f2007-07-06 12:20:49 +0300184 /*
185 * We don't clear a level sensitive interrupt here
186 */
187 if (!(s->elcr & (1 << irq)))
188 s->irr &= ~(1 << irq);
189}
190
Marcelo Tosattif5244722008-07-26 17:01:00 -0300191int kvm_pic_read_irq(struct kvm *kvm)
Eddie Dong85f455f2007-07-06 12:20:49 +0300192{
193 int irq, irq2, intno;
Marcelo Tosattif5244722008-07-26 17:01:00 -0300194 struct kvm_pic *s = pic_irqchip(kvm);
Eddie Dong85f455f2007-07-06 12:20:49 +0300195
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300196 spin_lock(&s->lock);
Eddie Dong85f455f2007-07-06 12:20:49 +0300197 irq = pic_get_irq(&s->pics[0]);
198 if (irq >= 0) {
199 pic_intack(&s->pics[0], irq);
200 if (irq == 2) {
201 irq2 = pic_get_irq(&s->pics[1]);
202 if (irq2 >= 0)
203 pic_intack(&s->pics[1], irq2);
204 else
205 /*
206 * spurious IRQ on slave controller
207 */
208 irq2 = 7;
209 intno = s->pics[1].irq_base + irq2;
210 irq = irq2 + 8;
211 } else
212 intno = s->pics[0].irq_base + irq;
213 } else {
214 /*
215 * spurious IRQ on host controller
216 */
217 irq = 7;
218 intno = s->pics[0].irq_base + irq;
219 }
220 pic_update_irq(s);
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300221 spin_unlock(&s->lock);
Eddie Dong85f455f2007-07-06 12:20:49 +0300222
223 return intno;
224}
225
Eddie Dong2fcceae2007-10-10 12:14:25 +0200226void kvm_pic_reset(struct kvm_kpic_state *s)
Eddie Dong85f455f2007-07-06 12:20:49 +0300227{
Avi Kivity3f353852008-12-21 22:48:32 +0200228 int irq, irqbase, n;
Marcelo Tosattif5244722008-07-26 17:01:00 -0300229 struct kvm *kvm = s->pics_state->irq_request_opaque;
Gleb Natapovc5af89b2009-06-09 15:56:26 +0300230 struct kvm_vcpu *vcpu0 = kvm->bsp_vcpu;
Marcelo Tosattif5244722008-07-26 17:01:00 -0300231
Marcelo Tosatti85428ac2008-08-14 20:53:25 -0300232 if (s == &s->pics_state->pics[0])
233 irqbase = 0;
234 else
235 irqbase = 8;
236
237 for (irq = 0; irq < PIC_NUM_PINS/2; irq++) {
238 if (vcpu0 && kvm_apic_accept_pic_intr(vcpu0))
Avi Kivity3f353852008-12-21 22:48:32 +0200239 if (s->irr & (1 << irq) || s->isr & (1 << irq)) {
240 n = irq + irqbase;
Gleb Natapov938396a2009-08-04 15:30:28 +0300241 kvm_notify_acked_irq(kvm, SELECT_PIC(n), n);
Avi Kivity3f353852008-12-21 22:48:32 +0200242 }
Marcelo Tosattif5244722008-07-26 17:01:00 -0300243 }
Eddie Dong85f455f2007-07-06 12:20:49 +0300244 s->last_irr = 0;
245 s->irr = 0;
246 s->imr = 0;
247 s->isr = 0;
Marcelo Tosattie4825802008-09-24 20:28:34 -0300248 s->isr_ack = 0xff;
Eddie Dong85f455f2007-07-06 12:20:49 +0300249 s->priority_add = 0;
250 s->irq_base = 0;
251 s->read_reg_select = 0;
252 s->poll = 0;
253 s->special_mask = 0;
254 s->init_state = 0;
255 s->auto_eoi = 0;
256 s->rotate_on_auto_eoi = 0;
257 s->special_fully_nested_mode = 0;
258 s->init4 = 0;
259}
260
261static void pic_ioport_write(void *opaque, u32 addr, u32 val)
262{
263 struct kvm_kpic_state *s = opaque;
264 int priority, cmd, irq;
265
266 addr &= 1;
267 if (addr == 0) {
268 if (val & 0x10) {
Eddie Dong2fcceae2007-10-10 12:14:25 +0200269 kvm_pic_reset(s); /* init */
Eddie Dong85f455f2007-07-06 12:20:49 +0300270 /*
271 * deassert a pending interrupt
272 */
273 s->pics_state->irq_request(s->pics_state->
274 irq_request_opaque, 0);
275 s->init_state = 1;
276 s->init4 = val & 1;
277 if (val & 0x02)
278 printk(KERN_ERR "single mode not supported");
279 if (val & 0x08)
280 printk(KERN_ERR
281 "level sensitive irq not supported");
282 } else if (val & 0x08) {
283 if (val & 0x04)
284 s->poll = 1;
285 if (val & 0x02)
286 s->read_reg_select = val & 1;
287 if (val & 0x40)
288 s->special_mask = (val >> 5) & 1;
289 } else {
290 cmd = val >> 5;
291 switch (cmd) {
292 case 0:
293 case 4:
294 s->rotate_on_auto_eoi = cmd >> 2;
295 break;
296 case 1: /* end of interrupt */
297 case 5:
298 priority = get_priority(s, s->isr);
299 if (priority != 8) {
300 irq = (priority + s->priority_add) & 7;
Avi Kivity7edd0ce2008-07-07 14:45:39 +0300301 pic_clear_isr(s, irq);
Eddie Dong85f455f2007-07-06 12:20:49 +0300302 if (cmd == 5)
303 s->priority_add = (irq + 1) & 7;
304 pic_update_irq(s->pics_state);
305 }
306 break;
307 case 3:
308 irq = val & 7;
Avi Kivity7edd0ce2008-07-07 14:45:39 +0300309 pic_clear_isr(s, irq);
Eddie Dong85f455f2007-07-06 12:20:49 +0300310 pic_update_irq(s->pics_state);
311 break;
312 case 6:
313 s->priority_add = (val + 1) & 7;
314 pic_update_irq(s->pics_state);
315 break;
316 case 7:
317 irq = val & 7;
Eddie Dong85f455f2007-07-06 12:20:49 +0300318 s->priority_add = (irq + 1) & 7;
Avi Kivity7edd0ce2008-07-07 14:45:39 +0300319 pic_clear_isr(s, irq);
Eddie Dong85f455f2007-07-06 12:20:49 +0300320 pic_update_irq(s->pics_state);
321 break;
322 default:
323 break; /* no operation */
324 }
325 }
326 } else
327 switch (s->init_state) {
328 case 0: /* normal mode */
329 s->imr = val;
330 pic_update_irq(s->pics_state);
331 break;
332 case 1:
333 s->irq_base = val & 0xf8;
334 s->init_state = 2;
335 break;
336 case 2:
337 if (s->init4)
338 s->init_state = 3;
339 else
340 s->init_state = 0;
341 break;
342 case 3:
343 s->special_fully_nested_mode = (val >> 4) & 1;
344 s->auto_eoi = (val >> 1) & 1;
345 s->init_state = 0;
346 break;
347 }
348}
349
350static u32 pic_poll_read(struct kvm_kpic_state *s, u32 addr1)
351{
352 int ret;
353
354 ret = pic_get_irq(s);
355 if (ret >= 0) {
356 if (addr1 >> 7) {
357 s->pics_state->pics[0].isr &= ~(1 << 2);
358 s->pics_state->pics[0].irr &= ~(1 << 2);
359 }
360 s->irr &= ~(1 << ret);
Avi Kivity7edd0ce2008-07-07 14:45:39 +0300361 pic_clear_isr(s, ret);
Eddie Dong85f455f2007-07-06 12:20:49 +0300362 if (addr1 >> 7 || ret != 2)
363 pic_update_irq(s->pics_state);
364 } else {
365 ret = 0x07;
366 pic_update_irq(s->pics_state);
367 }
368
369 return ret;
370}
371
372static u32 pic_ioport_read(void *opaque, u32 addr1)
373{
374 struct kvm_kpic_state *s = opaque;
375 unsigned int addr;
376 int ret;
377
378 addr = addr1;
379 addr &= 1;
380 if (s->poll) {
381 ret = pic_poll_read(s, addr1);
382 s->poll = 0;
383 } else
384 if (addr == 0)
385 if (s->read_reg_select)
386 ret = s->isr;
387 else
388 ret = s->irr;
389 else
390 ret = s->imr;
391 return ret;
392}
393
394static void elcr_ioport_write(void *opaque, u32 addr, u32 val)
395{
396 struct kvm_kpic_state *s = opaque;
397 s->elcr = val & s->elcr_mask;
398}
399
400static u32 elcr_ioport_read(void *opaque, u32 addr1)
401{
402 struct kvm_kpic_state *s = opaque;
403 return s->elcr;
404}
405
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300406static int picdev_in_range(gpa_t addr)
Eddie Dong85f455f2007-07-06 12:20:49 +0300407{
408 switch (addr) {
409 case 0x20:
410 case 0x21:
411 case 0xa0:
412 case 0xa1:
413 case 0x4d0:
414 case 0x4d1:
415 return 1;
416 default:
417 return 0;
418 }
419}
420
Gregory Haskinsd76685c2009-06-01 12:54:50 -0400421static inline struct kvm_pic *to_pic(struct kvm_io_device *dev)
422{
423 return container_of(dev, struct kvm_pic, dev);
424}
425
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300426static int picdev_write(struct kvm_io_device *this,
Eddie Dong85f455f2007-07-06 12:20:49 +0300427 gpa_t addr, int len, const void *val)
428{
Gregory Haskinsd76685c2009-06-01 12:54:50 -0400429 struct kvm_pic *s = to_pic(this);
Eddie Dong85f455f2007-07-06 12:20:49 +0300430 unsigned char data = *(unsigned char *)val;
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300431 if (!picdev_in_range(addr))
432 return -EOPNOTSUPP;
Eddie Dong85f455f2007-07-06 12:20:49 +0300433
434 if (len != 1) {
435 if (printk_ratelimit())
436 printk(KERN_ERR "PIC: non byte write\n");
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300437 return 0;
Eddie Dong85f455f2007-07-06 12:20:49 +0300438 }
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300439 spin_lock(&s->lock);
Eddie Dong85f455f2007-07-06 12:20:49 +0300440 switch (addr) {
441 case 0x20:
442 case 0x21:
443 case 0xa0:
444 case 0xa1:
445 pic_ioport_write(&s->pics[addr >> 7], addr, data);
446 break;
447 case 0x4d0:
448 case 0x4d1:
449 elcr_ioport_write(&s->pics[addr & 1], addr, data);
450 break;
451 }
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300452 spin_unlock(&s->lock);
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300453 return 0;
Eddie Dong85f455f2007-07-06 12:20:49 +0300454}
455
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300456static int picdev_read(struct kvm_io_device *this,
457 gpa_t addr, int len, void *val)
Eddie Dong85f455f2007-07-06 12:20:49 +0300458{
Gregory Haskinsd76685c2009-06-01 12:54:50 -0400459 struct kvm_pic *s = to_pic(this);
Eddie Dong85f455f2007-07-06 12:20:49 +0300460 unsigned char data = 0;
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300461 if (!picdev_in_range(addr))
462 return -EOPNOTSUPP;
Eddie Dong85f455f2007-07-06 12:20:49 +0300463
464 if (len != 1) {
465 if (printk_ratelimit())
466 printk(KERN_ERR "PIC: non byte read\n");
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300467 return 0;
Eddie Dong85f455f2007-07-06 12:20:49 +0300468 }
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300469 spin_lock(&s->lock);
Eddie Dong85f455f2007-07-06 12:20:49 +0300470 switch (addr) {
471 case 0x20:
472 case 0x21:
473 case 0xa0:
474 case 0xa1:
475 data = pic_ioport_read(&s->pics[addr >> 7], addr);
476 break;
477 case 0x4d0:
478 case 0x4d1:
479 data = elcr_ioport_read(&s->pics[addr & 1], addr);
480 break;
481 }
482 *(unsigned char *)val = data;
Gleb Natapov88ba63c2009-08-04 15:30:29 +0300483 spin_unlock(&s->lock);
Michael S. Tsirkinbda90202009-06-29 22:24:32 +0300484 return 0;
Eddie Dong85f455f2007-07-06 12:20:49 +0300485}
486
487/*
488 * callback when PIC0 irq status changed
489 */
490static void pic_irq_request(void *opaque, int level)
491{
492 struct kvm *kvm = opaque;
Gleb Natapovc5af89b2009-06-09 15:56:26 +0300493 struct kvm_vcpu *vcpu = kvm->bsp_vcpu;
Marcelo Tosattie4825802008-09-24 20:28:34 -0300494 struct kvm_pic *s = pic_irqchip(kvm);
495 int irq = pic_get_irq(&s->pics[0]);
Eddie Dong85f455f2007-07-06 12:20:49 +0300496
Marcelo Tosattie4825802008-09-24 20:28:34 -0300497 s->output = level;
498 if (vcpu && level && (s->pics[0].isr_ack & (1 << irq))) {
499 s->pics[0].isr_ack &= ~(1 << irq);
Gleb Natapov956f97c2009-08-04 15:30:27 +0300500 kvm_vcpu_kick(vcpu);
Marcelo Tosattie4825802008-09-24 20:28:34 -0300501 }
Eddie Dong85f455f2007-07-06 12:20:49 +0300502}
503
Gregory Haskinsd76685c2009-06-01 12:54:50 -0400504static const struct kvm_io_device_ops picdev_ops = {
505 .read = picdev_read,
506 .write = picdev_write,
Gregory Haskinsd76685c2009-06-01 12:54:50 -0400507};
508
Eddie Dong85f455f2007-07-06 12:20:49 +0300509struct kvm_pic *kvm_create_pic(struct kvm *kvm)
510{
511 struct kvm_pic *s;
Gregory Haskins090b7af2009-07-07 17:08:44 -0400512 int ret;
513
Eddie Dong85f455f2007-07-06 12:20:49 +0300514 s = kzalloc(sizeof(struct kvm_pic), GFP_KERNEL);
515 if (!s)
516 return NULL;
Avi Kivity3f353852008-12-21 22:48:32 +0200517 spin_lock_init(&s->lock);
518 s->kvm = kvm;
Eddie Dong85f455f2007-07-06 12:20:49 +0300519 s->pics[0].elcr_mask = 0xf8;
520 s->pics[1].elcr_mask = 0xde;
521 s->irq_request = pic_irq_request;
522 s->irq_request_opaque = kvm;
523 s->pics[0].pics_state = s;
524 s->pics[1].pics_state = s;
525
526 /*
527 * Initialize PIO device
528 */
Gregory Haskinsd76685c2009-06-01 12:54:50 -0400529 kvm_iodevice_init(&s->dev, &picdev_ops);
Gregory Haskins090b7af2009-07-07 17:08:44 -0400530 ret = kvm_io_bus_register_dev(kvm, &kvm->pio_bus, &s->dev);
531 if (ret < 0) {
532 kfree(s);
533 return NULL;
534 }
535
Eddie Dong85f455f2007-07-06 12:20:49 +0300536 return s;
537}