vatpit
struct vatpit *vatpit; /* (i) virtual atpit */ \
struct vatpit *vm_atpit(struct vm *vm);
static void pit_timer_start_cntr0(struct vatpit *vatpit);
vatpit_delta_ticks(struct vatpit *vatpit, struct channel *c)
result += delta.frac / vatpit->freq_bt.frac;
vatpit_get_out(struct vatpit *vatpit, int channel)
c = &vatpit->channel[channel];
delta_ticks = vatpit_delta_ticks(vatpit, c);
struct vatpit *vatpit;
vatpit = arg->vatpit;
c = &vatpit->channel[arg->channel_num];
VM_CTR1(vatpit->vm, "atpit t%d fired", arg->channel_num);
VATPIT_LOCK(vatpit);
pit_timer_start_cntr0(vatpit);
vatpic_pulse_irq(vatpit->vm, 0);
vioapic_pulse_irq(vatpit->vm, 2);
VATPIT_UNLOCK(vatpit);
pit_timer_start_cntr0(struct vatpit *vatpit)
c = &vatpit->channel[0];
delta.frac = vatpit->freq_bt.frac * c->initial;
pit_update_counter(struct vatpit *vatpit, struct channel *c, bool latch)
delta_ticks = vatpit_delta_ticks(vatpit, c);
pit_readback1(struct vatpit *vatpit, int channel, uint8_t cmd)
c = &vatpit->channel[channel];
(void) pit_update_counter(vatpit, c, true);
if (c->mode == TIMER_INTTC && vatpit_get_out(vatpit, channel))
pit_readback(struct vatpit *vatpit, uint8_t cmd)
error = pit_readback1(vatpit, 0, cmd);
error = pit_readback1(vatpit, 1, cmd);
error = pit_readback1(vatpit, 2, cmd);
vatpit_update_mode(struct vatpit *vatpit, uint8_t val)
return (pit_readback(vatpit, val));
c = &vatpit->channel[sel >> 6];
pit_update_counter(vatpit, c, true);
struct vatpit *vatpit;
vatpit = vm_atpit(vm);
VM_CTR0(vatpit->vm, "vatpit attempt to read mode");
VATPIT_LOCK(vatpit);
error = vatpit_update_mode(vatpit, val);
VATPIT_UNLOCK(vatpit);
c = &vatpit->channel[port - TIMER_CNTR0];
VATPIT_LOCK(vatpit);
tmp = pit_update_counter(vatpit, c, false);
pit_timer_start_cntr0(vatpit);
VATPIT_UNLOCK(vatpit);
struct vatpit *vatpit;
vatpit = vm_atpit(vm);
VATPIT_LOCK(vatpit);
if (vatpit_get_out(vatpit, 2))
VATPIT_UNLOCK(vatpit);
struct vatpit *
struct vatpit *vatpit;
vatpit = malloc(sizeof(struct vatpit), M_VATPIT, M_WAITOK | M_ZERO);
vatpit->vm = vm;
mtx_init(&vatpit->mtx, "vatpit lock", NULL, MTX_SPIN);
FREQ2BT(PIT_8254_FREQ, &vatpit->freq_bt);
callout_init(&vatpit->channel[i].callout, 1);
arg = &vatpit->channel[i].callout_arg;
arg->vatpit = vatpit;
return (vatpit);
vatpit_cleanup(struct vatpit *vatpit)
callout_drain(&vatpit->channel[i].callout);
mtx_destroy(&vatpit->mtx);
free(vatpit, M_VATPIT);
vatpit_snapshot(struct vatpit *vatpit, struct vm_snapshot_meta *meta)
SNAPSHOT_VAR_OR_LEAVE(vatpit->freq_bt.sec, meta, ret, done);
SNAPSHOT_VAR_OR_LEAVE(vatpit->freq_bt.frac, meta, ret, done);
for (i = 0; i < nitems(vatpit->channel); i++) {
channel = &vatpit->channel[i];
#define VATPIT_LOCK(vatpit) mtx_lock_spin(&((vatpit)->mtx))
#define VATPIT_UNLOCK(vatpit) mtx_unlock_spin(&((vatpit)->mtx))
#define VATPIT_LOCKED(vatpit) mtx_owned(&((vatpit)->mtx))
struct vatpit *vatpit;
struct vatpit *vatpit_init(struct vm *vm);
void vatpit_cleanup(struct vatpit *vatpit);
int vatpit_snapshot(struct vatpit *vatpit, struct vm_snapshot_meta *meta);
struct vatpit *
return (vm->vatpit);
vm->vatpit = vatpit_init(vm);
vatpit_cleanup(vm->vatpit);