i8254.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*
  2. * 8253/8254 interval timer emulation
  3. *
  4. * Copyright (c) 2003-2004 Fabrice Bellard
  5. * Copyright (c) 2006 Intel Corporation
  6. * Copyright (c) 2007 Keir Fraser, XenSource Inc
  7. * Copyright (c) 2008 Intel Corporation
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. * Authors:
  28. * Sheng Yang <sheng.yang@intel.com>
  29. * Based on QEMU and Xen.
  30. */
  31. #include <linux/kvm_host.h>
  32. #include "irq.h"
  33. #include "i8254.h"
  34. #ifndef CONFIG_X86_64
  35. #define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
  36. #else
  37. #define mod_64(x, y) ((x) % (y))
  38. #endif
  39. #define RW_STATE_LSB 1
  40. #define RW_STATE_MSB 2
  41. #define RW_STATE_WORD0 3
  42. #define RW_STATE_WORD1 4
  43. /* Compute with 96 bit intermediate result: (a*b)/c */
  44. static u64 muldiv64(u64 a, u32 b, u32 c)
  45. {
  46. union {
  47. u64 ll;
  48. struct {
  49. u32 low, high;
  50. } l;
  51. } u, res;
  52. u64 rl, rh;
  53. u.ll = a;
  54. rl = (u64)u.l.low * (u64)b;
  55. rh = (u64)u.l.high * (u64)b;
  56. rh += (rl >> 32);
  57. res.l.high = div64_u64(rh, c);
  58. res.l.low = div64_u64(((mod_64(rh, c) << 32) + (rl & 0xffffffff)), c);
  59. return res.ll;
  60. }
  61. static void pit_set_gate(struct kvm *kvm, int channel, u32 val)
  62. {
  63. struct kvm_kpit_channel_state *c =
  64. &kvm->arch.vpit->pit_state.channels[channel];
  65. WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
  66. switch (c->mode) {
  67. default:
  68. case 0:
  69. case 4:
  70. /* XXX: just disable/enable counting */
  71. break;
  72. case 1:
  73. case 2:
  74. case 3:
  75. case 5:
  76. /* Restart counting on rising edge. */
  77. if (c->gate < val)
  78. c->count_load_time = ktime_get();
  79. break;
  80. }
  81. c->gate = val;
  82. }
  83. static int pit_get_gate(struct kvm *kvm, int channel)
  84. {
  85. WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
  86. return kvm->arch.vpit->pit_state.channels[channel].gate;
  87. }
  88. static int pit_get_count(struct kvm *kvm, int channel)
  89. {
  90. struct kvm_kpit_channel_state *c =
  91. &kvm->arch.vpit->pit_state.channels[channel];
  92. s64 d, t;
  93. int counter;
  94. WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
  95. t = ktime_to_ns(ktime_sub(ktime_get(), c->count_load_time));
  96. d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC);
  97. switch (c->mode) {
  98. case 0:
  99. case 1:
  100. case 4:
  101. case 5:
  102. counter = (c->count - d) & 0xffff;
  103. break;
  104. case 3:
  105. /* XXX: may be incorrect for odd counts */
  106. counter = c->count - (mod_64((2 * d), c->count));
  107. break;
  108. default:
  109. counter = c->count - mod_64(d, c->count);
  110. break;
  111. }
  112. return counter;
  113. }
  114. static int pit_get_out(struct kvm *kvm, int channel)
  115. {
  116. struct kvm_kpit_channel_state *c =
  117. &kvm->arch.vpit->pit_state.channels[channel];
  118. s64 d, t;
  119. int out;
  120. WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
  121. t = ktime_to_ns(ktime_sub(ktime_get(), c->count_load_time));
  122. d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC);
  123. switch (c->mode) {
  124. default:
  125. case 0:
  126. out = (d >= c->count);
  127. break;
  128. case 1:
  129. out = (d < c->count);
  130. break;
  131. case 2:
  132. out = ((mod_64(d, c->count) == 0) && (d != 0));
  133. break;
  134. case 3:
  135. out = (mod_64(d, c->count) < ((c->count + 1) >> 1));
  136. break;
  137. case 4:
  138. case 5:
  139. out = (d == c->count);
  140. break;
  141. }
  142. return out;
  143. }
  144. static void pit_latch_count(struct kvm *kvm, int channel)
  145. {
  146. struct kvm_kpit_channel_state *c =
  147. &kvm->arch.vpit->pit_state.channels[channel];
  148. WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
  149. if (!c->count_latched) {
  150. c->latched_count = pit_get_count(kvm, channel);
  151. c->count_latched = c->rw_mode;
  152. }
  153. }
  154. static void pit_latch_status(struct kvm *kvm, int channel)
  155. {
  156. struct kvm_kpit_channel_state *c =
  157. &kvm->arch.vpit->pit_state.channels[channel];
  158. WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
  159. if (!c->status_latched) {
  160. /* TODO: Return NULL COUNT (bit 6). */
  161. c->status = ((pit_get_out(kvm, channel) << 7) |
  162. (c->rw_mode << 4) |
  163. (c->mode << 1) |
  164. c->bcd);
  165. c->status_latched = 1;
  166. }
  167. }
  168. static int __pit_timer_fn(struct kvm_kpit_state *ps)
  169. {
  170. struct kvm_vcpu *vcpu0 = ps->pit->kvm->vcpus[0];
  171. struct kvm_kpit_timer *pt = &ps->pit_timer;
  172. if (!atomic_inc_and_test(&pt->pending))
  173. set_bit(KVM_REQ_PENDING_TIMER, &vcpu0->requests);
  174. if (vcpu0 && waitqueue_active(&vcpu0->wq))
  175. wake_up_interruptible(&vcpu0->wq);
  176. hrtimer_add_expires_ns(&pt->timer, pt->period);
  177. pt->scheduled = hrtimer_get_expires_ns(&pt->timer);
  178. if (pt->period)
  179. ps->channels[0].count_load_time = hrtimer_get_expires(&pt->timer);
  180. return (pt->period == 0 ? 0 : 1);
  181. }
  182. int pit_has_pending_timer(struct kvm_vcpu *vcpu)
  183. {
  184. struct kvm_pit *pit = vcpu->kvm->arch.vpit;
  185. if (pit && vcpu->vcpu_id == 0 && pit->pit_state.irq_ack)
  186. return atomic_read(&pit->pit_state.pit_timer.pending);
  187. return 0;
  188. }
  189. static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian)
  190. {
  191. struct kvm_kpit_state *ps = container_of(kian, struct kvm_kpit_state,
  192. irq_ack_notifier);
  193. spin_lock(&ps->inject_lock);
  194. if (atomic_dec_return(&ps->pit_timer.pending) < 0)
  195. atomic_inc(&ps->pit_timer.pending);
  196. ps->irq_ack = 1;
  197. spin_unlock(&ps->inject_lock);
  198. }
  199. static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
  200. {
  201. struct kvm_kpit_state *ps;
  202. int restart_timer = 0;
  203. ps = container_of(data, struct kvm_kpit_state, pit_timer.timer);
  204. restart_timer = __pit_timer_fn(ps);
  205. if (restart_timer)
  206. return HRTIMER_RESTART;
  207. else
  208. return HRTIMER_NORESTART;
  209. }
  210. void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
  211. {
  212. struct kvm_pit *pit = vcpu->kvm->arch.vpit;
  213. struct hrtimer *timer;
  214. if (vcpu->vcpu_id != 0 || !pit)
  215. return;
  216. timer = &pit->pit_state.pit_timer.timer;
  217. if (hrtimer_cancel(timer))
  218. hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
  219. }
  220. static void destroy_pit_timer(struct kvm_kpit_timer *pt)
  221. {
  222. pr_debug("pit: execute del timer!\n");
  223. hrtimer_cancel(&pt->timer);
  224. }
  225. static void create_pit_timer(struct kvm_kpit_state *ps, u32 val, int is_period)
  226. {
  227. struct kvm_kpit_timer *pt = &ps->pit_timer;
  228. s64 interval;
  229. interval = muldiv64(val, NSEC_PER_SEC, KVM_PIT_FREQ);
  230. pr_debug("pit: create pit timer, interval is %llu nsec\n", interval);
  231. /* TODO The new value only affected after the retriggered */
  232. hrtimer_cancel(&pt->timer);
  233. pt->period = (is_period == 0) ? 0 : interval;
  234. pt->timer.function = pit_timer_fn;
  235. atomic_set(&pt->pending, 0);
  236. ps->irq_ack = 1;
  237. hrtimer_start(&pt->timer, ktime_add_ns(ktime_get(), interval),
  238. HRTIMER_MODE_ABS);
  239. }
  240. static void pit_load_count(struct kvm *kvm, int channel, u32 val)
  241. {
  242. struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state;
  243. WARN_ON(!mutex_is_locked(&ps->lock));
  244. pr_debug("pit: load_count val is %d, channel is %d\n", val, channel);
  245. /*
  246. * Though spec said the state of 8254 is undefined after power-up,
  247. * seems some tricky OS like Windows XP depends on IRQ0 interrupt
  248. * when booting up.
  249. * So here setting initialize rate for it, and not a specific number
  250. */
  251. if (val == 0)
  252. val = 0x10000;
  253. ps->channels[channel].count_load_time = ktime_get();
  254. ps->channels[channel].count = val;
  255. if (channel != 0)
  256. return;
  257. /* Two types of timer
  258. * mode 1 is one shot, mode 2 is period, otherwise del timer */
  259. switch (ps->channels[0].mode) {
  260. case 1:
  261. /* FIXME: enhance mode 4 precision */
  262. case 4:
  263. create_pit_timer(ps, val, 0);
  264. break;
  265. case 2:
  266. case 3:
  267. create_pit_timer(ps, val, 1);
  268. break;
  269. default:
  270. destroy_pit_timer(&ps->pit_timer);
  271. }
  272. }
  273. void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val)
  274. {
  275. mutex_lock(&kvm->arch.vpit->pit_state.lock);
  276. pit_load_count(kvm, channel, val);
  277. mutex_unlock(&kvm->arch.vpit->pit_state.lock);
  278. }
  279. static void pit_ioport_write(struct kvm_io_device *this,
  280. gpa_t addr, int len, const void *data)
  281. {
  282. struct kvm_pit *pit = (struct kvm_pit *)this->private;
  283. struct kvm_kpit_state *pit_state = &pit->pit_state;
  284. struct kvm *kvm = pit->kvm;
  285. int channel, access;
  286. struct kvm_kpit_channel_state *s;
  287. u32 val = *(u32 *) data;
  288. val &= 0xff;
  289. addr &= KVM_PIT_CHANNEL_MASK;
  290. mutex_lock(&pit_state->lock);
  291. if (val != 0)
  292. pr_debug("pit: write addr is 0x%x, len is %d, val is 0x%x\n",
  293. (unsigned int)addr, len, val);
  294. if (addr == 3) {
  295. channel = val >> 6;
  296. if (channel == 3) {
  297. /* Read-Back Command. */
  298. for (channel = 0; channel < 3; channel++) {
  299. s = &pit_state->channels[channel];
  300. if (val & (2 << channel)) {
  301. if (!(val & 0x20))
  302. pit_latch_count(kvm, channel);
  303. if (!(val & 0x10))
  304. pit_latch_status(kvm, channel);
  305. }
  306. }
  307. } else {
  308. /* Select Counter <channel>. */
  309. s = &pit_state->channels[channel];
  310. access = (val >> 4) & KVM_PIT_CHANNEL_MASK;
  311. if (access == 0) {
  312. pit_latch_count(kvm, channel);
  313. } else {
  314. s->rw_mode = access;
  315. s->read_state = access;
  316. s->write_state = access;
  317. s->mode = (val >> 1) & 7;
  318. if (s->mode > 5)
  319. s->mode -= 4;
  320. s->bcd = val & 1;
  321. }
  322. }
  323. } else {
  324. /* Write Count. */
  325. s = &pit_state->channels[addr];
  326. switch (s->write_state) {
  327. default:
  328. case RW_STATE_LSB:
  329. pit_load_count(kvm, addr, val);
  330. break;
  331. case RW_STATE_MSB:
  332. pit_load_count(kvm, addr, val << 8);
  333. break;
  334. case RW_STATE_WORD0:
  335. s->write_latch = val;
  336. s->write_state = RW_STATE_WORD1;
  337. break;
  338. case RW_STATE_WORD1:
  339. pit_load_count(kvm, addr, s->write_latch | (val << 8));
  340. s->write_state = RW_STATE_WORD0;
  341. break;
  342. }
  343. }
  344. mutex_unlock(&pit_state->lock);
  345. }
  346. static void pit_ioport_read(struct kvm_io_device *this,
  347. gpa_t addr, int len, void *data)
  348. {
  349. struct kvm_pit *pit = (struct kvm_pit *)this->private;
  350. struct kvm_kpit_state *pit_state = &pit->pit_state;
  351. struct kvm *kvm = pit->kvm;
  352. int ret, count;
  353. struct kvm_kpit_channel_state *s;
  354. addr &= KVM_PIT_CHANNEL_MASK;
  355. s = &pit_state->channels[addr];
  356. mutex_lock(&pit_state->lock);
  357. if (s->status_latched) {
  358. s->status_latched = 0;
  359. ret = s->status;
  360. } else if (s->count_latched) {
  361. switch (s->count_latched) {
  362. default:
  363. case RW_STATE_LSB:
  364. ret = s->latched_count & 0xff;
  365. s->count_latched = 0;
  366. break;
  367. case RW_STATE_MSB:
  368. ret = s->latched_count >> 8;
  369. s->count_latched = 0;
  370. break;
  371. case RW_STATE_WORD0:
  372. ret = s->latched_count & 0xff;
  373. s->count_latched = RW_STATE_MSB;
  374. break;
  375. }
  376. } else {
  377. switch (s->read_state) {
  378. default:
  379. case RW_STATE_LSB:
  380. count = pit_get_count(kvm, addr);
  381. ret = count & 0xff;
  382. break;
  383. case RW_STATE_MSB:
  384. count = pit_get_count(kvm, addr);
  385. ret = (count >> 8) & 0xff;
  386. break;
  387. case RW_STATE_WORD0:
  388. count = pit_get_count(kvm, addr);
  389. ret = count & 0xff;
  390. s->read_state = RW_STATE_WORD1;
  391. break;
  392. case RW_STATE_WORD1:
  393. count = pit_get_count(kvm, addr);
  394. ret = (count >> 8) & 0xff;
  395. s->read_state = RW_STATE_WORD0;
  396. break;
  397. }
  398. }
  399. if (len > sizeof(ret))
  400. len = sizeof(ret);
  401. memcpy(data, (char *)&ret, len);
  402. mutex_unlock(&pit_state->lock);
  403. }
  404. static int pit_in_range(struct kvm_io_device *this, gpa_t addr,
  405. int len, int is_write)
  406. {
  407. return ((addr >= KVM_PIT_BASE_ADDRESS) &&
  408. (addr < KVM_PIT_BASE_ADDRESS + KVM_PIT_MEM_LENGTH));
  409. }
  410. static void speaker_ioport_write(struct kvm_io_device *this,
  411. gpa_t addr, int len, const void *data)
  412. {
  413. struct kvm_pit *pit = (struct kvm_pit *)this->private;
  414. struct kvm_kpit_state *pit_state = &pit->pit_state;
  415. struct kvm *kvm = pit->kvm;
  416. u32 val = *(u32 *) data;
  417. mutex_lock(&pit_state->lock);
  418. pit_state->speaker_data_on = (val >> 1) & 1;
  419. pit_set_gate(kvm, 2, val & 1);
  420. mutex_unlock(&pit_state->lock);
  421. }
  422. static void speaker_ioport_read(struct kvm_io_device *this,
  423. gpa_t addr, int len, void *data)
  424. {
  425. struct kvm_pit *pit = (struct kvm_pit *)this->private;
  426. struct kvm_kpit_state *pit_state = &pit->pit_state;
  427. struct kvm *kvm = pit->kvm;
  428. unsigned int refresh_clock;
  429. int ret;
  430. /* Refresh clock toggles at about 15us. We approximate as 2^14ns. */
  431. refresh_clock = ((unsigned int)ktime_to_ns(ktime_get()) >> 14) & 1;
  432. mutex_lock(&pit_state->lock);
  433. ret = ((pit_state->speaker_data_on << 1) | pit_get_gate(kvm, 2) |
  434. (pit_get_out(kvm, 2) << 5) | (refresh_clock << 4));
  435. if (len > sizeof(ret))
  436. len = sizeof(ret);
  437. memcpy(data, (char *)&ret, len);
  438. mutex_unlock(&pit_state->lock);
  439. }
  440. static int speaker_in_range(struct kvm_io_device *this, gpa_t addr,
  441. int len, int is_write)
  442. {
  443. return (addr == KVM_SPEAKER_BASE_ADDRESS);
  444. }
  445. void kvm_pit_reset(struct kvm_pit *pit)
  446. {
  447. int i;
  448. struct kvm_kpit_channel_state *c;
  449. mutex_lock(&pit->pit_state.lock);
  450. for (i = 0; i < 3; i++) {
  451. c = &pit->pit_state.channels[i];
  452. c->mode = 0xff;
  453. c->gate = (i != 2);
  454. pit_load_count(pit->kvm, i, 0);
  455. }
  456. mutex_unlock(&pit->pit_state.lock);
  457. atomic_set(&pit->pit_state.pit_timer.pending, 0);
  458. pit->pit_state.irq_ack = 1;
  459. }
  460. struct kvm_pit *kvm_create_pit(struct kvm *kvm)
  461. {
  462. struct kvm_pit *pit;
  463. struct kvm_kpit_state *pit_state;
  464. pit = kzalloc(sizeof(struct kvm_pit), GFP_KERNEL);
  465. if (!pit)
  466. return NULL;
  467. mutex_lock(&kvm->lock);
  468. pit->irq_source_id = kvm_request_irq_source_id(kvm);
  469. mutex_unlock(&kvm->lock);
  470. if (pit->irq_source_id < 0) {
  471. kfree(pit);
  472. return NULL;
  473. }
  474. mutex_init(&pit->pit_state.lock);
  475. mutex_lock(&pit->pit_state.lock);
  476. spin_lock_init(&pit->pit_state.inject_lock);
  477. /* Initialize PIO device */
  478. pit->dev.read = pit_ioport_read;
  479. pit->dev.write = pit_ioport_write;
  480. pit->dev.in_range = pit_in_range;
  481. pit->dev.private = pit;
  482. kvm_io_bus_register_dev(&kvm->pio_bus, &pit->dev);
  483. pit->speaker_dev.read = speaker_ioport_read;
  484. pit->speaker_dev.write = speaker_ioport_write;
  485. pit->speaker_dev.in_range = speaker_in_range;
  486. pit->speaker_dev.private = pit;
  487. kvm_io_bus_register_dev(&kvm->pio_bus, &pit->speaker_dev);
  488. kvm->arch.vpit = pit;
  489. pit->kvm = kvm;
  490. pit_state = &pit->pit_state;
  491. pit_state->pit = pit;
  492. hrtimer_init(&pit_state->pit_timer.timer,
  493. CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  494. pit_state->irq_ack_notifier.gsi = 0;
  495. pit_state->irq_ack_notifier.irq_acked = kvm_pit_ack_irq;
  496. kvm_register_irq_ack_notifier(kvm, &pit_state->irq_ack_notifier);
  497. mutex_unlock(&pit->pit_state.lock);
  498. kvm_pit_reset(pit);
  499. return pit;
  500. }
  501. void kvm_free_pit(struct kvm *kvm)
  502. {
  503. struct hrtimer *timer;
  504. if (kvm->arch.vpit) {
  505. mutex_lock(&kvm->arch.vpit->pit_state.lock);
  506. timer = &kvm->arch.vpit->pit_state.pit_timer.timer;
  507. hrtimer_cancel(timer);
  508. kvm_free_irq_source_id(kvm, kvm->arch.vpit->irq_source_id);
  509. mutex_unlock(&kvm->arch.vpit->pit_state.lock);
  510. kfree(kvm->arch.vpit);
  511. }
  512. }
  513. static void __inject_pit_timer_intr(struct kvm *kvm)
  514. {
  515. mutex_lock(&kvm->lock);
  516. kvm_set_irq(kvm, kvm->arch.vpit->irq_source_id, 0, 1);
  517. kvm_set_irq(kvm, kvm->arch.vpit->irq_source_id, 0, 0);
  518. mutex_unlock(&kvm->lock);
  519. }
  520. void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu)
  521. {
  522. struct kvm_pit *pit = vcpu->kvm->arch.vpit;
  523. struct kvm *kvm = vcpu->kvm;
  524. struct kvm_kpit_state *ps;
  525. if (vcpu && pit) {
  526. int inject = 0;
  527. ps = &pit->pit_state;
  528. /* Try to inject pending interrupts when
  529. * last one has been acked.
  530. */
  531. spin_lock(&ps->inject_lock);
  532. if (atomic_read(&ps->pit_timer.pending) && ps->irq_ack) {
  533. ps->irq_ack = 0;
  534. inject = 1;
  535. }
  536. spin_unlock(&ps->inject_lock);
  537. if (inject)
  538. __inject_pit_timer_intr(kvm);
  539. }
  540. }