/scsi/qemu-pr-helper
/vhost-user-scsi
/vhost-user-blk
+/vhost-user-gpu
+/vhost-user-input
/fsdev/virtfs-proxy-helper
*.tmp
*.[1-9]
/docs/interop/qemu-qmp-ref.info*
/docs/interop/qemu-qmp-ref.txt
/docs/version.texi
+/contrib/vhost-user-gpu/50-qemu-gpu.json
*.tps
.stgit-*
.git-submodule-status
M: Eduardo Habkost <ehabkost@redhat.com>
M: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
S: Supported
+F: hw/core/cpu.c
F: hw/core/machine-qmp-cmds.c
F: hw/core/machine.c
F: hw/core/null-machine.c
F: hw/cpu/cluster.c
F: qapi/machine.json
F: qapi/machine-target.json
-F: qom/cpu.c
F: include/hw/boards.h
+F: include/hw/core/cpu.h
F: include/hw/cpu/cluster.h
-F: include/qom/cpu.h
F: include/sysemu/numa.h
T: git https://github.com/ehabkost/qemu.git machine-next
F: include/hw/qdev*
F: include/monitor/qdev.h
F: include/qom/
-X: include/qom/cpu.h
F: qapi/qom.json
F: qapi/qdev.json
F: qdev-monitor.c
F: qom/
-X: qom/cpu.c
F: tests/check-qom-interface.c
F: tests/check-qom-proplist.c
F: tests/test-qdev-global-props.c
#include "qemu/osdep.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "sysemu/replay.h"
#include "sysemu/sysemu.h"
return 0;
#endif
}
-
-
-TargetInfo *qmp_query_target(Error **errp)
-{
- TargetInfo *info = g_malloc0(sizeof(*info));
-
- info->arch = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME, -1,
- &error_abort);
-
- return info;
-}
struct pollfd *pfds;
int count;
int mask;
+ AudioState *s;
};
typedef struct ALSAVoiceOut {
break;
case SND_PCM_STATE_PREPARED:
- audio_run ("alsa run (prepared)");
+ audio_run(hlp->s, "alsa run (prepared)");
break;
case SND_PCM_STATE_RUNNING:
- audio_run ("alsa run (running)");
+ audio_run(hlp->s, "alsa run (running)");
break;
default:
return alsa_poll_helper (alsa->handle, &alsa->pollhlp, POLLIN);
}
-static int alsa_write (SWVoiceOut *sw, void *buf, int len)
-{
- return audio_pcm_sw_write (sw, buf, len);
-}
-
static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
{
switch (fmt) {
while (alsa->pending) {
int left_till_end_samples = hw->samples - alsa->wpos;
- int len = audio_MIN (alsa->pending, left_till_end_samples);
+ int len = MIN (alsa->pending, left_till_end_samples);
char *src = advance (alsa->pcm_buf, alsa->wpos << hw->info.shift);
while (len) {
}
}
-static int alsa_run_out (HWVoiceOut *hw, int live)
+static size_t alsa_run_out(HWVoiceOut *hw, size_t live)
{
ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
- int decr;
+ size_t decr;
snd_pcm_sframes_t avail;
avail = alsa_get_avail (alsa->handle);
return 0;
}
- decr = audio_MIN (live, avail);
+ decr = MIN (live, avail);
decr = audio_pcm_hw_clip_out (hw, alsa->pcm_buf, decr, alsa->pending);
alsa->pending += decr;
alsa_write_pending (alsa);
alsa->pcm_buf = audio_calloc(__func__, obt.samples, 1 << hw->info.shift);
if (!alsa->pcm_buf) {
- dolog ("Could not allocate DAC buffer (%d samples, each %d bytes)\n",
- hw->samples, 1 << hw->info.shift);
+ dolog("Could not allocate DAC buffer (%zu samples, each %d bytes)\n",
+ hw->samples, 1 << hw->info.shift);
alsa_anal_close1 (&handle);
return -1;
}
+ alsa->pollhlp.s = hw->s;
alsa->handle = handle;
alsa->dev = dev;
return 0;
alsa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
if (!alsa->pcm_buf) {
- dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
- hw->samples, 1 << hw->info.shift);
+ dolog("Could not allocate ADC buffer (%zu samples, each %d bytes)\n",
+ hw->samples, 1 << hw->info.shift);
alsa_anal_close1 (&handle);
return -1;
}
+ alsa->pollhlp.s = hw->s;
alsa->handle = handle;
alsa->dev = dev;
return 0;
alsa->pcm_buf = NULL;
}
-static int alsa_run_in (HWVoiceIn *hw)
+static size_t alsa_run_in(HWVoiceIn *hw)
{
ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
int hwshift = hw->info.shift;
int i;
- int live = audio_pcm_hw_get_live_in (hw);
- int dead = hw->samples - live;
- int decr;
+ size_t live = audio_pcm_hw_get_live_in (hw);
+ size_t dead = hw->samples - live;
+ size_t decr;
struct {
- int add;
- int len;
+ size_t add;
+ size_t len;
} bufs[2] = {
{ .add = hw->wpos, .len = 0 },
{ .add = 0, .len = 0 }
}
}
- decr = audio_MIN (dead, avail);
+ decr = MIN(dead, avail);
if (!decr) {
return 0;
}
return read_samples;
}
-static int alsa_read (SWVoiceIn *sw, void *buf, int size)
-{
- return audio_pcm_sw_read (sw, buf, size);
-}
-
static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)
{
ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
.init_out = alsa_init_out,
.fini_out = alsa_fini_out,
.run_out = alsa_run_out,
- .write = alsa_write,
.ctl_out = alsa_ctl_out,
.init_in = alsa_init_in,
.fini_in = alsa_fini_in,
.run_in = alsa_run_in,
- .read = alsa_read,
.ctl_in = alsa_ctl_in,
};
return NULL;
}
-static AudioState glob_audio_state;
+static QTAILQ_HEAD(AudioStateHead, AudioState) audio_states =
+ QTAILQ_HEAD_INITIALIZER(audio_states);
const struct mixeng_volume nominal_volume = {
.mute = 0,
#endif
};
+static bool legacy_config = true;
+
#ifdef AUDIO_IS_FLAWLESS_AND_NO_CHECKS_ARE_REQURIED
#error No its not
#else
case AUDIO_FORMAT_S16:
sign = 1;
+ /* fall through */
case AUDIO_FORMAT_U16:
bits = 16;
shift = 1;
case AUDIO_FORMAT_S32:
sign = 1;
+ /* fall through */
case AUDIO_FORMAT_U32:
bits = 32;
shift = 2;
(void) samples;
}
-static CaptureVoiceOut *audio_pcm_capture_find_specific (
- struct audsettings *as
- )
+static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioState *s,
+ struct audsettings *as)
{
CaptureVoiceOut *cap;
- AudioState *s = &glob_audio_state;
for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
if (audio_pcm_info_eq (&cap->hw.info, as)) {
static int audio_attach_capture (HWVoiceOut *hw)
{
- AudioState *s = &glob_audio_state;
+ AudioState *s = hw->s;
CaptureVoiceOut *cap;
audio_detach_capture (hw);
/*
* Hard voice (capture)
*/
-static int audio_pcm_hw_find_min_in (HWVoiceIn *hw)
+static size_t audio_pcm_hw_find_min_in (HWVoiceIn *hw)
{
SWVoiceIn *sw;
- int m = hw->total_samples_captured;
+ size_t m = hw->total_samples_captured;
for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
if (sw->active) {
- m = audio_MIN (m, sw->total_hw_samples_acquired);
+ m = MIN (m, sw->total_hw_samples_acquired);
}
}
return m;
}
-int audio_pcm_hw_get_live_in (HWVoiceIn *hw)
+size_t audio_pcm_hw_get_live_in(HWVoiceIn *hw)
{
- int live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);
- if (audio_bug(__func__, live < 0 || live > hw->samples)) {
- dolog ("live=%d hw->samples=%d\n", live, hw->samples);
+ size_t live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);
+ if (audio_bug(__func__, live > hw->samples)) {
+ dolog("live=%zu hw->samples=%zu\n", live, hw->samples);
return 0;
}
return live;
}
-int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
- int live, int pending)
+size_t audio_pcm_hw_clip_out(HWVoiceOut *hw, void *pcm_buf,
+ size_t live, size_t pending)
{
- int left = hw->samples - pending;
- int len = audio_MIN (left, live);
- int clipped = 0;
+ size_t left = hw->samples - pending;
+ size_t len = MIN (left, live);
+ size_t clipped = 0;
while (len) {
struct st_sample *src = hw->mix_buf + hw->rpos;
uint8_t *dst = advance (pcm_buf, hw->rpos << hw->info.shift);
- int samples_till_end_of_buf = hw->samples - hw->rpos;
- int samples_to_clip = audio_MIN (len, samples_till_end_of_buf);
+ size_t samples_till_end_of_buf = hw->samples - hw->rpos;
+ size_t samples_to_clip = MIN (len, samples_till_end_of_buf);
hw->clip (dst, src, samples_to_clip);
/*
* Soft voice (capture)
*/
-static int audio_pcm_sw_get_rpos_in (SWVoiceIn *sw)
+static size_t audio_pcm_sw_get_rpos_in(SWVoiceIn *sw)
{
HWVoiceIn *hw = sw->hw;
- int live = hw->total_samples_captured - sw->total_hw_samples_acquired;
- int rpos;
+ ssize_t live = hw->total_samples_captured - sw->total_hw_samples_acquired;
+ ssize_t rpos;
if (audio_bug(__func__, live < 0 || live > hw->samples)) {
- dolog ("live=%d hw->samples=%d\n", live, hw->samples);
+ dolog("live=%zu hw->samples=%zu\n", live, hw->samples);
return 0;
}
}
}
-int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size)
+static size_t audio_pcm_sw_read(SWVoiceIn *sw, void *buf, size_t size)
{
HWVoiceIn *hw = sw->hw;
- int samples, live, ret = 0, swlim, isamp, osamp, rpos, total = 0;
+ size_t samples, live, ret = 0, swlim, isamp, osamp, rpos, total = 0;
struct st_sample *src, *dst = sw->buf;
rpos = audio_pcm_sw_get_rpos_in (sw) % hw->samples;
live = hw->total_samples_captured - sw->total_hw_samples_acquired;
- if (audio_bug(__func__, live < 0 || live > hw->samples)) {
- dolog ("live_in=%d hw->samples=%d\n", live, hw->samples);
+ if (audio_bug(__func__, live > hw->samples)) {
+ dolog("live_in=%zu hw->samples=%zu\n", live, hw->samples);
return 0;
}
}
swlim = (live * sw->ratio) >> 32;
- swlim = audio_MIN (swlim, samples);
+ swlim = MIN (swlim, samples);
while (swlim) {
src = hw->conv_buf + rpos;
- isamp = hw->wpos - rpos;
- /* XXX: <= ? */
- if (isamp <= 0) {
+ if (hw->wpos > rpos) {
+ isamp = hw->wpos - rpos;
+ } else {
isamp = hw->samples - rpos;
}
}
osamp = swlim;
- if (audio_bug(__func__, osamp < 0)) {
- dolog ("osamp=%d\n", osamp);
- return 0;
- }
-
st_rate_flow (sw->rate, src, dst, &isamp, &osamp);
swlim -= osamp;
rpos = (rpos + isamp) % hw->samples;
/*
* Hard voice (playback)
*/
-static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)
+static size_t audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)
{
SWVoiceOut *sw;
- int m = INT_MAX;
+ size_t m = SIZE_MAX;
int nb_live = 0;
for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
if (sw->active || !sw->empty) {
- m = audio_MIN (m, sw->total_hw_samples_mixed);
+ m = MIN (m, sw->total_hw_samples_mixed);
nb_live += 1;
}
}
return m;
}
-static int audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)
+static size_t audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)
{
- int smin;
+ size_t smin;
int nb_live1;
smin = audio_pcm_hw_find_min_out (hw, &nb_live1);
}
if (nb_live1) {
- int live = smin;
+ size_t live = smin;
- if (audio_bug(__func__, live < 0 || live > hw->samples)) {
- dolog ("live=%d hw->samples=%d\n", live, hw->samples);
+ if (audio_bug(__func__, live > hw->samples)) {
+ dolog("live=%zu hw->samples=%zu\n", live, hw->samples);
return 0;
}
return live;
/*
* Soft voice (playback)
*/
-int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)
+static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t size)
{
- int hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;
- int ret = 0, pos = 0, total = 0;
+ size_t hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;
+ size_t ret = 0, pos = 0, total = 0;
if (!sw) {
return size;
hwsamples = sw->hw->samples;
live = sw->total_hw_samples_mixed;
- if (audio_bug(__func__, live < 0 || live > hwsamples)) {
- dolog ("live=%d hw->samples=%d\n", live, hwsamples);
+ if (audio_bug(__func__, live > hwsamples)) {
+ dolog("live=%zu hw->samples=%zu\n", live, hwsamples);
return 0;
}
dead = hwsamples - live;
swlim = ((int64_t) dead << 32) / sw->ratio;
- swlim = audio_MIN (swlim, samples);
+ swlim = MIN (swlim, samples);
if (swlim) {
sw->conv (sw->buf, buf, swlim);
while (swlim) {
dead = hwsamples - live;
left = hwsamples - wpos;
- blck = audio_MIN (dead, left);
+ blck = MIN (dead, left);
if (!blck) {
break;
}
#ifdef DEBUG_OUT
dolog (
- "%s: write size %d ret %d total sw %d\n",
+ "%s: write size %zu ret %zu total sw %zu\n",
SW_NAME (sw),
size >> sw->info.shift,
ret,
/*
* Timer
*/
-
-static bool audio_timer_running;
-static uint64_t audio_timer_last;
-
-static int audio_is_timer_needed (void)
+static int audio_is_timer_needed(AudioState *s)
{
HWVoiceIn *hwi = NULL;
HWVoiceOut *hwo = NULL;
- while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) {
+ while ((hwo = audio_pcm_hw_find_any_enabled_out(s, hwo))) {
if (!hwo->poll_mode) return 1;
}
- while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) {
+ while ((hwi = audio_pcm_hw_find_any_enabled_in(s, hwi))) {
if (!hwi->poll_mode) return 1;
}
return 0;
static void audio_reset_timer (AudioState *s)
{
- if (audio_is_timer_needed ()) {
+ if (audio_is_timer_needed(s)) {
timer_mod_anticipate_ns(s->ts,
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->period_ticks);
- if (!audio_timer_running) {
- audio_timer_running = true;
- audio_timer_last = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+ if (!s->timer_running) {
+ s->timer_running = true;
+ s->timer_last = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
trace_audio_timer_start(s->period_ticks / SCALE_MS);
}
} else {
timer_del(s->ts);
- if (audio_timer_running) {
- audio_timer_running = false;
+ if (s->timer_running) {
+ s->timer_running = false;
trace_audio_timer_stop();
}
}
AudioState *s = opaque;
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
- diff = now - audio_timer_last;
+ diff = now - s->timer_last;
if (diff > s->period_ticks * 3 / 2) {
trace_audio_timer_delayed(diff / SCALE_MS);
}
- audio_timer_last = now;
+ s->timer_last = now;
- audio_run("timer");
+ audio_run(s, "timer");
audio_reset_timer(s);
}
/*
* Public API
*/
-int AUD_write (SWVoiceOut *sw, void *buf, int size)
+size_t AUD_write(SWVoiceOut *sw, void *buf, size_t size)
{
if (!sw) {
/* XXX: Consider options */
return 0;
}
- return sw->hw->pcm_ops->write(sw, buf, size);
+ return audio_pcm_sw_write(sw, buf, size);
}
-int AUD_read (SWVoiceIn *sw, void *buf, int size)
+size_t AUD_read(SWVoiceIn *sw, void *buf, size_t size)
{
if (!sw) {
/* XXX: Consider options */
return 0;
}
- return sw->hw->pcm_ops->read(sw, buf, size);
+ return audio_pcm_sw_read(sw, buf, size);
}
int AUD_get_buffer_size_out (SWVoiceOut *sw)
hw = sw->hw;
if (sw->active != on) {
- AudioState *s = &glob_audio_state;
+ AudioState *s = sw->s;
SWVoiceOut *temp_sw;
SWVoiceCap *sc;
hw = sw->hw;
if (sw->active != on) {
- AudioState *s = &glob_audio_state;
+ AudioState *s = sw->s;
SWVoiceIn *temp_sw;
if (on) {
}
}
-static int audio_get_avail (SWVoiceIn *sw)
+static size_t audio_get_avail (SWVoiceIn *sw)
{
- int live;
+ size_t live;
if (!sw) {
return 0;
}
live = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
- if (audio_bug(__func__, live < 0 || live > sw->hw->samples)) {
- dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples);
+ if (audio_bug(__func__, live > sw->hw->samples)) {
+ dolog("live=%zu sw->hw->samples=%zu\n", live, sw->hw->samples);
return 0;
}
return (((int64_t) live << 32) / sw->ratio) << sw->info.shift;
}
-static int audio_get_free (SWVoiceOut *sw)
+static size_t audio_get_free(SWVoiceOut *sw)
{
- int live, dead;
+ size_t live, dead;
if (!sw) {
return 0;
live = sw->total_hw_samples_mixed;
- if (audio_bug(__func__, live < 0 || live > sw->hw->samples)) {
- dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples);
+ if (audio_bug(__func__, live > sw->hw->samples)) {
+ dolog("live=%zu sw->hw->samples=%zu\n", live, sw->hw->samples);
return 0;
}
return (((int64_t) dead << 32) / sw->ratio) << sw->info.shift;
}
-static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples)
+static void audio_capture_mix_and_clear(HWVoiceOut *hw, size_t rpos,
+ size_t samples)
{
- int n;
+ size_t n;
if (hw->enabled) {
SWVoiceCap *sc;
n = samples;
while (n) {
- int till_end_of_hw = hw->samples - rpos2;
- int to_write = audio_MIN (till_end_of_hw, n);
- int bytes = to_write << hw->info.shift;
- int written;
+ size_t till_end_of_hw = hw->samples - rpos2;
+ size_t to_write = MIN(till_end_of_hw, n);
+ size_t bytes = to_write << hw->info.shift;
+ size_t written;
sw->buf = hw->mix_buf + rpos2;
written = audio_pcm_sw_write (sw, NULL, bytes);
if (written - bytes) {
- dolog ("Could not mix %d bytes into a capture "
- "buffer, mixed %d\n",
- bytes, written);
+ dolog("Could not mix %zu bytes into a capture "
+ "buffer, mixed %zu\n",
+ bytes, written);
break;
}
n -= to_write;
}
}
- n = audio_MIN (samples, hw->samples - rpos);
- mixeng_clear (hw->mix_buf + rpos, n);
- mixeng_clear (hw->mix_buf, samples - n);
+ n = MIN(samples, hw->samples - rpos);
+ mixeng_clear(hw->mix_buf + rpos, n);
+ mixeng_clear(hw->mix_buf, samples - n);
}
static void audio_run_out (AudioState *s)
HWVoiceOut *hw = NULL;
SWVoiceOut *sw;
- while ((hw = audio_pcm_hw_find_any_enabled_out (hw))) {
- int played;
- int live, free, nb_live, cleanup_required, prev_rpos;
+ while ((hw = audio_pcm_hw_find_any_enabled_out(s, hw))) {
+ size_t played, live, prev_rpos, free;
+ int nb_live, cleanup_required;
live = audio_pcm_hw_get_live_out (hw, &nb_live);
if (!nb_live) {
live = 0;
}
- if (audio_bug(__func__, live < 0 || live > hw->samples)) {
- dolog ("live=%d hw->samples=%d\n", live, hw->samples);
+ if (audio_bug(__func__, live > hw->samples)) {
+ dolog ("live=%zu hw->samples=%zu\n", live, hw->samples);
continue;
}
played = hw->pcm_ops->run_out (hw, live);
replay_audio_out(&played);
if (audio_bug(__func__, hw->rpos >= hw->samples)) {
- dolog ("hw->rpos=%d hw->samples=%d played=%d\n",
- hw->rpos, hw->samples, played);
+ dolog("hw->rpos=%zu hw->samples=%zu played=%zu\n",
+ hw->rpos, hw->samples, played);
hw->rpos = 0;
}
#ifdef DEBUG_OUT
- dolog ("played=%d\n", played);
+ dolog("played=%zu\n", played);
#endif
if (played) {
}
if (audio_bug(__func__, played > sw->total_hw_samples_mixed)) {
- dolog ("played=%d sw->total_hw_samples_mixed=%d\n",
- played, sw->total_hw_samples_mixed);
+ dolog("played=%zu sw->total_hw_samples_mixed=%zu\n",
+ played, sw->total_hw_samples_mixed);
played = sw->total_hw_samples_mixed;
}
{
HWVoiceIn *hw = NULL;
- while ((hw = audio_pcm_hw_find_any_enabled_in (hw))) {
+ while ((hw = audio_pcm_hw_find_any_enabled_in(s, hw))) {
SWVoiceIn *sw;
- int captured = 0, min;
+ size_t captured = 0, min;
if (replay_mode != REPLAY_MODE_PLAY) {
captured = hw->pcm_ops->run_in(hw);
sw->total_hw_samples_acquired -= min;
if (sw->active) {
- int avail;
+ size_t avail;
avail = audio_get_avail (sw);
if (avail > 0) {
CaptureVoiceOut *cap;
for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
- int live, rpos, captured;
+ size_t live, rpos, captured;
HWVoiceOut *hw = &cap->hw;
SWVoiceOut *sw;
captured = live = audio_pcm_hw_get_live_out (hw, NULL);
rpos = hw->rpos;
while (live) {
- int left = hw->samples - rpos;
- int to_capture = audio_MIN (live, left);
+ size_t left = hw->samples - rpos;
+ size_t to_capture = MIN(live, left);
struct st_sample *src;
struct capture_callback *cb;
}
if (audio_bug(__func__, captured > sw->total_hw_samples_mixed)) {
- dolog ("captured=%d sw->total_hw_samples_mixed=%d\n",
- captured, sw->total_hw_samples_mixed);
+ dolog("captured=%zu sw->total_hw_samples_mixed=%zu\n",
+ captured, sw->total_hw_samples_mixed);
captured = sw->total_hw_samples_mixed;
}
}
}
-void audio_run (const char *msg)
+void audio_run(AudioState *s, const char *msg)
{
- AudioState *s = &glob_audio_state;
+ audio_run_out(s);
+ audio_run_in(s);
+ audio_run_capture(s);
- audio_run_out (s);
- audio_run_in (s);
- audio_run_capture (s);
#ifdef DEBUG_POLL
{
static double prevtime;
s->drv_opaque = drv->init(dev);
if (s->drv_opaque) {
- audio_init_nb_voices_out (drv);
- audio_init_nb_voices_in (drv);
+ audio_init_nb_voices_out(s, drv);
+ audio_init_nb_voices_in(s, drv);
s->drv = drv;
return 0;
}
int op = running ? VOICE_ENABLE : VOICE_DISABLE;
s->vm_running = running;
- while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) {
+ while ((hwo = audio_pcm_hw_find_any_enabled_out(s, hwo))) {
hwo->pcm_ops->ctl_out(hwo, op);
}
- while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) {
+ while ((hwi = audio_pcm_hw_find_any_enabled_in(s, hwi))) {
hwi->pcm_ops->ctl_in(hwi, op);
}
audio_reset_timer (s);
return is_cleaning_up;
}
-void audio_cleanup(void)
+static void free_audio_state(AudioState *s)
{
- AudioState *s = &glob_audio_state;
HWVoiceOut *hwo, *hwon;
HWVoiceIn *hwi, *hwin;
- is_cleaning_up = true;
- QLIST_FOREACH_SAFE(hwo, &glob_audio_state.hw_head_out, entries, hwon) {
+ QLIST_FOREACH_SAFE(hwo, &s->hw_head_out, entries, hwon) {
SWVoiceCap *sc;
if (hwo->enabled) {
QLIST_REMOVE(hwo, entries);
}
- QLIST_FOREACH_SAFE(hwi, &glob_audio_state.hw_head_in, entries, hwin) {
+ QLIST_FOREACH_SAFE(hwi, &s->hw_head_in, entries, hwin) {
if (hwi->enabled) {
hwi->pcm_ops->ctl_in (hwi, VOICE_DISABLE);
}
qapi_free_Audiodev(s->dev);
s->dev = NULL;
}
+
+ if (s->ts) {
+ timer_free(s->ts);
+ s->ts = NULL;
+ }
+
+ g_free(s);
+}
+
+void audio_cleanup(void)
+{
+ is_cleaning_up = true;
+ while (!QTAILQ_EMPTY(&audio_states)) {
+ AudioState *s = QTAILQ_FIRST(&audio_states);
+ QTAILQ_REMOVE(&audio_states, s, list);
+ free_audio_state(s);
+ }
}
static const VMStateDescription vmstate_audio = {
return NULL;
}
-static int audio_init(Audiodev *dev)
+/*
+ * if we have dev, this function was called because of an -audiodev argument =>
+ * initialize a new state with it
+ * if dev == NULL => legacy implicit initialization, return the already created
+ * state or create a new one
+ */
+static AudioState *audio_init(Audiodev *dev, const char *name)
{
+ static bool atexit_registered;
size_t i;
int done = 0;
const char *drvname = NULL;
VMChangeStateEntry *e;
- AudioState *s = &glob_audio_state;
+ AudioState *s;
struct audio_driver *driver;
/* silence gcc warning about uninitialized variable */
AudiodevListHead head = QSIMPLEQ_HEAD_INITIALIZER(head);
- if (s->drv) {
- if (dev) {
- dolog("Cannot create more than one audio backend, sorry\n");
- qapi_free_Audiodev(dev);
- }
- return -1;
- }
-
if (dev) {
/* -audiodev option */
+ legacy_config = false;
drvname = AudiodevDriver_str(dev->driver);
+ } else if (!QTAILQ_EMPTY(&audio_states)) {
+ if (!legacy_config) {
+ dolog("You must specify an audiodev= for the device %s\n", name);
+ exit(1);
+ }
+ return QTAILQ_FIRST(&audio_states);
} else {
/* legacy implicit initialization */
head = audio_handle_legacy_opts();
dev = QSIMPLEQ_FIRST(&head)->dev;
audio_validate_opts(dev, &error_abort);
}
+
+ s = g_malloc0(sizeof(AudioState));
s->dev = dev;
QLIST_INIT (&s->hw_head_out);
QLIST_INIT (&s->hw_head_in);
QLIST_INIT (&s->cap_head);
- atexit(audio_cleanup);
+ if (!atexit_registered) {
+ atexit(audio_cleanup);
+ atexit_registered = true;
+ }
+ QTAILQ_INSERT_TAIL(&audio_states, s, list);
s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
QLIST_INIT (&s->card_head);
vmstate_register (NULL, 0, &vmstate_audio, s);
- return 0;
+ return s;
}
void audio_free_audiodev_list(AudiodevListHead *head)
void AUD_register_card (const char *name, QEMUSoundCard *card)
{
- audio_init(NULL);
+ if (!card->state) {
+ card->state = audio_init(NULL, name);
+ }
+
card->name = g_strdup (name);
memset (&card->entries, 0, sizeof (card->entries));
- QLIST_INSERT_HEAD (&glob_audio_state.card_head, card, entries);
+ QLIST_INSERT_HEAD(&card->state->card_head, card, entries);
}
void AUD_remove_card (QEMUSoundCard *card)
}
-CaptureVoiceOut *AUD_add_capture (
+CaptureVoiceOut *AUD_add_capture(
+ AudioState *s,
struct audsettings *as,
struct audio_capture_ops *ops,
void *cb_opaque
)
{
- AudioState *s = &glob_audio_state;
CaptureVoiceOut *cap;
struct capture_callback *cb;
+ if (!s) {
+ if (!legacy_config) {
+ dolog("You must specify audiodev when trying to capture\n");
+ return NULL;
+ }
+ s = audio_init(NULL, NULL);
+ }
+
if (audio_validate_settings (as)) {
dolog ("Invalid settings were passed when trying to add capture\n");
audio_print_settings (as);
cb->ops = *ops;
cb->opaque = cb_opaque;
- cap = audio_pcm_capture_find_specific (as);
+ cap = audio_pcm_capture_find_specific(s, as);
if (cap) {
QLIST_INSERT_HEAD (&cap->cb_head, cb, entries);
return cap;
cap = g_malloc0(sizeof(*cap));
hw = &cap->hw;
+ hw->s = s;
QLIST_INIT (&hw->sw_head);
QLIST_INIT (&cap->cb_head);
QLIST_INSERT_HEAD (&s->cap_head, cap, entries);
QLIST_INSERT_HEAD (&cap->cb_head, cb, entries);
- QLIST_FOREACH(hw, &glob_audio_state.hw_head_out, entries) {
+ QLIST_FOREACH(hw, &s->hw_head_out, entries) {
audio_attach_capture (hw);
}
return cap;
AudiodevListEntry *e;
QSIMPLEQ_FOREACH(e, &audiodevs, next) {
- audio_init(e->dev);
+ audio_init(e->dev, NULL);
}
}
return audio_buffer_samples(pdo, as, def_usecs) *
audioformat_bytes_per_sample(as->fmt);
}
+
+AudioState *audio_state_by_name(const char *name)
+{
+ AudioState *s;
+ QTAILQ_FOREACH(s, &audio_states, list) {
+ assert(s->dev);
+ if (strcmp(name, s->dev->id) == 0) {
+ return s;
+ }
+ }
+ return NULL;
+}
+
+const char *audio_get_id(QEMUSoundCard *card)
+{
+ if (card->state) {
+ assert(card->state->dev);
+ return card->state->dev->id;
+ } else {
+ return "";
+ }
+}
#include "qemu/queue.h"
#include "qapi/qapi-types-audio.h"
+#include "hw/qdev-properties.h"
typedef void (*audio_callback_fn) (void *opaque, int avail);
typedef struct CaptureVoiceOut CaptureVoiceOut;
typedef struct SWVoiceIn SWVoiceIn;
+typedef struct AudioState AudioState;
typedef struct QEMUSoundCard {
char *name;
+ AudioState *state;
QLIST_ENTRY (QEMUSoundCard) entries;
} QEMUSoundCard;
void AUD_register_card (const char *name, QEMUSoundCard *card);
void AUD_remove_card (QEMUSoundCard *card);
-CaptureVoiceOut *AUD_add_capture (
+CaptureVoiceOut *AUD_add_capture(
+ AudioState *s,
struct audsettings *as,
struct audio_capture_ops *ops,
void *opaque
);
void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
-int AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
+size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size);
int AUD_get_buffer_size_out (SWVoiceOut *sw);
void AUD_set_active_out (SWVoiceOut *sw, int on);
int AUD_is_active_out (SWVoiceOut *sw);
);
void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
-int AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
+size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size);
void AUD_set_active_in (SWVoiceIn *sw, int on);
int AUD_is_active_in (SWVoiceIn *sw);
return (d + incr);
}
-#ifdef __GNUC__
-#define audio_MIN(a, b) ( __extension__ ({ \
- __typeof (a) ta = a; \
- __typeof (b) tb = b; \
- ((ta)>(tb)?(tb):(ta)); \
-}))
-
-#define audio_MAX(a, b) ( __extension__ ({ \
- __typeof (a) ta = a; \
- __typeof (b) tb = b; \
- ((ta)<(tb)?(tb):(ta)); \
-}))
-#else
-#define audio_MIN(a, b) ((a)>(b)?(b):(a))
-#define audio_MAX(a, b) ((a)<(b)?(b):(a))
-#endif
-
-int wav_start_capture (CaptureState *s, const char *path, int freq,
- int bits, int nchannels);
+int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+ int freq, int bits, int nchannels);
bool audio_is_cleaning_up(void);
void audio_cleanup(void);
void audio_init_audiodevs(void);
void audio_legacy_help(void);
+AudioState *audio_state_by_name(const char *name);
+const char *audio_get_id(QEMUSoundCard *card);
+
+#define DEFINE_AUDIO_PROPERTIES(_s, _f) \
+ DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
+
#endif /* QEMU_AUDIO_H */
int swap_endianness;
};
+typedef struct AudioState AudioState;
typedef struct SWVoiceCap SWVoiceCap;
typedef struct HWVoiceOut {
+ AudioState *s;
int enabled;
int poll_mode;
int pending_disable;
f_sample *clip;
- int rpos;
+ size_t rpos;
uint64_t ts_helper;
struct st_sample *mix_buf;
- int samples;
+ size_t samples;
QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
int ctl_caps;
} HWVoiceOut;
typedef struct HWVoiceIn {
+ AudioState *s;
int enabled;
int poll_mode;
struct audio_pcm_info info;
t_sample *conv;
- int wpos;
- int total_samples_captured;
+ size_t wpos;
+ size_t total_samples_captured;
uint64_t ts_helper;
struct st_sample *conv_buf;
- int samples;
+ size_t samples;
QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
int ctl_caps;
struct audio_pcm_ops *pcm_ops;
struct SWVoiceOut {
QEMUSoundCard *card;
+ AudioState *s;
struct audio_pcm_info info;
t_sample *conv;
int64_t ratio;
struct st_sample *buf;
void *rate;
- int total_hw_samples_mixed;
+ size_t total_hw_samples_mixed;
int active;
int empty;
HWVoiceOut *hw;
struct SWVoiceIn {
QEMUSoundCard *card;
+ AudioState *s;
int active;
struct audio_pcm_info info;
int64_t ratio;
void *rate;
- int total_hw_samples_acquired;
+ size_t total_hw_samples_acquired;
struct st_sample *buf;
f_sample *clip;
HWVoiceIn *hw;
struct audio_pcm_ops {
int (*init_out)(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque);
void (*fini_out)(HWVoiceOut *hw);
- int (*run_out) (HWVoiceOut *hw, int live);
- int (*write) (SWVoiceOut *sw, void *buf, int size);
+ size_t (*run_out)(HWVoiceOut *hw, size_t live);
int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
int (*init_in) (HWVoiceIn *hw, struct audsettings *as, void *drv_opaque);
void (*fini_in) (HWVoiceIn *hw);
- int (*run_in) (HWVoiceIn *hw);
- int (*read) (SWVoiceIn *sw, void *buf, int size);
+ size_t (*run_in)(HWVoiceIn *hw);
int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
};
int nb_hw_voices_in;
int vm_running;
int64_t period_ticks;
+
+ bool timer_running;
+ uint64_t timer_last;
+
+ QTAILQ_ENTRY(AudioState) list;
} AudioState;
extern const struct mixeng_volume nominal_volume;
void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
-int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
-int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
-
-int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
+size_t audio_pcm_hw_get_live_in(HWVoiceIn *hw);
-int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
- int live, int pending);
+size_t audio_pcm_hw_clip_out(HWVoiceOut *hw, void *pcm_buf,
+ size_t live, size_t pending);
int audio_bug (const char *funcname, int cond);
void *audio_calloc (const char *funcname, int nmemb, size_t size);
-void audio_run (const char *msg);
+void audio_run(AudioState *s, const char *msg);
#define VOICE_ENABLE 1
#define VOICE_DISABLE 2
#define VOICE_VOLUME_CAP (1 << VOICE_VOLUME)
-static inline int audio_ring_dist (int dst, int src, int len)
+static inline size_t audio_ring_dist(size_t dst, size_t src, size_t len)
{
return (dst >= src) ? (dst - src) : (len - src + dst);
}
#define HWBUF hw->conv_buf
#endif
-static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
+static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
+ struct audio_driver *drv)
{
- AudioState *s = &glob_audio_state;
int max_voices = glue (drv->max_voices_, TYPE);
int voice_size = glue (drv->voice_size_, TYPE);
HWBUF = NULL;
}
-static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
+static bool glue(audio_pcm_hw_alloc_resources_, TYPE)(HW *hw)
{
HWBUF = audio_calloc(__func__, hw->samples, sizeof(struct st_sample));
if (!HWBUF) {
- dolog ("Could not allocate " NAME " buffer (%d samples)\n",
- hw->samples);
- return -1;
+ dolog("Could not allocate " NAME " buffer (%zu samples)\n",
+ hw->samples);
+ return false;
}
- return 0;
+ return true;
}
static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
{
- AudioState *s = &glob_audio_state;
HW *hw = *hwp;
+ AudioState *s = hw->s;
if (!hw->sw_head.lh_first) {
#ifdef DAC
}
}
-static HW *glue (audio_pcm_hw_find_any_, TYPE) (HW *hw)
+static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioState *s, HW *hw)
{
- AudioState *s = &glob_audio_state;
return hw ? hw->entries.le_next : glue (s->hw_head_, TYPE).lh_first;
}
-static HW *glue (audio_pcm_hw_find_any_enabled_, TYPE) (HW *hw)
+static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, HW *hw)
{
- while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) {
+ while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
if (hw->enabled) {
return hw;
}
return NULL;
}
-static HW *glue (audio_pcm_hw_find_specific_, TYPE) (
- HW *hw,
- struct audsettings *as
- )
+static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW *hw,
+ struct audsettings *as)
{
- while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (hw))) {
+ while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
if (audio_pcm_info_eq (&hw->info, as)) {
return hw;
}
return NULL;
}
-static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
+static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
+ struct audsettings *as)
{
HW *hw;
- AudioState *s = &glob_audio_state;
struct audio_driver *drv = s->drv;
if (!glue (s->nb_hw_voices_, TYPE)) {
return NULL;
}
+ hw->s = s;
hw->pcm_ops = drv->pcm_ops;
hw->ctl_caps = drv->ctl_caps;
}
if (audio_bug(__func__, hw->samples <= 0)) {
- dolog ("hw->samples=%d\n", hw->samples);
+ dolog("hw->samples=%zd\n", hw->samples);
goto err1;
}
[hw->info.swap_endianness]
[audio_bits_to_index (hw->info.bits)];
- if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
+ if (!glue(audio_pcm_hw_alloc_resources_, TYPE)(hw)) {
goto err1;
}
abort();
}
-static HW *glue (audio_pcm_hw_add_, TYPE) (struct audsettings *as)
+static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct audsettings *as)
{
HW *hw;
- AudioState *s = &glob_audio_state;
AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
if (pdo->fixed_settings) {
- hw = glue (audio_pcm_hw_add_new_, TYPE) (as);
+ hw = glue(audio_pcm_hw_add_new_, TYPE)(s, as);
if (hw) {
return hw;
}
}
- hw = glue (audio_pcm_hw_find_specific_, TYPE) (NULL, as);
+ hw = glue(audio_pcm_hw_find_specific_, TYPE)(s, NULL, as);
if (hw) {
return hw;
}
- hw = glue (audio_pcm_hw_add_new_, TYPE) (as);
+ hw = glue(audio_pcm_hw_add_new_, TYPE)(s, as);
if (hw) {
return hw;
}
- return glue (audio_pcm_hw_find_any_, TYPE) (NULL);
+ return glue(audio_pcm_hw_find_any_, TYPE)(s, NULL);
}
-static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
+static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
+ AudioState *s,
const char *sw_name,
struct audsettings *as
)
SW *sw;
HW *hw;
struct audsettings hw_as;
- AudioState *s = &glob_audio_state;
AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
if (pdo->fixed_settings) {
sw_name ? sw_name : "unknown", sizeof (*sw));
goto err1;
}
+ sw->s = s;
- hw = glue (audio_pcm_hw_add_, TYPE) (&hw_as);
+ hw = glue(audio_pcm_hw_add_, TYPE)(s, &hw_as);
if (!hw) {
goto err2;
}
struct audsettings *as
)
{
- AudioState *s = &glob_audio_state;
+ AudioState *s = card->state;
AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
}
}
else {
- sw = glue (audio_pcm_create_voice_pair_, TYPE) (name, as);
+ sw = glue(audio_pcm_create_voice_pair_, TYPE)(s, name, as);
if (!sw) {
dolog ("Failed to create voice `%s'\n", name);
return NULL;
UInt32 audioDevicePropertyBufferFrameSize;
AudioStreamBasicDescription outputStreamBasicDescription;
AudioDeviceIOProcID ioprocid;
- int live;
- int decr;
- int rpos;
+ size_t live;
+ size_t decr;
+ size_t rpos;
} coreaudioVoiceOut;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
return 0;
}
-static int coreaudio_run_out (HWVoiceOut *hw, int live)
+static size_t coreaudio_run_out(HWVoiceOut *hw, size_t live)
{
- int decr;
+ size_t decr;
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
if (coreaudio_lock (core, "coreaudio_run_out")) {
core->live);
}
- decr = audio_MIN (core->decr, live);
+ decr = MIN (core->decr, live);
core->decr -= decr;
core->live = live - decr;
return 0;
}
-static int coreaudio_write (SWVoiceOut *sw, void *buf, int len)
-{
- return audio_pcm_sw_write (sw, buf, len);
-}
-
static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
void *drv_opaque)
{
.init_out = coreaudio_init_out,
.fini_out = coreaudio_fini_out,
.run_out = coreaudio_run_out,
- .write = coreaudio_write,
.ctl_out = coreaudio_ctl_out
};
return 0;
}
-static int dsound_write (SWVoiceOut *sw, void *buf, int len)
-{
- return audio_pcm_sw_write (sw, buf, len);
-}
-
-static int dsound_run_out (HWVoiceOut *hw, int live)
+static size_t dsound_run_out(HWVoiceOut *hw, size_t live)
{
int err;
HRESULT hr;
DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer;
- int len, hwshift;
+ size_t len;
+ int hwshift;
DWORD blen1, blen2;
DWORD len1, len2;
DWORD decr;
DWORD wpos, ppos, old_pos;
LPVOID p1, p2;
- int bufsize;
+ size_t bufsize;
dsound *s = ds->s;
AudiodevDsoundOptions *dso = &s->dev->u.dsound;
}
}
- if (audio_bug(__func__, len < 0 || len > bufsize)) {
- dolog ("len=%d bufsize=%d old_pos=%ld ppos=%ld\n",
- len, bufsize, old_pos, ppos);
+ if (audio_bug(__func__, len > bufsize)) {
+ dolog("len=%zu bufsize=%zu old_pos=%ld ppos=%ld\n",
+ len, bufsize, old_pos, ppos);
return 0;
}
return 0;
}
-static int dsound_read (SWVoiceIn *sw, void *buf, int len)
-{
- return audio_pcm_sw_read (sw, buf, len);
-}
-
-static int dsound_run_in (HWVoiceIn *hw)
+static size_t dsound_run_in(HWVoiceIn *hw)
{
int err;
HRESULT hr;
DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
LPDIRECTSOUNDCAPTUREBUFFER dscb = ds->dsound_capture_buffer;
- int live, len, dead;
+ size_t live, len, dead;
DWORD blen1, blen2;
DWORD len1, len2;
DWORD decr;
if (!len) {
return 0;
}
- len = audio_MIN (len, dead);
+ len = MIN (len, dead);
err = dsound_lock_in (
dscb,
.init_out = dsound_init_out,
.fini_out = dsound_fini_out,
.run_out = dsound_run_out,
- .write = dsound_write,
.ctl_out = dsound_ctl_out,
.init_in = dsound_init_in,
.fini_in = dsound_fini_in,
.run_in = dsound_run_in,
- .read = dsound_read,
.ctl_in = dsound_ctl_in
};
struct mixeng_volume { int mute; int64_t r; int64_t l; };
struct st_sample { int64_t l; int64_t r; };
#endif
+typedef struct st_sample st_sample;
typedef void (t_sample) (struct st_sample *dst, const void *src, int samples);
typedef void (f_sample) (void *dst, const struct st_sample *src, int samples);
extern f_sample *mixeng_clip[2][2][2][3];
void *st_rate_start (int inrate, int outrate);
-void st_rate_flow (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
- int *isamp, int *osamp);
-void st_rate_flow_mix (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
- int *isamp, int *osamp);
+void st_rate_flow(void *opaque, st_sample *ibuf, st_sample *obuf,
+ size_t *isamp, size_t *osamp);
+void st_rate_flow_mix(void *opaque, st_sample *ibuf, st_sample *obuf,
+ size_t *isamp, size_t *osamp);
void st_rate_stop (void *opaque);
void mixeng_clear (struct st_sample *buf, int len);
void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol);
int64_t old_ticks;
} NoVoiceIn;
-static int no_run_out (HWVoiceOut *hw, int live)
+static size_t no_run_out(HWVoiceOut *hw, size_t live)
{
NoVoiceOut *no = (NoVoiceOut *) hw;
- int decr, samples;
+ size_t decr, samples;
int64_t now;
int64_t ticks;
int64_t bytes;
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
ticks = now - no->old_ticks;
bytes = muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
- bytes = audio_MIN(bytes, INT_MAX);
+ bytes = MIN(bytes, SIZE_MAX);
samples = bytes >> hw->info.shift;
no->old_ticks = now;
- decr = audio_MIN (live, samples);
+ decr = MIN (live, samples);
hw->rpos = (hw->rpos + decr) % hw->samples;
return decr;
}
-static int no_write (SWVoiceOut *sw, void *buf, int len)
-{
- return audio_pcm_sw_write(sw, buf, len);
-}
-
static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque)
{
audio_pcm_init_info (&hw->info, as);
(void) hw;
}
-static int no_run_in (HWVoiceIn *hw)
+static size_t no_run_in(HWVoiceIn *hw)
{
NoVoiceIn *no = (NoVoiceIn *) hw;
- int live = audio_pcm_hw_get_live_in (hw);
- int dead = hw->samples - live;
- int samples = 0;
+ size_t live = audio_pcm_hw_get_live_in(hw);
+ size_t dead = hw->samples - live;
+ size_t samples = 0;
if (dead) {
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
no->old_ticks = now;
- bytes = audio_MIN (bytes, INT_MAX);
+ bytes = MIN (bytes, SIZE_MAX);
samples = bytes >> hw->info.shift;
- samples = audio_MIN (samples, dead);
+ samples = MIN (samples, dead);
}
return samples;
}
-static int no_read (SWVoiceIn *sw, void *buf, int size)
-{
- /* use custom code here instead of audio_pcm_sw_read() to avoid
- * useless resampling/mixing */
- int samples = size >> sw->info.shift;
- int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
- int to_clear = audio_MIN (samples, total);
- sw->total_hw_samples_acquired += total;
- audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
- return to_clear << sw->info.shift;
-}
-
static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
{
(void) hw;
.init_out = no_init_out,
.fini_out = no_fini_out,
.run_out = no_run_out,
- .write = no_write,
.ctl_out = no_ctl_out,
.init_in = no_init_in,
.fini_in = no_fini_in,
.run_in = no_run_in,
- .read = no_read,
.ctl_in = no_ctl_in
};
static void oss_helper_poll_out (void *opaque)
{
- (void) opaque;
- audio_run ("oss_poll_out");
+ AudioState *s = opaque;
+ audio_run(s, "oss_poll_out");
}
static void oss_helper_poll_in (void *opaque)
{
- (void) opaque;
- audio_run ("oss_poll_in");
+ AudioState *s = opaque;
+ audio_run(s, "oss_poll_in");
}
static void oss_poll_out (HWVoiceOut *hw)
{
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
- qemu_set_fd_handler (oss->fd, NULL, oss_helper_poll_out, NULL);
+ qemu_set_fd_handler(oss->fd, NULL, oss_helper_poll_out, hw->s);
}
static void oss_poll_in (HWVoiceIn *hw)
{
OSSVoiceIn *oss = (OSSVoiceIn *) hw;
- qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL);
-}
-
-static int oss_write (SWVoiceOut *sw, void *buf, int len)
-{
- return audio_pcm_sw_write (sw, buf, len);
+ qemu_set_fd_handler(oss->fd, oss_helper_poll_in, NULL, hw->s);
}
static int aud_to_ossfmt (AudioFormat fmt, int endianness)
int samples_written;
ssize_t bytes_written;
int samples_till_end = hw->samples - oss->wpos;
- int samples_to_write = audio_MIN (oss->pending, samples_till_end);
+ int samples_to_write = MIN (oss->pending, samples_till_end);
int bytes_to_write = samples_to_write << hw->info.shift;
void *pcm = advance (oss->pcm_buf, oss->wpos << hw->info.shift);
}
}
-static int oss_run_out (HWVoiceOut *hw, int live)
+static size_t oss_run_out(HWVoiceOut *hw, size_t live)
{
OSSVoiceOut *oss = (OSSVoiceOut *) hw;
- int err, decr;
+ int err;
+ size_t decr;
struct audio_buf_info abinfo;
struct count_info cntinfo;
- int bufsize;
+ size_t bufsize;
bufsize = hw->samples << hw->info.shift;
pos = hw->rpos << hw->info.shift;
bytes = audio_ring_dist (cntinfo.ptr, pos, bufsize);
- decr = audio_MIN (bytes >> hw->info.shift, live);
+ decr = MIN (bytes >> hw->info.shift, live);
}
else {
err = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &abinfo);
return 0;
}
- decr = audio_MIN (abinfo.bytes >> hw->info.shift, live);
+ decr = MIN (abinfo.bytes >> hw->info.shift, live);
if (!decr) {
return 0;
}
if (oss->mmapped) {
err = munmap (oss->pcm_buf, hw->samples << hw->info.shift);
if (err) {
- oss_logerr (errno, "Failed to unmap buffer %p, size %d\n",
- oss->pcm_buf, hw->samples << hw->info.shift);
+ oss_logerr(errno, "Failed to unmap buffer %p, size %zu\n",
+ oss->pcm_buf, hw->samples << hw->info.shift);
}
}
else {
0
);
if (oss->pcm_buf == MAP_FAILED) {
- oss_logerr (errno, "Failed to map %d bytes of DAC\n",
- hw->samples << hw->info.shift);
+ oss_logerr(errno, "Failed to map %zu bytes of DAC\n",
+ hw->samples << hw->info.shift);
}
else {
int err;
if (!oss->mmapped) {
err = munmap (oss->pcm_buf, hw->samples << hw->info.shift);
if (err) {
- oss_logerr (errno, "Failed to unmap buffer %p size %d\n",
- oss->pcm_buf, hw->samples << hw->info.shift);
+ oss_logerr(errno, "Failed to unmap buffer %p size %zu\n",
+ oss->pcm_buf, hw->samples << hw->info.shift);
}
}
}
1 << hw->info.shift);
if (!oss->pcm_buf) {
dolog (
- "Could not allocate DAC buffer (%d samples, each %d bytes)\n",
+ "Could not allocate DAC buffer (%zu samples, each %d bytes)\n",
hw->samples,
1 << hw->info.shift
);
hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
oss->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
if (!oss->pcm_buf) {
- dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
- hw->samples, 1 << hw->info.shift);
+ dolog("Could not allocate ADC buffer (%zu samples, each %d bytes)\n",
+ hw->samples, 1 << hw->info.shift);
oss_anal_close (&fd);
return -1;
}
oss->pcm_buf = NULL;
}
-static int oss_run_in (HWVoiceIn *hw)
+static size_t oss_run_in(HWVoiceIn *hw)
{
OSSVoiceIn *oss = (OSSVoiceIn *) hw;
int hwshift = hw->info.shift;
int i;
- int live = audio_pcm_hw_get_live_in (hw);
- int dead = hw->samples - live;
+ size_t live = audio_pcm_hw_get_live_in (hw);
+ size_t dead = hw->samples - live;
size_t read_samples = 0;
struct {
- int add;
- int len;
+ size_t add;
+ size_t len;
} bufs[2] = {
{ .add = hw->wpos, .len = 0 },
{ .add = 0, .len = 0 }
if (nread > 0) {
if (nread & hw->info.align) {
- dolog ("warning: Misaligned read %zd (requested %d), "
- "alignment %d\n", nread, bufs[i].add << hwshift,
- hw->info.align + 1);
+ dolog("warning: Misaligned read %zd (requested %zu), "
+ "alignment %d\n", nread, bufs[i].add << hwshift,
+ hw->info.align + 1);
}
read_samples += nread >> hwshift;
hw->conv (hw->conv_buf + bufs[i].add, p, nread >> hwshift);
case EAGAIN:
break;
default:
- oss_logerr (
+ oss_logerr(
errno,
- "Failed to read %d bytes of audio (to %p)\n",
+ "Failed to read %zu bytes of audio (to %p)\n",
bufs[i].len, p
);
break;
return read_samples;
}
-static int oss_read (SWVoiceIn *sw, void *buf, int size)
-{
- return audio_pcm_sw_read (sw, buf, size);
-}
-
static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
{
OSSVoiceIn *oss = (OSSVoiceIn *) hw;
.init_out = oss_init_out,
.fini_out = oss_fini_out,
.run_out = oss_run_out,
- .write = oss_write,
.ctl_out = oss_ctl_out,
.init_in = oss_init_in,
.fini_in = oss_fini_in,
.run_in = oss_run_in,
- .read = oss_read,
.ctl_in = oss_ctl_in
};
#include "audio_int.h"
#include "audio_pt_int.h"
-typedef struct {
- Audiodev *dev;
+typedef struct PAConnection {
+ char *server;
+ int refcount;
+ QTAILQ_ENTRY(PAConnection) list;
+
pa_threaded_mainloop *mainloop;
pa_context *context;
+} PAConnection;
+
+static QTAILQ_HEAD(PAConnectionHead, PAConnection) pa_conns =
+ QTAILQ_HEAD_INITIALIZER(pa_conns);
+
+typedef struct {
+ Audiodev *dev;
+ PAConnection *conn;
} paaudio;
typedef struct {
HWVoiceOut hw;
- int done;
- int live;
- int decr;
- int rpos;
+ size_t done;
+ size_t live;
+ size_t decr;
+ size_t rpos;
pa_stream *stream;
void *pcm_buf;
struct audio_pt pt;
paaudio *g;
- int samples;
+ size_t samples;
} PAVoiceOut;
typedef struct {
HWVoiceIn hw;
- int done;
- int dead;
- int incr;
- int wpos;
+ size_t done;
+ size_t dead;
+ size_t incr;
+ size_t wpos;
pa_stream *stream;
void *pcm_buf;
struct audio_pt pt;
const void *read_data;
size_t read_index, read_length;
paaudio *g;
- int samples;
+ size_t samples;
} PAVoiceIn;
-static void qpa_audio_fini(void *opaque);
+static void qpa_conn_fini(PAConnection *c);
static void GCC_FMT_ATTR (2, 3) qpa_logerr (int err, const char *fmt, ...)
{
static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror)
{
- paaudio *g = p->g;
+ PAConnection *c = p->g->conn;
- pa_threaded_mainloop_lock (g->mainloop);
+ pa_threaded_mainloop_lock(c->mainloop);
- CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
+ CHECK_DEAD_GOTO(c, p->stream, rerror, unlock_and_fail);
while (length > 0) {
size_t l;
int r;
r = pa_stream_peek (p->stream, &p->read_data, &p->read_length);
- CHECK_SUCCESS_GOTO (g, rerror, r == 0, unlock_and_fail);
+ CHECK_SUCCESS_GOTO(c, rerror, r == 0, unlock_and_fail);
if (!p->read_data) {
- pa_threaded_mainloop_wait (g->mainloop);
- CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
+ pa_threaded_mainloop_wait(c->mainloop);
+ CHECK_DEAD_GOTO(c, p->stream, rerror, unlock_and_fail);
} else {
p->read_index = 0;
}
p->read_length = 0;
p->read_index = 0;
- CHECK_SUCCESS_GOTO (g, rerror, r == 0, unlock_and_fail);
+ CHECK_SUCCESS_GOTO(c, rerror, r == 0, unlock_and_fail);
}
}
- pa_threaded_mainloop_unlock (g->mainloop);
+ pa_threaded_mainloop_unlock(c->mainloop);
return 0;
unlock_and_fail:
- pa_threaded_mainloop_unlock (g->mainloop);
+ pa_threaded_mainloop_unlock(c->mainloop);
return -1;
}
static int qpa_simple_write (PAVoiceOut *p, const void *data, size_t length, int *rerror)
{
- paaudio *g = p->g;
+ PAConnection *c = p->g->conn;
- pa_threaded_mainloop_lock (g->mainloop);
+ pa_threaded_mainloop_lock(c->mainloop);
- CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
+ CHECK_DEAD_GOTO(c, p->stream, rerror, unlock_and_fail);
while (length > 0) {
size_t l;
int r;
while (!(l = pa_stream_writable_size (p->stream))) {
- pa_threaded_mainloop_wait (g->mainloop);
- CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
+ pa_threaded_mainloop_wait(c->mainloop);
+ CHECK_DEAD_GOTO(c, p->stream, rerror, unlock_and_fail);
}
- CHECK_SUCCESS_GOTO (g, rerror, l != (size_t) -1, unlock_and_fail);
+ CHECK_SUCCESS_GOTO(c, rerror, l != (size_t) -1, unlock_and_fail);
if (l > length) {
l = length;
}
r = pa_stream_write (p->stream, data, l, NULL, 0LL, PA_SEEK_RELATIVE);
- CHECK_SUCCESS_GOTO (g, rerror, r >= 0, unlock_and_fail);
+ CHECK_SUCCESS_GOTO(c, rerror, r >= 0, unlock_and_fail);
data = (const uint8_t *) data + l;
length -= l;
}
- pa_threaded_mainloop_unlock (g->mainloop);
+ pa_threaded_mainloop_unlock(c->mainloop);
return 0;
unlock_and_fail:
- pa_threaded_mainloop_unlock (g->mainloop);
+ pa_threaded_mainloop_unlock(c->mainloop);
return -1;
}
}
for (;;) {
- int decr, to_mix, rpos;
+ size_t decr, to_mix, rpos;
for (;;) {
if (pa->done) {
}
}
- decr = to_mix = audio_MIN(pa->live, pa->samples >> 5);
+ decr = to_mix = MIN(pa->live, pa->samples >> 5);
rpos = pa->rpos;
if (audio_pt_unlock(&pa->pt, __func__)) {
while (to_mix) {
int error;
- int chunk = audio_MIN (to_mix, hw->samples - rpos);
+ size_t chunk = MIN (to_mix, hw->samples - rpos);
struct st_sample *src = hw->mix_buf + rpos;
hw->clip (pa->pcm_buf, src, chunk);
return NULL;
}
-static int qpa_run_out (HWVoiceOut *hw, int live)
+static size_t qpa_run_out(HWVoiceOut *hw, size_t live)
{
- int decr;
+ size_t decr;
PAVoiceOut *pa = (PAVoiceOut *) hw;
if (audio_pt_lock(&pa->pt, __func__)) {
return 0;
}
- decr = audio_MIN (live, pa->decr);
+ decr = MIN (live, pa->decr);
pa->decr -= decr;
pa->live = live - decr;
hw->rpos = pa->rpos;
return decr;
}
-static int qpa_write (SWVoiceOut *sw, void *buf, int len)
-{
- return audio_pcm_sw_write (sw, buf, len);
-}
-
/* capture */
static void *qpa_thread_in (void *arg)
{
}
for (;;) {
- int incr, to_grab, wpos;
+ size_t incr, to_grab, wpos;
for (;;) {
if (pa->done) {
}
}
- incr = to_grab = audio_MIN(pa->dead, pa->samples >> 5);
+ incr = to_grab = MIN(pa->dead, pa->samples >> 5);
wpos = pa->wpos;
if (audio_pt_unlock(&pa->pt, __func__)) {
while (to_grab) {
int error;
- int chunk = audio_MIN (to_grab, hw->samples - wpos);
+ size_t chunk = MIN (to_grab, hw->samples - wpos);
void *buf = advance (pa->pcm_buf, wpos);
if (qpa_simple_read (pa, buf,
return NULL;
}
-static int qpa_run_in (HWVoiceIn *hw)
+static size_t qpa_run_in(HWVoiceIn *hw)
{
- int live, incr, dead;
+ size_t live, incr, dead;
PAVoiceIn *pa = (PAVoiceIn *) hw;
if (audio_pt_lock(&pa->pt, __func__)) {
live = audio_pcm_hw_get_live_in (hw);
dead = hw->samples - live;
- incr = audio_MIN (dead, pa->incr);
+ incr = MIN (dead, pa->incr);
pa->incr -= incr;
pa->dead = dead - incr;
hw->wpos = pa->wpos;
return incr;
}
-static int qpa_read (SWVoiceIn *sw, void *buf, int len)
-{
- return audio_pcm_sw_read (sw, buf, len);
-}
-
static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness)
{
int format;
static void context_state_cb (pa_context *c, void *userdata)
{
- paaudio *g = userdata;
+ PAConnection *conn = userdata;
switch (pa_context_get_state(c)) {
case PA_CONTEXT_READY:
case PA_CONTEXT_TERMINATED:
case PA_CONTEXT_FAILED:
- pa_threaded_mainloop_signal (g->mainloop, 0);
+ pa_threaded_mainloop_signal(conn->mainloop, 0);
break;
case PA_CONTEXT_UNCONNECTED:
static void stream_state_cb (pa_stream *s, void * userdata)
{
- paaudio *g = userdata;
+ PAConnection *c = userdata;
switch (pa_stream_get_state (s)) {
case PA_STREAM_READY:
case PA_STREAM_FAILED:
case PA_STREAM_TERMINATED:
- pa_threaded_mainloop_signal (g->mainloop, 0);
+ pa_threaded_mainloop_signal(c->mainloop, 0);
break;
case PA_STREAM_UNCONNECTED:
static void stream_request_cb (pa_stream *s, size_t length, void *userdata)
{
- paaudio *g = userdata;
+ PAConnection *c = userdata;
- pa_threaded_mainloop_signal (g->mainloop, 0);
+ pa_threaded_mainloop_signal(c->mainloop, 0);
}
static pa_stream *qpa_simple_new (
- paaudio *g,
+ PAConnection *c,
const char *name,
pa_stream_direction_t dir,
const char *dev,
{
int r;
pa_stream *stream;
+ pa_stream_flags_t flags;
- pa_threaded_mainloop_lock (g->mainloop);
+ pa_threaded_mainloop_lock(c->mainloop);
- stream = pa_stream_new (g->context, name, ss, map);
+ stream = pa_stream_new(c->context, name, ss, map);
if (!stream) {
goto fail;
}
- pa_stream_set_state_callback (stream, stream_state_cb, g);
- pa_stream_set_read_callback (stream, stream_request_cb, g);
- pa_stream_set_write_callback (stream, stream_request_cb, g);
+ pa_stream_set_state_callback(stream, stream_state_cb, c);
+ pa_stream_set_read_callback(stream, stream_request_cb, c);
+ pa_stream_set_write_callback(stream, stream_request_cb, c);
+
+ flags =
+ PA_STREAM_INTERPOLATE_TIMING
+ | PA_STREAM_AUTO_TIMING_UPDATE
+ | PA_STREAM_EARLY_REQUESTS;
+
+ if (dev) {
+ /* don't move the stream if the user specified a sink/source */
+ flags |= PA_STREAM_DONT_MOVE;
+ }
if (dir == PA_STREAM_PLAYBACK) {
- r = pa_stream_connect_playback (stream, dev, attr,
- PA_STREAM_INTERPOLATE_TIMING
-#ifdef PA_STREAM_ADJUST_LATENCY
- |PA_STREAM_ADJUST_LATENCY
-#endif
- |PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL);
+ r = pa_stream_connect_playback(stream, dev, attr, flags, NULL, NULL);
} else {
- r = pa_stream_connect_record (stream, dev, attr,
- PA_STREAM_INTERPOLATE_TIMING
-#ifdef PA_STREAM_ADJUST_LATENCY
- |PA_STREAM_ADJUST_LATENCY
-#endif
- |PA_STREAM_AUTO_TIMING_UPDATE);
+ r = pa_stream_connect_record(stream, dev, attr, flags);
}
if (r < 0) {
goto fail;
}
- pa_threaded_mainloop_unlock (g->mainloop);
+ pa_threaded_mainloop_unlock(c->mainloop);
return stream;
fail:
- pa_threaded_mainloop_unlock (g->mainloop);
+ pa_threaded_mainloop_unlock(c->mainloop);
if (stream) {
pa_stream_unref (stream);
}
- *rerror = pa_context_errno (g->context);
+ *rerror = pa_context_errno(c->context);
return NULL;
}
paaudio *g = pa->g = drv_opaque;
AudiodevPaOptions *popts = &g->dev->u.pa;
AudiodevPaPerDirectionOptions *ppdo = popts->out;
+ PAConnection *c = g->conn;
ss.format = audfmt_to_pa (as->fmt, as->endianness);
ss.channels = as->nchannels;
obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
pa->stream = qpa_simple_new (
- g,
+ c,
"qemu",
PA_STREAM_PLAYBACK,
ppdo->has_name ? ppdo->name : NULL,
pa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
pa->rpos = hw->rpos;
if (!pa->pcm_buf) {
- dolog ("Could not allocate buffer (%d bytes)\n",
- hw->samples << hw->info.shift);
+ dolog("Could not allocate buffer (%zu bytes)\n",
+ hw->samples << hw->info.shift);
goto fail2;
}
paaudio *g = pa->g = drv_opaque;
AudiodevPaOptions *popts = &g->dev->u.pa;
AudiodevPaPerDirectionOptions *ppdo = popts->in;
+ PAConnection *c = g->conn;
ss.format = audfmt_to_pa (as->fmt, as->endianness);
ss.channels = as->nchannels;
obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
pa->stream = qpa_simple_new (
- g,
+ c,
"qemu",
PA_STREAM_RECORD,
ppdo->has_name ? ppdo->name : NULL,
pa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
pa->wpos = hw->wpos;
if (!pa->pcm_buf) {
- dolog ("Could not allocate buffer (%d bytes)\n",
- hw->samples << hw->info.shift);
+ dolog("Could not allocate buffer (%zu bytes)\n",
+ hw->samples << hw->info.shift);
goto fail2;
}
return -1;
}
+static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream)
+{
+ int err;
+
+ pa_threaded_mainloop_lock(c->mainloop);
+ /*
+ * wait until actually connects. workaround pa bug #247
+ * https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/247
+ */
+ while (pa_stream_get_state(stream) == PA_STREAM_CREATING) {
+ pa_threaded_mainloop_wait(c->mainloop);
+ }
+
+ err = pa_stream_disconnect(stream);
+ if (err != 0) {
+ dolog("Failed to disconnect! err=%d\n", err);
+ }
+ pa_stream_unref(stream);
+ pa_threaded_mainloop_unlock(c->mainloop);
+}
+
static void qpa_fini_out (HWVoiceOut *hw)
{
void *ret;
audio_pt_join(&pa->pt, &ret, __func__);
if (pa->stream) {
- pa_stream_unref (pa->stream);
+ qpa_simple_disconnect(pa->g->conn, pa->stream);
pa->stream = NULL;
}
audio_pt_join(&pa->pt, &ret, __func__);
if (pa->stream) {
- pa_stream_unref (pa->stream);
+ qpa_simple_disconnect(pa->g->conn, pa->stream);
pa->stream = NULL;
}
PAVoiceOut *pa = (PAVoiceOut *) hw;
pa_operation *op;
pa_cvolume v;
- paaudio *g = pa->g;
+ PAConnection *c = pa->g->conn;
#ifdef PA_CHECK_VERSION /* macro is present in 0.9.16+ */
pa_cvolume_init (&v); /* function is present in 0.9.13+ */
v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
- pa_threaded_mainloop_lock (g->mainloop);
+ pa_threaded_mainloop_lock(c->mainloop);
- op = pa_context_set_sink_input_volume (g->context,
+ op = pa_context_set_sink_input_volume(c->context,
pa_stream_get_index (pa->stream),
&v, NULL, NULL);
- if (!op)
- qpa_logerr (pa_context_errno (g->context),
- "set_sink_input_volume() failed\n");
- else
- pa_operation_unref (op);
+ if (!op) {
+ qpa_logerr(pa_context_errno(c->context),
+ "set_sink_input_volume() failed\n");
+ } else {
+ pa_operation_unref(op);
+ }
- op = pa_context_set_sink_input_mute (g->context,
+ op = pa_context_set_sink_input_mute(c->context,
pa_stream_get_index (pa->stream),
sw->vol.mute, NULL, NULL);
if (!op) {
- qpa_logerr (pa_context_errno (g->context),
- "set_sink_input_mute() failed\n");
+ qpa_logerr(pa_context_errno(c->context),
+ "set_sink_input_mute() failed\n");
} else {
- pa_operation_unref (op);
+ pa_operation_unref(op);
}
- pa_threaded_mainloop_unlock (g->mainloop);
+ pa_threaded_mainloop_unlock(c->mainloop);
}
}
return 0;
PAVoiceIn *pa = (PAVoiceIn *) hw;
pa_operation *op;
pa_cvolume v;
- paaudio *g = pa->g;
+ PAConnection *c = pa->g->conn;
#ifdef PA_CHECK_VERSION
pa_cvolume_init (&v);
v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
- pa_threaded_mainloop_lock (g->mainloop);
+ pa_threaded_mainloop_lock(c->mainloop);
- op = pa_context_set_source_output_volume (g->context,
- pa_stream_get_index (pa->stream),
+ op = pa_context_set_source_output_volume(c->context,
+ pa_stream_get_index(pa->stream),
&v, NULL, NULL);
if (!op) {
- qpa_logerr (pa_context_errno (g->context),
- "set_source_output_volume() failed\n");
+ qpa_logerr(pa_context_errno(c->context),
+ "set_source_output_volume() failed\n");
} else {
pa_operation_unref(op);
}
- op = pa_context_set_source_output_mute (g->context,
+ op = pa_context_set_source_output_mute(c->context,
pa_stream_get_index (pa->stream),
sw->vol.mute, NULL, NULL);
if (!op) {
- qpa_logerr (pa_context_errno (g->context),
- "set_source_output_mute() failed\n");
+ qpa_logerr(pa_context_errno(c->context),
+ "set_source_output_mute() failed\n");
} else {
pa_operation_unref (op);
}
- pa_threaded_mainloop_unlock (g->mainloop);
+ pa_threaded_mainloop_unlock(c->mainloop);
}
}
return 0;
return 1;
}
+/* common */
+static void *qpa_conn_init(const char *server)
+{
+ PAConnection *c = g_malloc0(sizeof(PAConnection));
+ QTAILQ_INSERT_TAIL(&pa_conns, c, list);
+
+ c->mainloop = pa_threaded_mainloop_new();
+ if (!c->mainloop) {
+ goto fail;
+ }
+
+ c->context = pa_context_new(pa_threaded_mainloop_get_api(c->mainloop),
+ server);
+ if (!c->context) {
+ goto fail;
+ }
+
+ pa_context_set_state_callback(c->context, context_state_cb, c);
+
+ if (pa_context_connect(c->context, server, 0, NULL) < 0) {
+ qpa_logerr(pa_context_errno(c->context),
+ "pa_context_connect() failed\n");
+ goto fail;
+ }
+
+ pa_threaded_mainloop_lock(c->mainloop);
+
+ if (pa_threaded_mainloop_start(c->mainloop) < 0) {
+ goto unlock_and_fail;
+ }
+
+ for (;;) {
+ pa_context_state_t state;
+
+ state = pa_context_get_state(c->context);
+
+ if (state == PA_CONTEXT_READY) {
+ break;
+ }
+
+ if (!PA_CONTEXT_IS_GOOD(state)) {
+ qpa_logerr(pa_context_errno(c->context),
+ "Wrong context state\n");
+ goto unlock_and_fail;
+ }
+
+ /* Wait until the context is ready */
+ pa_threaded_mainloop_wait(c->mainloop);
+ }
+
+ pa_threaded_mainloop_unlock(c->mainloop);
+ return c;
+
+unlock_and_fail:
+ pa_threaded_mainloop_unlock(c->mainloop);
+fail:
+ AUD_log (AUDIO_CAP, "Failed to initialize PA context");
+ qpa_conn_fini(c);
+ return NULL;
+}
+
static void *qpa_audio_init(Audiodev *dev)
{
paaudio *g;
AudiodevPaOptions *popts = &dev->u.pa;
const char *server;
+ PAConnection *c;
+
+ assert(dev->driver == AUDIODEV_DRIVER_PA);
if (!popts->has_server) {
char pidfile[64];
}
}
- assert(dev->driver == AUDIODEV_DRIVER_PA);
-
- g = g_malloc(sizeof(paaudio));
- server = popts->has_server ? popts->server : NULL;
-
if (!qpa_validate_per_direction_opts(dev, popts->in)) {
- goto fail;
+ return NULL;
}
if (!qpa_validate_per_direction_opts(dev, popts->out)) {
- goto fail;
+ return NULL;
}
+ g = g_malloc0(sizeof(paaudio));
+ server = popts->has_server ? popts->server : NULL;
+
g->dev = dev;
- g->mainloop = NULL;
- g->context = NULL;
- g->mainloop = pa_threaded_mainloop_new ();
- if (!g->mainloop) {
- goto fail;
+ QTAILQ_FOREACH(c, &pa_conns, list) {
+ if (server == NULL || c->server == NULL ?
+ server == c->server :
+ strcmp(server, c->server) == 0) {
+ g->conn = c;
+ break;
+ }
}
-
- g->context = pa_context_new (pa_threaded_mainloop_get_api (g->mainloop),
- server);
- if (!g->context) {
- goto fail;
+ if (!g->conn) {
+ g->conn = qpa_conn_init(server);
}
-
- pa_context_set_state_callback (g->context, context_state_cb, g);
-
- if (pa_context_connect(g->context, server, 0, NULL) < 0) {
- qpa_logerr (pa_context_errno (g->context),
- "pa_context_connect() failed\n");
- goto fail;
+ if (!g->conn) {
+ g_free(g);
+ return NULL;
}
- pa_threaded_mainloop_lock (g->mainloop);
+ ++g->conn->refcount;
+ return g;
+}
- if (pa_threaded_mainloop_start (g->mainloop) < 0) {
- goto unlock_and_fail;
+static void qpa_conn_fini(PAConnection *c)
+{
+ if (c->mainloop) {
+ pa_threaded_mainloop_stop(c->mainloop);
}
- for (;;) {
- pa_context_state_t state;
-
- state = pa_context_get_state (g->context);
-
- if (state == PA_CONTEXT_READY) {
- break;
- }
-
- if (!PA_CONTEXT_IS_GOOD (state)) {
- qpa_logerr (pa_context_errno (g->context),
- "Wrong context state\n");
- goto unlock_and_fail;
- }
-
- /* Wait until the context is ready */
- pa_threaded_mainloop_wait (g->mainloop);
+ if (c->context) {
+ pa_context_disconnect(c->context);
+ pa_context_unref(c->context);
}
- pa_threaded_mainloop_unlock (g->mainloop);
-
- return g;
+ if (c->mainloop) {
+ pa_threaded_mainloop_free(c->mainloop);
+ }
-unlock_and_fail:
- pa_threaded_mainloop_unlock (g->mainloop);
-fail:
- AUD_log (AUDIO_CAP, "Failed to initialize PA context");
- qpa_audio_fini(g);
- return NULL;
+ QTAILQ_REMOVE(&pa_conns, c, list);
+ g_free(c);
}
static void qpa_audio_fini (void *opaque)
{
paaudio *g = opaque;
+ PAConnection *c = g->conn;
- if (g->mainloop) {
- pa_threaded_mainloop_stop (g->mainloop);
- }
-
- if (g->context) {
- pa_context_disconnect (g->context);
- pa_context_unref (g->context);
- }
-
- if (g->mainloop) {
- pa_threaded_mainloop_free (g->mainloop);
+ if (--c->refcount == 0) {
+ qpa_conn_fini(c);
}
g_free(g);
.init_out = qpa_init_out,
.fini_out = qpa_fini_out,
.run_out = qpa_run_out,
- .write = qpa_write,
.ctl_out = qpa_ctl_out,
.init_in = qpa_init_in,
.fini_in = qpa_fini_in,
.run_in = qpa_run_in,
- .read = qpa_read,
.ctl_in = qpa_ctl_in
};
* Return number of samples processed.
*/
void NAME (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
- int *isamp, int *osamp)
+ size_t *isamp, size_t *osamp)
{
struct rate *rate = opaque;
struct st_sample *istart, *iend;
typedef struct SDLVoiceOut {
HWVoiceOut hw;
- int live;
- int decr;
+ size_t live;
+ size_t decr;
} SDLVoiceOut;
static struct SDLAudioState {
SDLVoiceOut *sdl = opaque;
SDLAudioState *s = &glob_sdl;
HWVoiceOut *hw = &sdl->hw;
- int samples = len >> hw->info.shift;
- int to_mix, decr;
+ size_t samples = len >> hw->info.shift;
+ size_t to_mix, decr;
if (s->exit || !sdl->live) {
return;
}
- /* dolog ("in callback samples=%d live=%d\n", samples, sdl->live); */
+ /* dolog ("in callback samples=%zu live=%zu\n", samples, sdl->live); */
- to_mix = audio_MIN(samples, sdl->live);
+ to_mix = MIN(samples, sdl->live);
decr = to_mix;
while (to_mix) {
- int chunk = audio_MIN(to_mix, hw->samples - hw->rpos);
+ size_t chunk = MIN(to_mix, hw->samples - hw->rpos);
struct st_sample *src = hw->mix_buf + hw->rpos;
- /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
+ /* dolog ("in callback to_mix %zu, chunk %zu\n", to_mix, chunk); */
hw->clip(buf, src, chunk);
hw->rpos = (hw->rpos + chunk) % hw->samples;
to_mix -= chunk;
sdl->live -= decr;
sdl->decr += decr;
- /* dolog ("done len=%d\n", len); */
+ /* dolog ("done len=%zu\n", len); */
/* SDL2 does not clear the remaining buffer for us, so do it on our own */
if (samples) {
}
}
-static int sdl_write_out (SWVoiceOut *sw, void *buf, int len)
+static size_t sdl_run_out(HWVoiceOut *hw, size_t live)
{
- return audio_pcm_sw_write (sw, buf, len);
-}
-
-static int sdl_run_out (HWVoiceOut *hw, int live)
-{
- int decr;
+ size_t decr;
SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
SDL_LockAudio();
sdl->live);
}
- decr = audio_MIN (sdl->decr, live);
+ decr = MIN (sdl->decr, live);
sdl->decr -= decr;
sdl->live = live;
.init_out = sdl_init_out,
.fini_out = sdl_fini_out,
.run_out = sdl_run_out,
- .write = sdl_write_out,
.ctl_out = sdl_ctl_out,
};
spice_server_remove_interface (&out->sin.base);
}
-static int line_out_run (HWVoiceOut *hw, int live)
+static size_t line_out_run (HWVoiceOut *hw, size_t live)
{
SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
- int rpos, decr;
- int samples;
+ size_t rpos, decr;
+ size_t samples;
if (!live) {
return 0;
}
decr = rate_get_samples (&hw->info, &out->rate);
- decr = audio_MIN (live, decr);
+ decr = MIN (live, decr);
samples = decr;
rpos = hw->rpos;
while (samples) {
int left_till_end_samples = hw->samples - rpos;
- int len = audio_MIN (samples, left_till_end_samples);
+ int len = MIN (samples, left_till_end_samples);
if (!out->frame) {
spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize);
out->fpos = out->frame;
}
if (out->frame) {
- len = audio_MIN (len, out->fsize);
+ len = MIN (len, out->fsize);
hw->clip (out->fpos, hw->mix_buf + rpos, len);
out->fsize -= len;
out->fpos += len;
return decr;
}
-static int line_out_write (SWVoiceOut *sw, void *buf, int len)
-{
- return audio_pcm_sw_write (sw, buf, len);
-}
-
static int line_out_ctl (HWVoiceOut *hw, int cmd, ...)
{
SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
spice_server_remove_interface (&in->sin.base);
}
-static int line_in_run (HWVoiceIn *hw)
+static size_t line_in_run(HWVoiceIn *hw)
{
SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
- int num_samples;
+ size_t num_samples;
int ready;
- int len[2];
+ size_t len[2];
uint64_t delta_samp;
const uint32_t *samples;
}
delta_samp = rate_get_samples (&hw->info, &in->rate);
- num_samples = audio_MIN (num_samples, delta_samp);
+ num_samples = MIN (num_samples, delta_samp);
ready = spice_server_record_get_samples (&in->sin, in->samples, num_samples);
samples = in->samples;
ready = LINE_IN_SAMPLES;
}
- num_samples = audio_MIN (ready, num_samples);
+ num_samples = MIN (ready, num_samples);
if (hw->wpos + num_samples > hw->samples) {
len[0] = hw->samples - hw->wpos;
return num_samples;
}
-static int line_in_read (SWVoiceIn *sw, void *buf, int size)
-{
- return audio_pcm_sw_read (sw, buf, size);
-}
-
static int line_in_ctl (HWVoiceIn *hw, int cmd, ...)
{
SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
.init_out = line_out_init,
.fini_out = line_out_fini,
.run_out = line_out_run,
- .write = line_out_write,
.ctl_out = line_out_ctl,
.init_in = line_in_init,
.fini_in = line_in_fini,
.run_in = line_in_run,
- .read = line_in_read,
.ctl_in = line_in_ctl,
};
int total_samples;
} WAVVoiceOut;
-static int wav_run_out (HWVoiceOut *hw, int live)
+static size_t wav_run_out(HWVoiceOut *hw, size_t live)
{
WAVVoiceOut *wav = (WAVVoiceOut *) hw;
- int rpos, decr, samples;
+ size_t rpos, decr, samples;
uint8_t *dst;
struct st_sample *src;
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
}
wav->old_ticks = now;
- decr = audio_MIN (live, samples);
+ decr = MIN (live, samples);
samples = decr;
rpos = hw->rpos;
while (samples) {
int left_till_end_samples = hw->samples - rpos;
- int convert_samples = audio_MIN (samples, left_till_end_samples);
+ int convert_samples = MIN (samples, left_till_end_samples);
src = hw->mix_buf + rpos;
dst = advance (wav->pcm_buf, rpos << hw->info.shift);
return decr;
}
-static int wav_write_out (SWVoiceOut *sw, void *buf, int len)
-{
- return audio_pcm_sw_write (sw, buf, len);
-}
-
/* VICE code: Store number as little endian. */
static void le_store (uint8_t *buf, uint32_t val, int len)
{
hw->samples = 1024;
wav->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
if (!wav->pcm_buf) {
- dolog ("Could not allocate buffer (%d bytes)\n",
- hw->samples << hw->info.shift);
+ dolog("Could not allocate buffer (%zu bytes)\n",
+ hw->samples << hw->info.shift);
return -1;
}
.init_out = wav_init_out,
.fini_out = wav_fini_out,
.run_out = wav_run_out,
- .write = wav_write_out,
.ctl_out = wav_ctl_out,
};
.info = wav_capture_info
};
-int wav_start_capture (CaptureState *s, const char *path, int freq,
- int bits, int nchannels)
+int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+ int freq, int bits, int nchannels)
{
WAVState *wav;
uint8_t hdr[] = {
goto error_free;
}
- cap = AUD_add_capture (&as, &ops, wav);
+ cap = AUD_add_capture(state, &as, &ops, wav);
if (!cap) {
error_report("Failed to add audio capture");
goto error_free;
##########################################
# SDL probe
-# Look for sdl configuration program (pkg-config or sdl-config). Try
-# sdl-config even without cross prefix, and favour pkg-config over sdl-config.
+# Look for sdl configuration program (pkg-config or sdl2-config). Try
+# sdl2-config even without cross prefix, and favour pkg-config over sdl2-config.
sdl_probe ()
{
if $pkg_config sdl2 --exists; then
sdlconfig="$pkg_config sdl2"
sdlversion=$($sdlconfig --modversion 2>/dev/null)
- elif has ${sdl_config}; then
+ elif has "$sdl2_config"; then
sdlconfig="$sdl2_config"
sdlversion=$($sdlconfig --version)
else
# no need to do the rest
return
fi
- if test -n "$cross_prefix" && test "$(basename "$sdlconfig")" = sdl-config; then
+ if test -n "$cross_prefix" && test "$(basename "$sdlconfig")" = sdl2-config; then
echo warning: using "\"$sdlconfig\"" to detect cross-compiled sdl >&2
fi
echo "VNC JPEG support $vnc_jpeg"
echo "VNC PNG support $vnc_png"
fi
-if test -n "$sparc_cpu"; then
- echo "Target Sparc Arch $sparc_cpu"
-fi
echo "xen support $xen"
if test "$xen" = "yes" ; then
echo "xen ctrl version $xen_ctrl_version"
preserve_env PKG_CONFIG_LIBDIR
preserve_env PKG_CONFIG_PATH
preserve_env PYTHON
-preserve_env SDL_CONFIG
preserve_env SDL2_CONFIG
preserve_env SMBD
preserve_env STRIP
#include "qemu/osdep.h"
#include "qemu/main-loop.h"
#include "exec/cpu-common.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "sysemu/cpus.h"
static QemuMutex qemu_cpu_list_lock;
a) Add a new property using ``DEFINE_PROP_BOOL`` - e.g. support-foo and
default it to true.
- b) Add an entry to the ``HW_COMPAT_`` for the previous version that sets
+ b) Add an entry to the ``hw_compat_`` for the previous version that sets
the property to false.
c) Add a static bool support_foo function that tests the property.
d) Add a subsection with a .needed set to the support_foo function
# = Firmware
##
-{ 'include' : 'common.json' }
+{ 'include' : 'machine.json' }
{ 'include' : 'block-core.json' }
##
Property cpu_common_props[] = {
#ifndef CONFIG_USER_ONLY
/* Create a memory property for softmmu CPU object,
- * so users can wire up its memory. (This can't go in qom/cpu.c
+ * so users can wire up its memory. (This can't go in hw/core/cpu.c
* because that file is compiled only once for both user-mode
* and system builds.) The default if no link is set up is to use
* the system address space.
{
.name = "wavcapture",
- .args_type = "path:F,freq:i?,bits:i?,nchannels:i?",
- .params = "path [frequency [bits [channels]]]",
+ .args_type = "path:F,audiodev:s,freq:i?,bits:i?,nchannels:i?",
+ .params = "path audiodev [frequency [bits [channels]]]",
.help = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
.cmd = hmp_wavcapture,
},
STEXI
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} @var{audiodev} [@var{frequency} [@var{bits} [@var{channels}]]]
@findex wavcapture
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
+Capture audio into @var{filename} from @var{audiodev}, using sample rate
+@var{frequency} bits per sample @var{bits} and number of channels
+@var{channels}.
Defaults:
@itemize @minus
#include "qemu/osdep.h"
#include "hw/acpi/cpu_hotplug.h"
#include "qapi/error.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "hw/i386/pc.h"
#include "qemu/error-report.h"
#include "hw/pci/pci.h"
#include "migration/vmstate.h"
#include "qemu/timer.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "sysemu/reset.h"
#include "sysemu/runstate.h"
#include "hw/acpi/acpi.h"
#include "hw/xen/xen.h"
#include "migration/qemu-file-types.h"
#include "migration/vmstate.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "trace.h"
#define GPE_BASE 0xafe0
#include "exec/address-spaces.h"
#include "trace.h"
#include "exec/target_page.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "hw/qdev-properties.h"
#include "qapi/error.h"
#include "qemu/jhash.h"
#include "qapi/error.h"
#include "qemu/bitmap.h"
#include "trace.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "target/arm/cpu.h"
#include "hw/acpi/acpi-defs.h"
#include "hw/acpi/acpi.h"
uint32_t temp = r->picb << 1;
uint32_t written = 0;
int to_copy = 0;
- temp = audio_MIN (temp, max);
+ temp = MIN (temp, max);
if (!temp) {
*stop = 1;
while (temp) {
int copied;
- to_copy = audio_MIN (temp, sizeof (tmpbuf));
+ to_copy = MIN (temp, sizeof (tmpbuf));
pci_dma_read (&s->dev, addr, tmpbuf, to_copy);
copied = AUD_write (s->voice_po, tmpbuf, to_copy);
dolog ("write_audio max=%x to_copy=%x copied=%x\n",
}
while (elapsed) {
- int temp = audio_MIN (elapsed, sizeof (s->silence));
+ int temp = MIN (elapsed, sizeof (s->silence));
while (temp) {
int copied = AUD_write (s->voice_po, s->silence, temp);
if (!copied)
int to_copy = 0;
SWVoiceIn *voice = (r - s->bm_regs) == MC_INDEX ? s->voice_mc : s->voice_pi;
- temp = audio_MIN (temp, max);
+ temp = MIN (temp, max);
if (!temp) {
*stop = 1;
while (temp) {
int acquired;
- to_copy = audio_MIN (temp, sizeof (tmpbuf));
+ to_copy = MIN (temp, sizeof (tmpbuf));
acquired = AUD_read (voice, tmpbuf, to_copy);
if (!acquired) {
*stop = 1;
}
static Property ac97_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(AC97LinkState, card),
DEFINE_PROP_UINT32 ("use_broken_id", AC97LinkState, use_broken_id, 0),
DEFINE_PROP_END_OF_LIST (),
};
return;
}
- to_play = audio_MIN (s->left, samples);
+ to_play = MIN (s->left, samples);
while (to_play) {
written = write_audio (s, to_play);
}
}
- samples = audio_MIN (samples, s->samples - s->pos);
+ samples = MIN (samples, s->samples - s->pos);
if (!samples) {
return;
}
}
static Property adlib_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(AdlibState, card),
DEFINE_PROP_UINT32 ("iobase", AdlibState, port, 0x220),
DEFINE_PROP_UINT32 ("freq", AdlibState, freq, 44100),
DEFINE_PROP_END_OF_LIST (),
int copied;
size_t to_copy;
- to_copy = audio_MIN (temp, left);
+ to_copy = MIN (temp, left);
if (to_copy > sizeof (tmpbuf)) {
to_copy = sizeof (tmpbuf);
}
till = (s->dregs[Playback_Lower_Base_Count]
| (s->dregs[Playback_Upper_Base_Count] << 8)) << s->shift;
till -= s->transferred;
- copy = audio_MIN (till, copy);
+ copy = MIN (till, copy);
}
if ((copy <= 0) || (dma_len <= 0)) {
}
static Property cs4231a_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(CSState, card),
DEFINE_PROP_UINT32 ("iobase", CSState, port, 0x534),
DEFINE_PROP_UINT32 ("irq", CSState, irq, 9),
DEFINE_PROP_UINT32 ("dma", CSState, dma, 3),
int size = d->frame_cnt & 0xffff;
int left = ((size - cnt + 1) << 2) + d->leftover;
int transferred = 0;
- int temp = audio_MIN (max, audio_MIN (left, csc_bytes));
+ int temp = MIN (max, MIN (left, csc_bytes));
int index = d - &s->chan[0];
addr += (cnt << 2) + d->leftover;
while (temp) {
int acquired, to_copy;
- to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf));
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));
acquired = AUD_read (s->adc_voice, tmpbuf, to_copy);
if (!acquired)
break;
while (temp) {
int copied, to_copy;
- to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf));
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));
pci_dma_read (&s->dev, addr, tmpbuf, to_copy);
copied = AUD_write (voice, tmpbuf, to_copy);
if (!copied)
return 0;
}
+static Property es1370_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(ES1370State, card),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
static void es1370_class_init (ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS (klass);
dc->desc = "ENSONIQ AudioPCI ES1370";
dc->vmsd = &vmstate_es1370;
dc->reset = es1370_on_reset;
+ dc->props = es1370_properties;
}
static const TypeInfo es1370_info = {
}
type_init (es1370_register_types)
-
GUSState *s = opaque;
samples = free >> s->shift;
- to_play = audio_MIN (samples, s->left);
+ to_play = MIN (samples, s->left);
while (to_play) {
int written = write_audio (s, to_play);
net += written;
}
- samples = audio_MIN (samples, s->samples);
+ samples = MIN (samples, s->samples);
if (samples) {
gus_mixvoices (&s->emu, s->freq, samples, s->mixbuf);
ldebug ("read DMA %#x %d\n", dma_pos, dma_len);
mode = k->has_autoinitialization(s->isa_dma, s->emu.gusdma);
while (left) {
- int to_copy = audio_MIN ((size_t) left, sizeof (tmpbuf));
+ int to_copy = MIN ((size_t) left, sizeof (tmpbuf));
int copied;
ldebug ("left=%d to_copy=%d pos=%d\n", left, to_copy, pos);
}
static Property gus_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(GUSState, card),
DEFINE_PROP_UINT32 ("freq", GUSState, freq, 44100),
DEFINE_PROP_UINT32 ("iobase", GUSState, port, 0x240),
DEFINE_PROP_UINT32 ("irq", GUSState, emu.gusirq, 7),
goto out_timer;
}
- int64_t to_transfer = audio_MIN(wpos - rpos, wanted_rpos - rpos);
+ int64_t to_transfer = MIN(wpos - rpos, wanted_rpos - rpos);
while (to_transfer) {
uint32_t start = (rpos & B_MASK);
- uint32_t chunk = audio_MIN(B_SIZE - start, to_transfer);
+ uint32_t chunk = MIN(B_SIZE - start, to_transfer);
int rc = hda_codec_xfer(
&st->state->hda, st->stream, false, st->buf + start, chunk);
if (!rc) {
int64_t wpos = st->wpos;
int64_t rpos = st->rpos;
- int64_t to_transfer = audio_MIN(B_SIZE - (wpos - rpos), avail);
+ int64_t to_transfer = MIN(B_SIZE - (wpos - rpos), avail);
hda_timer_sync_adjust(st, -((wpos - rpos) + to_transfer - (B_SIZE >> 1)));
while (to_transfer) {
uint32_t start = (uint32_t) (wpos & B_MASK);
- uint32_t chunk = (uint32_t) audio_MIN(B_SIZE - start, to_transfer);
+ uint32_t chunk = (uint32_t) MIN(B_SIZE - start, to_transfer);
uint32_t read = AUD_read(st->voice.in, st->buf + start, chunk);
wpos += read;
to_transfer -= read;
goto out_timer;
}
- int64_t to_transfer = audio_MIN(B_SIZE - (wpos - rpos), wanted_wpos - wpos);
+ int64_t to_transfer = MIN(B_SIZE - (wpos - rpos), wanted_wpos - wpos);
while (to_transfer) {
uint32_t start = (wpos & B_MASK);
- uint32_t chunk = audio_MIN(B_SIZE - start, to_transfer);
+ uint32_t chunk = MIN(B_SIZE - start, to_transfer);
int rc = hda_codec_xfer(
&st->state->hda, st->stream, true, st->buf + start, chunk);
if (!rc) {
int64_t wpos = st->wpos;
int64_t rpos = st->rpos;
- int64_t to_transfer = audio_MIN(wpos - rpos, avail);
+ int64_t to_transfer = MIN(wpos - rpos, avail);
if (wpos - rpos == B_SIZE) {
/* drop buffer, reset timer adjust */
while (to_transfer) {
uint32_t start = (uint32_t) (rpos & B_MASK);
- uint32_t chunk = (uint32_t) audio_MIN(B_SIZE - start, to_transfer);
+ uint32_t chunk = (uint32_t) MIN(B_SIZE - start, to_transfer);
uint32_t written = AUD_write(st->voice.out, st->buf + start, chunk);
rpos += written;
to_transfer -= written;
};
static Property hda_audio_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(HDAAudioState, card),
DEFINE_PROP_UINT32("debug", HDAAudioState, debug, 0),
DEFINE_PROP_BOOL("mixer", HDAAudioState, mixer, true),
DEFINE_PROP_BOOL("use-timer", HDAAudioState, use_timer, true),
MilkymistAC97State *s = opaque;
uint8_t buf[4096];
uint32_t remaining = s->regs[R_U_REMAINING];
- int temp = audio_MIN(remaining, avail_b);
+ int temp = MIN(remaining, avail_b);
uint32_t addr = s->regs[R_U_ADDR];
int transferred = 0;
while (temp) {
int acquired, to_copy;
- to_copy = audio_MIN(temp, sizeof(buf));
+ to_copy = MIN(temp, sizeof(buf));
acquired = AUD_read(s->voice_in, buf, to_copy);
if (!acquired) {
break;
MilkymistAC97State *s = opaque;
uint8_t buf[4096];
uint32_t remaining = s->regs[R_D_REMAINING];
- int temp = audio_MIN(remaining, free_b);
+ int temp = MIN(remaining, free_b);
uint32_t addr = s->regs[R_D_ADDR];
int transferred = 0;
while (temp) {
int copied, to_copy;
- to_copy = audio_MIN(temp, sizeof(buf));
+ to_copy = MIN(temp, sizeof(buf));
cpu_physical_memory_read(addr, buf, to_copy);
copied = AUD_write(s->voice_out, buf, to_copy);
if (!copied) {
}
};
+static Property milkymist_ac97_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(MilkymistAC97State, card),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
static void milkymist_ac97_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
dc->realize = milkymist_ac97_realize;
dc->reset = milkymist_ac97_reset;
dc->vmsd = &vmstate_milkymist_ac97;
+ dc->props = milkymist_ac97_properties;
}
static const TypeInfo milkymist_ac97_info = {
}
while (free > 0) {
- n = audio_MIN(s->samples - s->play_pos, (unsigned int)free);
+ n = MIN(s->samples - s->play_pos, (unsigned int)free);
n = AUD_write(s->voice, &s->sample_buf[s->play_pos], n);
if (!n)
break;
};
static Property pcspk_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(PCSpkState, card),
DEFINE_PROP_UINT32("iobase", PCSpkState, iobase, -1),
DEFINE_PROP_BOOL("migrate", PCSpkState, migrate, true),
DEFINE_PROP_END_OF_LIST(),
};
static Property pl041_device_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(PL041State, codec.card),
/* Non-compact FIFO depth property */
DEFINE_PROP_UINT32("nc_fifo_depth", PL041State, fifo_depth,
DEFAULT_FIFO_DEPTH),
int copied;
size_t to_copy;
- to_copy = audio_MIN (temp, left);
+ to_copy = MIN (temp, left);
if (to_copy > sizeof (tmpbuf)) {
to_copy = sizeof (tmpbuf);
}
}
static Property sb16_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(SB16State, card),
DEFINE_PROP_UINT32 ("version", SB16State, ver, 0x0405), /* 4.5 */
DEFINE_PROP_UINT32 ("iobase", SB16State, port, 0x220),
DEFINE_PROP_UINT32 ("irq", SB16State, irq, 5),
{
if (s->idx_in + s->req_in <= sizeof(s->data_in))
return;
- s->idx_in = audio_MAX(0, (int) sizeof(s->data_in) - s->req_in);
+ s->idx_in = MAX(0, (int) sizeof(s->data_in) - s->req_in);
AUD_read(*s->in[0], s->data_in + s->idx_in,
sizeof(s->data_in) - s->idx_in);
}
wm8750_out_flush(s);
} else
s->req_out = free_b - s->idx_out;
-
+
s->data_req(s->opaque, s->req_out >> 2, s->req_in >> 2);
}
wm8750_clk_update(s, 1);
}
+static Property wm8750_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(WM8750State, card),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
static void wm8750_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
sc->recv = wm8750_rx;
sc->send = wm8750_tx;
dc->vmsd = &vmstate_wm8750;
+ dc->props = wm8750_properties;
}
static const TypeInfo wm8750_info = {
common-obj-y += hotplug.o
common-obj-$(CONFIG_SOFTMMU) += nmi.o
common-obj-$(CONFIG_SOFTMMU) += vm-change-state-handler.o
+common-obj-y += cpu.o
common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
common-obj-$(CONFIG_XILINX_AXI) += stream.o
--- /dev/null
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012-2014 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/core/cpu.h"
+#include "sysemu/hw_accel.h"
+#include "qemu/notify.h"
+#include "qemu/log.h"
+#include "qemu/main-loop.h"
+#include "exec/log.h"
+#include "qemu/error-report.h"
+#include "qemu/qemu-print.h"
+#include "sysemu/tcg.h"
+#include "hw/boards.h"
+#include "hw/qdev-properties.h"
+#include "trace-root.h"
+
+CPUInterruptHandler cpu_interrupt_handler;
+
+CPUState *cpu_by_arch_id(int64_t id)
+{
+ CPUState *cpu;
+
+ CPU_FOREACH(cpu) {
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ if (cc->get_arch_id(cpu) == id) {
+ return cpu;
+ }
+ }
+ return NULL;
+}
+
+bool cpu_exists(int64_t id)
+{
+ return !!cpu_by_arch_id(id);
+}
+
+CPUState *cpu_create(const char *typename)
+{
+ Error *err = NULL;
+ CPUState *cpu = CPU(object_new(typename));
+ object_property_set_bool(OBJECT(cpu), true, "realized", &err);
+ if (err != NULL) {
+ error_report_err(err);
+ object_unref(OBJECT(cpu));
+ exit(EXIT_FAILURE);
+ }
+ return cpu;
+}
+
+bool cpu_paging_enabled(const CPUState *cpu)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ return cc->get_paging_enabled(cpu);
+}
+
+static bool cpu_common_get_paging_enabled(const CPUState *cpu)
+{
+ return false;
+}
+
+void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
+ Error **errp)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ cc->get_memory_mapping(cpu, list, errp);
+}
+
+static void cpu_common_get_memory_mapping(CPUState *cpu,
+ MemoryMappingList *list,
+ Error **errp)
+{
+ error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
+}
+
+/* Resetting the IRQ comes from across the code base so we take the
+ * BQL here if we need to. cpu_interrupt assumes it is held.*/
+void cpu_reset_interrupt(CPUState *cpu, int mask)
+{
+ bool need_lock = !qemu_mutex_iothread_locked();
+
+ if (need_lock) {
+ qemu_mutex_lock_iothread();
+ }
+ cpu->interrupt_request &= ~mask;
+ if (need_lock) {
+ qemu_mutex_unlock_iothread();
+ }
+}
+
+void cpu_exit(CPUState *cpu)
+{
+ atomic_set(&cpu->exit_request, 1);
+ /* Ensure cpu_exec will see the exit request after TCG has exited. */
+ smp_wmb();
+ atomic_set(&cpu->icount_decr_ptr->u16.high, -1);
+}
+
+int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
+ void *opaque)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ return (*cc->write_elf32_qemunote)(f, cpu, opaque);
+}
+
+static int cpu_common_write_elf32_qemunote(WriteCoreDumpFunction f,
+ CPUState *cpu, void *opaque)
+{
+ return 0;
+}
+
+int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
+ int cpuid, void *opaque)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ return (*cc->write_elf32_note)(f, cpu, cpuid, opaque);
+}
+
+static int cpu_common_write_elf32_note(WriteCoreDumpFunction f,
+ CPUState *cpu, int cpuid,
+ void *opaque)
+{
+ return -1;
+}
+
+int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
+ void *opaque)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ return (*cc->write_elf64_qemunote)(f, cpu, opaque);
+}
+
+static int cpu_common_write_elf64_qemunote(WriteCoreDumpFunction f,
+ CPUState *cpu, void *opaque)
+{
+ return 0;
+}
+
+int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
+ int cpuid, void *opaque)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ return (*cc->write_elf64_note)(f, cpu, cpuid, opaque);
+}
+
+static int cpu_common_write_elf64_note(WriteCoreDumpFunction f,
+ CPUState *cpu, int cpuid,
+ void *opaque)
+{
+ return -1;
+}
+
+
+static int cpu_common_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg)
+{
+ return 0;
+}
+
+static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg)
+{
+ return 0;
+}
+
+static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)
+{
+ /* If no extra check is required, QEMU watchpoint match can be considered
+ * as an architectural match.
+ */
+ return true;
+}
+
+static bool cpu_common_virtio_is_big_endian(CPUState *cpu)
+{
+ return target_words_bigendian();
+}
+
+static void cpu_common_noop(CPUState *cpu)
+{
+}
+
+static bool cpu_common_exec_interrupt(CPUState *cpu, int int_req)
+{
+ return false;
+}
+
+GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ GuestPanicInformation *res = NULL;
+
+ if (cc->get_crash_info) {
+ res = cc->get_crash_info(cpu);
+ }
+ return res;
+}
+
+void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ if (cc->dump_state) {
+ cpu_synchronize_state(cpu);
+ cc->dump_state(cpu, f, flags);
+ }
+}
+
+void cpu_dump_statistics(CPUState *cpu, int flags)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ if (cc->dump_statistics) {
+ cc->dump_statistics(cpu, flags);
+ }
+}
+
+void cpu_reset(CPUState *cpu)
+{
+ CPUClass *klass = CPU_GET_CLASS(cpu);
+
+ if (klass->reset != NULL) {
+ (*klass->reset)(cpu);
+ }
+
+ trace_guest_cpu_reset(cpu);
+}
+
+static void cpu_common_reset(CPUState *cpu)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ if (qemu_loglevel_mask(CPU_LOG_RESET)) {
+ qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
+ log_cpu_state(cpu, cc->reset_dump_flags);
+ }
+
+ cpu->interrupt_request = 0;
+ cpu->halted = 0;
+ cpu->mem_io_pc = 0;
+ cpu->mem_io_vaddr = 0;
+ cpu->icount_extra = 0;
+ atomic_set(&cpu->icount_decr_ptr->u32, 0);
+ cpu->can_do_io = 1;
+ cpu->exception_index = -1;
+ cpu->crash_occurred = false;
+ cpu->cflags_next_tb = -1;
+
+ if (tcg_enabled()) {
+ cpu_tb_jmp_cache_clear(cpu);
+
+ tcg_flush_softmmu_tlb(cpu);
+ }
+}
+
+static bool cpu_common_has_work(CPUState *cs)
+{
+ return false;
+}
+
+ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model)
+{
+ CPUClass *cc = CPU_CLASS(object_class_by_name(typename));
+
+ assert(cpu_model && cc->class_by_name);
+ return cc->class_by_name(cpu_model);
+}
+
+static void cpu_common_parse_features(const char *typename, char *features,
+ Error **errp)
+{
+ char *val;
+ static bool cpu_globals_initialized;
+ /* Single "key=value" string being parsed */
+ char *featurestr = features ? strtok(features, ",") : NULL;
+
+ /* should be called only once, catch invalid users */
+ assert(!cpu_globals_initialized);
+ cpu_globals_initialized = true;
+
+ while (featurestr) {
+ val = strchr(featurestr, '=');
+ if (val) {
+ GlobalProperty *prop = g_new0(typeof(*prop), 1);
+ *val = 0;
+ val++;
+ prop->driver = typename;
+ prop->property = g_strdup(featurestr);
+ prop->value = g_strdup(val);
+ qdev_prop_register_global(prop);
+ } else {
+ error_setg(errp, "Expected key=value format, found %s.",
+ featurestr);
+ return;
+ }
+ featurestr = strtok(NULL, ",");
+ }
+}
+
+static void cpu_common_realizefn(DeviceState *dev, Error **errp)
+{
+ CPUState *cpu = CPU(dev);
+ Object *machine = qdev_get_machine();
+
+ /* qdev_get_machine() can return something that's not TYPE_MACHINE
+ * if this is one of the user-only emulators; in that case there's
+ * no need to check the ignore_memory_transaction_failures board flag.
+ */
+ if (object_dynamic_cast(machine, TYPE_MACHINE)) {
+ ObjectClass *oc = object_get_class(machine);
+ MachineClass *mc = MACHINE_CLASS(oc);
+
+ if (mc) {
+ cpu->ignore_memory_transaction_failures =
+ mc->ignore_memory_transaction_failures;
+ }
+ }
+
+ if (dev->hotplugged) {
+ cpu_synchronize_post_init(cpu);
+ cpu_resume(cpu);
+ }
+
+ /* NOTE: latest generic point where the cpu is fully realized */
+ trace_init_vcpu(cpu);
+}
+
+static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
+{
+ CPUState *cpu = CPU(dev);
+ /* NOTE: latest generic point before the cpu is fully unrealized */
+ trace_fini_vcpu(cpu);
+ cpu_exec_unrealizefn(cpu);
+}
+
+static void cpu_common_initfn(Object *obj)
+{
+ CPUState *cpu = CPU(obj);
+ CPUClass *cc = CPU_GET_CLASS(obj);
+
+ cpu->cpu_index = UNASSIGNED_CPU_INDEX;
+ cpu->cluster_index = UNASSIGNED_CLUSTER_INDEX;
+ cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
+ /* *-user doesn't have configurable SMP topology */
+ /* the default value is changed by qemu_init_vcpu() for softmmu */
+ cpu->nr_cores = 1;
+ cpu->nr_threads = 1;
+
+ qemu_mutex_init(&cpu->work_mutex);
+ QTAILQ_INIT(&cpu->breakpoints);
+ QTAILQ_INIT(&cpu->watchpoints);
+
+ cpu_exec_initfn(cpu);
+}
+
+static void cpu_common_finalize(Object *obj)
+{
+ CPUState *cpu = CPU(obj);
+
+ qemu_mutex_destroy(&cpu->work_mutex);
+}
+
+static int64_t cpu_common_get_arch_id(CPUState *cpu)
+{
+ return cpu->cpu_index;
+}
+
+static vaddr cpu_adjust_watchpoint_address(CPUState *cpu, vaddr addr, int len)
+{
+ return addr;
+}
+
+static void generic_handle_interrupt(CPUState *cpu, int mask)
+{
+ cpu->interrupt_request |= mask;
+
+ if (!qemu_cpu_is_self(cpu)) {
+ qemu_cpu_kick(cpu);
+ }
+}
+
+CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
+
+static void cpu_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ CPUClass *k = CPU_CLASS(klass);
+
+ k->parse_features = cpu_common_parse_features;
+ k->reset = cpu_common_reset;
+ k->get_arch_id = cpu_common_get_arch_id;
+ k->has_work = cpu_common_has_work;
+ k->get_paging_enabled = cpu_common_get_paging_enabled;
+ k->get_memory_mapping = cpu_common_get_memory_mapping;
+ k->write_elf32_qemunote = cpu_common_write_elf32_qemunote;
+ k->write_elf32_note = cpu_common_write_elf32_note;
+ k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
+ k->write_elf64_note = cpu_common_write_elf64_note;
+ k->gdb_read_register = cpu_common_gdb_read_register;
+ k->gdb_write_register = cpu_common_gdb_write_register;
+ k->virtio_is_big_endian = cpu_common_virtio_is_big_endian;
+ k->debug_excp_handler = cpu_common_noop;
+ k->debug_check_watchpoint = cpu_common_debug_check_watchpoint;
+ k->cpu_exec_enter = cpu_common_noop;
+ k->cpu_exec_exit = cpu_common_noop;
+ k->cpu_exec_interrupt = cpu_common_exec_interrupt;
+ k->adjust_watchpoint_address = cpu_adjust_watchpoint_address;
+ set_bit(DEVICE_CATEGORY_CPU, dc->categories);
+ dc->realize = cpu_common_realizefn;
+ dc->unrealize = cpu_common_unrealizefn;
+ dc->props = cpu_common_props;
+ /*
+ * Reason: CPUs still need special care by board code: wiring up
+ * IRQs, adding reset handlers, halting non-first CPUs, ...
+ */
+ dc->user_creatable = false;
+}
+
+static const TypeInfo cpu_type_info = {
+ .name = TYPE_CPU,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(CPUState),
+ .instance_init = cpu_common_initfn,
+ .instance_finalize = cpu_common_finalize,
+ .abstract = true,
+ .class_size = sizeof(CPUClass),
+ .class_init = cpu_class_init,
+};
+
+static void cpu_register_types(void)
+{
+ type_register_static(&cpu_type_info);
+}
+
+type_init(cpu_register_types)
*/
#include "qemu/osdep.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "hw/sysbus.h"
#include "sysemu/dma.h"
#include "sysemu/reset.h"
return params;
}
+TargetInfo *qmp_query_target(Error **errp)
+{
+ TargetInfo *info = g_malloc0(sizeof(*info));
+
+ info->arch = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME, -1,
+ &error_abort);
+
+ return info;
+}
+
HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)
{
MachineState *ms = MACHINE(qdev_get_machine());
#include "hw/boards.h"
#include "sysemu/sysemu.h"
#include "exec/address-spaces.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
static void machine_none_init(MachineState *mch)
{
#include "qapi/opts-visitor.h"
#include "qapi/qapi-visit-machine.h"
#include "sysemu/qtest.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "hw/mem/pc-dimm.h"
#include "migration/vmstate.h"
#include "hw/boards.h"
*/
#include "qemu/osdep.h"
+#include "audio/audio.h"
#include "net/net.h"
#include "hw/qdev-properties.h"
#include "qapi/error.h"
};
+/* --- audiodev --- */
+static void get_audiodev(Object *obj, Visitor *v, const char* name,
+ void *opaque, Error **errp)
+{
+ DeviceState *dev = DEVICE(obj);
+ Property *prop = opaque;
+ QEMUSoundCard *card = qdev_get_prop_ptr(dev, prop);
+ char *p = g_strdup(audio_get_id(card));
+
+ visit_type_str(v, name, &p, errp);
+ g_free(p);
+}
+
+static void set_audiodev(Object *obj, Visitor *v, const char* name,
+ void *opaque, Error **errp)
+{
+ DeviceState *dev = DEVICE(obj);
+ Property *prop = opaque;
+ QEMUSoundCard *card = qdev_get_prop_ptr(dev, prop);
+ AudioState *state;
+ Error *local_err = NULL;
+ int err = 0;
+ char *str;
+
+ if (dev->realized) {
+ qdev_prop_set_after_realize(dev, name, errp);
+ return;
+ }
+
+ visit_type_str(v, name, &str, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ state = audio_state_by_name(str);
+
+ if (!state) {
+ err = -ENOENT;
+ goto out;
+ }
+ card->state = state;
+
+out:
+ error_set_from_qdev_prop_error(errp, err, dev, prop, str);
+ g_free(str);
+}
+
+const PropertyInfo qdev_prop_audiodev = {
+ .name = "str",
+ .description = "ID of an audiodev to use as a backend",
+ /* release done on shutdown */
+ .get = get_audiodev,
+ .set = set_audiodev,
+};
+
void qdev_prop_set_drive(DeviceState *dev, const char *name,
BlockBackend *value, Error **errp)
{
#include "hw/cpu/a9mpcore.h"
#include "hw/irq.h"
#include "hw/qdev-properties.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
static void a9mp_priv_set_irq(void *opaque, int irq, int level)
{
#include "qemu/osdep.h"
#include "hw/cpu/cluster.h"
#include "hw/qdev-properties.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "qemu/cutils.h"
milkymist-tmu2.o-cflags := $(X11_CFLAGS) $(OPENGL_CFLAGS)
milkymist-tmu2.o-libs := $(X11_LIBS) $(OPENGL_LIBS)
-obj-$(CONFIG_OMAP) += omap_dss.o
+common-obj-$(CONFIG_OMAP) += omap_dss.o
obj-$(CONFIG_OMAP) += omap_lcdc.o
-obj-$(CONFIG_PXA2XX) += pxa2xx_lcd.o
-obj-$(CONFIG_RASPI) += bcm2835_fb.o
-obj-$(CONFIG_SM501) += sm501.o
-obj-$(CONFIG_TCX) += tcx.o
-obj-$(CONFIG_CG3) += cg3.o
+common-obj-$(CONFIG_PXA2XX) += pxa2xx_lcd.o
+common-obj-$(CONFIG_RASPI) += bcm2835_fb.o
+common-obj-$(CONFIG_SM501) += sm501.o
+common-obj-$(CONFIG_TCX) += tcx.o
+common-obj-$(CONFIG_CG3) += cg3.o
obj-$(CONFIG_VGA) += vga.o
virtio-gpu.o-libs += $(VIRGL_LIBS)
virtio-gpu-3d.o-cflags := $(VIRGL_CFLAGS)
virtio-gpu-3d.o-libs += $(VIRGL_LIBS)
-obj-$(CONFIG_DPCD) += dpcd.o
-obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx_dp.o
+common-obj-$(CONFIG_DPCD) += dpcd.o
+common-obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx_dp.o
-obj-$(CONFIG_ATI_VGA) += ati.o ati_2d.o ati_dbg.o
+common-obj-$(CONFIG_ATI_VGA) += ati.o ati_2d.o ati_dbg.o
#include "qapi/error.h"
#include "qemu/log.h"
#include "qemu/module.h"
-#include "cpu.h"
#include "hw/char/serial.h"
#include "ui/console.h"
#include "hw/sysbus.h"
case 0x404 ... 0x4fe:
if (s->model <= omap_dma_3_1)
break;
+ /* fall through */
case 0x400:
- /* Fall through. */
if (omap_dma_sys_write(s, addr, value))
break;
return;
#include "qemu/bitmap.h"
#include "qemu/error-report.h"
#include "hw/pci/pci.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "target/i386/cpu.h"
#include "hw/misc/pvpanic.h"
#include "hw/timer/hpet.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-common.h"
#include "qapi/visitor.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "hw/nmi.h"
#include "hw/usb.h"
#include "hw/i386/intel_iommu.h"
* pc_compat_*() functions that run on machine-init time and
* change global QEMU state are deprecated. Please don't create
* one, and implement any pc-*-2.4 (and newer) compat code in
- * HW_COMPAT_*, PC_COMPAT_*, or * pc_*_machine_options().
+ * hw_compat_*, pc_compat_*, or * pc_*_machine_options().
*/
static void pc_compat_2_3_fn(MachineState *machine)
#include "hw/sysbus.h"
#include "gic_internal.h"
#include "qapi/error.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "trace.h"
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu/module.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "hw/intc/arm_gicv3_common.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
ibe->outbuf[ibe->outlen] = VM_ESCAPE_CHAR;
ibe->outlen++;
ch |= 0x10;
- /* No break */
-
+ /* fall through */
default:
ibe->outbuf[ibe->outlen] = ch;
ibe->outlen++;
#include "exec/address-spaces.h"
#include "sysemu/runstate.h"
#include "sysemu/sysemu.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "hw/nvram/fw_cfg.h"
#include "qemu/cutils.h"
#include "qemu/main-loop.h"
#include "qemu/module.h"
#include "arm-powerctl.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#ifndef DEBUG_IMX6_SRC
#define DEBUG_IMX6_SRC 0
/*
* EEPROM contents documented in Tables 5-2 and 5-3, pp. 98-102.
- * Note: A valid DevId will be inserted during pci_e1000_init().
+ * Note: A valid DevId will be inserted during pci_e1000_realize().
*/
static const uint16_t e1000_eeprom_template[64] = {
0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0x0000, 0x0000, 0x0000,
#include "mmu-hash64.h"
#include "mmu-book3s-v3.h"
#include "cpu-models.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "hw/boards.h"
#include "hw/ppc/ppc.h"
g_assert(source->enabled);
break;
}
- /* fall back to epow for legacy hotplug interrupt source */
+ /* fall through back to epow for legacy hotplug interrupt source */
case RTAS_LOG_TYPE_EPOW:
source = spapr_event_sources_get_source(spapr->event_sources,
EVENT_CLASS_EPOW);
#include "qemu/bitops.h"
#include "qemu/log.h"
#include "qemu/module.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#ifndef A9_GTIMER_ERR_DEBUG
#define A9_GTIMER_ERR_DEBUG 0
#include "qapi/error.h"
#include "qemu/main-loop.h"
#include "qemu/module.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define PTIMER_POLICY \
(PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD | \
};
static Property usb_audio_properties[] = {
+ DEFINE_AUDIO_PROPERTIES(USBAudioState, card),
DEFINE_PROP_UINT32("debug", USBAudioState, debug, 0),
DEFINE_PROP_UINT32("buffer", USBAudioState, buffer,
32 * USBAUDIO_PACKET_SIZE),
#include "exec/cpu-common.h"
#include "exec/memory.h"
#include "qemu/thread.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "qemu/rcu.h"
#define EXCP_INTERRUPT 0x10000 /* async interruption */
#include "exec/hwaddr.h"
#endif
#include "exec/memattrs.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "cpu-param.h"
#define QEMU_EXEC_LOG_H
#include "qemu/log.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "disas/disas.h"
/* cpu_dump_state() logging functions: */
#include "qapi/qapi-types-machine.h"
#include "qemu/module.h"
#include "qom/object.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
/**
* memory_region_allocate_system_memory - Allocate a board's main memory
--- /dev/null
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
+ */
+#ifndef QEMU_CPU_H
+#define QEMU_CPU_H
+
+#include "hw/qdev-core.h"
+#include "disas/dis-asm.h"
+#include "exec/hwaddr.h"
+#include "exec/memattrs.h"
+#include "qapi/qapi-types-run-state.h"
+#include "qemu/bitmap.h"
+#include "qemu/rcu_queue.h"
+#include "qemu/queue.h"
+#include "qemu/thread.h"
+
+typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
+ void *opaque);
+
+/**
+ * vaddr:
+ * Type wide enough to contain any #target_ulong virtual address.
+ */
+typedef uint64_t vaddr;
+#define VADDR_PRId PRId64
+#define VADDR_PRIu PRIu64
+#define VADDR_PRIo PRIo64
+#define VADDR_PRIx PRIx64
+#define VADDR_PRIX PRIX64
+#define VADDR_MAX UINT64_MAX
+
+/**
+ * SECTION:cpu
+ * @section_id: QEMU-cpu
+ * @title: CPU Class
+ * @short_description: Base class for all CPUs
+ */
+
+#define TYPE_CPU "cpu"
+
+/* Since this macro is used a lot in hot code paths and in conjunction with
+ * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
+ * an unchecked cast.
+ */
+#define CPU(obj) ((CPUState *)(obj))
+
+#define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
+#define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
+
+typedef enum MMUAccessType {
+ MMU_DATA_LOAD = 0,
+ MMU_DATA_STORE = 1,
+ MMU_INST_FETCH = 2
+} MMUAccessType;
+
+typedef struct CPUWatchpoint CPUWatchpoint;
+
+typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
+ bool is_write, bool is_exec, int opaque,
+ unsigned size);
+
+struct TranslationBlock;
+
+/**
+ * CPUClass:
+ * @class_by_name: Callback to map -cpu command line model name to an
+ * instantiatable CPU type.
+ * @parse_features: Callback to parse command line arguments.
+ * @reset: Callback to reset the #CPUState to its initial state.
+ * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
+ * @has_work: Callback for checking if there is work to do.
+ * @do_interrupt: Callback for interrupt handling.
+ * @do_unassigned_access: Callback for unassigned access handling.
+ * (this is deprecated: new targets should use do_transaction_failed instead)
+ * @do_unaligned_access: Callback for unaligned access handling, if
+ * the target defines #TARGET_ALIGNED_ONLY.
+ * @do_transaction_failed: Callback for handling failed memory transactions
+ * (ie bus faults or external aborts; not MMU faults)
+ * @virtio_is_big_endian: Callback to return %true if a CPU which supports
+ * runtime configurable endianness is currently big-endian. Non-configurable
+ * CPUs can use the default implementation of this method. This method should
+ * not be used by any callers other than the pre-1.0 virtio devices.
+ * @memory_rw_debug: Callback for GDB memory access.
+ * @dump_state: Callback for dumping state.
+ * @dump_statistics: Callback for dumping statistics.
+ * @get_arch_id: Callback for getting architecture-dependent CPU ID.
+ * @get_paging_enabled: Callback for inquiring whether paging is enabled.
+ * @get_memory_mapping: Callback for obtaining the memory mappings.
+ * @set_pc: Callback for setting the Program Counter register. This
+ * should have the semantics used by the target architecture when
+ * setting the PC from a source such as an ELF file entry point;
+ * for example on Arm it will also set the Thumb mode bit based
+ * on the least significant bit of the new PC value.
+ * If the target behaviour here is anything other than "set
+ * the PC register to the value passed in" then the target must
+ * also implement the synchronize_from_tb hook.
+ * @synchronize_from_tb: Callback for synchronizing state from a TCG
+ * #TranslationBlock. This is called when we abandon execution
+ * of a TB before starting it, and must set all parts of the CPU
+ * state which the previous TB in the chain may not have updated.
+ * This always includes at least the program counter; some targets
+ * will need to do more. If this hook is not implemented then the
+ * default is to call @set_pc(tb->pc).
+ * @tlb_fill: Callback for handling a softmmu tlb miss or user-only
+ * address fault. For system mode, if the access is valid, call
+ * tlb_set_page and return true; if the access is invalid, and
+ * probe is true, return false; otherwise raise an exception and
+ * do not return. For user-only mode, always raise an exception
+ * and do not return.
+ * @get_phys_page_debug: Callback for obtaining a physical address.
+ * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
+ * associated memory transaction attributes to use for the access.
+ * CPUs which use memory transaction attributes should implement this
+ * instead of get_phys_page_debug.
+ * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
+ * a memory access with the specified memory transaction attributes.
+ * @gdb_read_register: Callback for letting GDB read a register.
+ * @gdb_write_register: Callback for letting GDB write a register.
+ * @debug_check_watchpoint: Callback: return true if the architectural
+ * watchpoint whose address has matched should really fire.
+ * @debug_excp_handler: Callback for handling debug exceptions.
+ * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
+ * 64-bit VM coredump.
+ * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
+ * note to a 32-bit VM coredump.
+ * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
+ * 32-bit VM coredump.
+ * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
+ * note to a 32-bit VM coredump.
+ * @vmsd: State description for migration.
+ * @gdb_num_core_regs: Number of core registers accessible to GDB.
+ * @gdb_core_xml_file: File name for core registers GDB XML description.
+ * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
+ * before the insn which triggers a watchpoint rather than after it.
+ * @gdb_arch_name: Optional callback that returns the architecture name known
+ * to GDB. The caller must free the returned string with g_free.
+ * @gdb_get_dynamic_xml: Callback to return dynamically generated XML for the
+ * gdb stub. Returns a pointer to the XML contents for the specified XML file
+ * or NULL if the CPU doesn't have a dynamically generated content for it.
+ * @cpu_exec_enter: Callback for cpu_exec preparation.
+ * @cpu_exec_exit: Callback for cpu_exec cleanup.
+ * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
+ * @disas_set_info: Setup architecture specific components of disassembly info
+ * @adjust_watchpoint_address: Perform a target-specific adjustment to an
+ * address before attempting to match it against watchpoints.
+ *
+ * Represents a CPU family or model.
+ */
+typedef struct CPUClass {
+ /*< private >*/
+ DeviceClass parent_class;
+ /*< public >*/
+
+ ObjectClass *(*class_by_name)(const char *cpu_model);
+ void (*parse_features)(const char *typename, char *str, Error **errp);
+
+ void (*reset)(CPUState *cpu);
+ int reset_dump_flags;
+ bool (*has_work)(CPUState *cpu);
+ void (*do_interrupt)(CPUState *cpu);
+ CPUUnassignedAccess do_unassigned_access;
+ void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
+ MMUAccessType access_type,
+ int mmu_idx, uintptr_t retaddr);
+ void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
+ unsigned size, MMUAccessType access_type,
+ int mmu_idx, MemTxAttrs attrs,
+ MemTxResult response, uintptr_t retaddr);
+ bool (*virtio_is_big_endian)(CPUState *cpu);
+ int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
+ uint8_t *buf, int len, bool is_write);
+ void (*dump_state)(CPUState *cpu, FILE *, int flags);
+ GuestPanicInformation* (*get_crash_info)(CPUState *cpu);
+ void (*dump_statistics)(CPUState *cpu, int flags);
+ int64_t (*get_arch_id)(CPUState *cpu);
+ bool (*get_paging_enabled)(const CPUState *cpu);
+ void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
+ Error **errp);
+ void (*set_pc)(CPUState *cpu, vaddr value);
+ void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
+ bool (*tlb_fill)(CPUState *cpu, vaddr address, int size,
+ MMUAccessType access_type, int mmu_idx,
+ bool probe, uintptr_t retaddr);
+ hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
+ hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
+ MemTxAttrs *attrs);
+ int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
+ int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg);
+ int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
+ bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
+ void (*debug_excp_handler)(CPUState *cpu);
+
+ int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
+ int cpuid, void *opaque);
+ int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
+ void *opaque);
+ int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
+ int cpuid, void *opaque);
+ int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
+ void *opaque);
+
+ const VMStateDescription *vmsd;
+ const char *gdb_core_xml_file;
+ gchar * (*gdb_arch_name)(CPUState *cpu);
+ const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
+ void (*cpu_exec_enter)(CPUState *cpu);
+ void (*cpu_exec_exit)(CPUState *cpu);
+ bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
+
+ void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
+ vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
+ void (*tcg_initialize)(void);
+
+ /* Keep non-pointer data at the end to minimize holes. */
+ int gdb_num_core_regs;
+ bool gdb_stop_before_watchpoint;
+} CPUClass;
+
+/*
+ * Low 16 bits: number of cycles left, used only in icount mode.
+ * High 16 bits: Set to -1 to force TCG to stop executing linked TBs
+ * for this CPU and return to its top level loop (even in non-icount mode).
+ * This allows a single read-compare-cbranch-write sequence to test
+ * for both decrementer underflow and exceptions.
+ */
+typedef union IcountDecr {
+ uint32_t u32;
+ struct {
+#ifdef HOST_WORDS_BIGENDIAN
+ uint16_t high;
+ uint16_t low;
+#else
+ uint16_t low;
+ uint16_t high;
+#endif
+ } u16;
+} IcountDecr;
+
+typedef struct CPUBreakpoint {
+ vaddr pc;
+ int flags; /* BP_* */
+ QTAILQ_ENTRY(CPUBreakpoint) entry;
+} CPUBreakpoint;
+
+struct CPUWatchpoint {
+ vaddr vaddr;
+ vaddr len;
+ vaddr hitaddr;
+ MemTxAttrs hitattrs;
+ int flags; /* BP_* */
+ QTAILQ_ENTRY(CPUWatchpoint) entry;
+};
+
+struct KVMState;
+struct kvm_run;
+
+struct hax_vcpu_state;
+
+#define TB_JMP_CACHE_BITS 12
+#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
+
+/* work queue */
+
+/* The union type allows passing of 64 bit target pointers on 32 bit
+ * hosts in a single parameter
+ */
+typedef union {
+ int host_int;
+ unsigned long host_ulong;
+ void *host_ptr;
+ vaddr target_ptr;
+} run_on_cpu_data;
+
+#define RUN_ON_CPU_HOST_PTR(p) ((run_on_cpu_data){.host_ptr = (p)})
+#define RUN_ON_CPU_HOST_INT(i) ((run_on_cpu_data){.host_int = (i)})
+#define RUN_ON_CPU_HOST_ULONG(ul) ((run_on_cpu_data){.host_ulong = (ul)})
+#define RUN_ON_CPU_TARGET_PTR(v) ((run_on_cpu_data){.target_ptr = (v)})
+#define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL)
+
+typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
+
+struct qemu_work_item;
+
+#define CPU_UNSET_NUMA_NODE_ID -1
+#define CPU_TRACE_DSTATE_MAX_EVENTS 32
+
+/**
+ * CPUState:
+ * @cpu_index: CPU index (informative).
+ * @cluster_index: Identifies which cluster this CPU is in.
+ * For boards which don't define clusters or for "loose" CPUs not assigned
+ * to a cluster this will be UNASSIGNED_CLUSTER_INDEX; otherwise it will
+ * be the same as the cluster-id property of the CPU object's TYPE_CPU_CLUSTER
+ * QOM parent.
+ * @nr_cores: Number of cores within this CPU package.
+ * @nr_threads: Number of threads within this CPU.
+ * @running: #true if CPU is currently running (lockless).
+ * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
+ * valid under cpu_list_lock.
+ * @created: Indicates whether the CPU thread has been successfully created.
+ * @interrupt_request: Indicates a pending interrupt request.
+ * @halted: Nonzero if the CPU is in suspended state.
+ * @stop: Indicates a pending stop request.
+ * @stopped: Indicates the CPU has been artificially stopped.
+ * @unplug: Indicates a pending CPU unplug request.
+ * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
+ * @singlestep_enabled: Flags for single-stepping.
+ * @icount_extra: Instructions until next timer event.
+ * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
+ * requires that IO only be performed on the last instruction of a TB
+ * so that interrupts take effect immediately.
+ * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
+ * AddressSpaces this CPU has)
+ * @num_ases: number of CPUAddressSpaces in @cpu_ases
+ * @as: Pointer to the first AddressSpace, for the convenience of targets which
+ * only have a single AddressSpace
+ * @env_ptr: Pointer to subclass-specific CPUArchState field.
+ * @icount_decr_ptr: Pointer to IcountDecr field within subclass.
+ * @gdb_regs: Additional GDB registers.
+ * @gdb_num_regs: Number of total registers accessible to GDB.
+ * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
+ * @next_cpu: Next CPU sharing TB cache.
+ * @opaque: User data.
+ * @mem_io_pc: Host Program Counter at which the memory was accessed.
+ * @mem_io_vaddr: Target virtual address at which the memory was accessed.
+ * @kvm_fd: vCPU file descriptor for KVM.
+ * @work_mutex: Lock to prevent multiple access to queued_work_*.
+ * @queued_work_first: First asynchronous work pending.
+ * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes
+ * to @trace_dstate).
+ * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
+ * @ignore_memory_transaction_failures: Cached copy of the MachineState
+ * flag of the same name: allows the board to suppress calling of the
+ * CPU do_transaction_failed hook function.
+ *
+ * State of one CPU core or thread.
+ */
+struct CPUState {
+ /*< private >*/
+ DeviceState parent_obj;
+ /*< public >*/
+
+ int nr_cores;
+ int nr_threads;
+
+ struct QemuThread *thread;
+#ifdef _WIN32
+ HANDLE hThread;
+#endif
+ int thread_id;
+ bool running, has_waiter;
+ struct QemuCond *halt_cond;
+ bool thread_kicked;
+ bool created;
+ bool stop;
+ bool stopped;
+ bool unplug;
+ bool crash_occurred;
+ bool exit_request;
+ uint32_t cflags_next_tb;
+ /* updates protected by BQL */
+ uint32_t interrupt_request;
+ int singlestep_enabled;
+ int64_t icount_budget;
+ int64_t icount_extra;
+ uint64_t random_seed;
+ sigjmp_buf jmp_env;
+
+ QemuMutex work_mutex;
+ struct qemu_work_item *queued_work_first, *queued_work_last;
+
+ CPUAddressSpace *cpu_ases;
+ int num_ases;
+ AddressSpace *as;
+ MemoryRegion *memory;
+
+ void *env_ptr; /* CPUArchState */
+ IcountDecr *icount_decr_ptr;
+
+ /* Accessed in parallel; all accesses must be atomic */
+ struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
+
+ struct GDBRegisterState *gdb_regs;
+ int gdb_num_regs;
+ int gdb_num_g_regs;
+ QTAILQ_ENTRY(CPUState) node;
+
+ /* ice debug support */
+ QTAILQ_HEAD(, CPUBreakpoint) breakpoints;
+
+ QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
+ CPUWatchpoint *watchpoint_hit;
+
+ void *opaque;
+
+ /* In order to avoid passing too many arguments to the MMIO helpers,
+ * we store some rarely used information in the CPU context.
+ */
+ uintptr_t mem_io_pc;
+ vaddr mem_io_vaddr;
+ /*
+ * This is only needed for the legacy cpu_unassigned_access() hook;
+ * when all targets using it have been converted to use
+ * cpu_transaction_failed() instead it can be removed.
+ */
+ MMUAccessType mem_io_access_type;
+
+ int kvm_fd;
+ struct KVMState *kvm_state;
+ struct kvm_run *kvm_run;
+
+ /* Used for events with 'vcpu' and *without* the 'disabled' properties */
+ DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);
+ DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);
+
+ /* TODO Move common fields from CPUArchState here. */
+ int cpu_index;
+ int cluster_index;
+ uint32_t halted;
+ uint32_t can_do_io;
+ int32_t exception_index;
+
+ /* shared by kvm, hax and hvf */
+ bool vcpu_dirty;
+
+ /* Used to keep track of an outstanding cpu throttle thread for migration
+ * autoconverge
+ */
+ bool throttle_thread_scheduled;
+
+ bool ignore_memory_transaction_failures;
+
+ struct hax_vcpu_state *hax_vcpu;
+
+ int hvf_fd;
+
+ /* track IOMMUs whose translations we've cached in the TCG TLB */
+ GArray *iommu_notifiers;
+};
+
+typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
+extern CPUTailQ cpus;
+
+#define first_cpu QTAILQ_FIRST_RCU(&cpus)
+#define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node)
+#define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus, node)
+#define CPU_FOREACH_SAFE(cpu, next_cpu) \
+ QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus, node, next_cpu)
+
+extern __thread CPUState *current_cpu;
+
+static inline void cpu_tb_jmp_cache_clear(CPUState *cpu)
+{
+ unsigned int i;
+
+ for (i = 0; i < TB_JMP_CACHE_SIZE; i++) {
+ atomic_set(&cpu->tb_jmp_cache[i], NULL);
+ }
+}
+
+/**
+ * qemu_tcg_mttcg_enabled:
+ * Check whether we are running MultiThread TCG or not.
+ *
+ * Returns: %true if we are in MTTCG mode %false otherwise.
+ */
+extern bool mttcg_enabled;
+#define qemu_tcg_mttcg_enabled() (mttcg_enabled)
+
+/**
+ * cpu_paging_enabled:
+ * @cpu: The CPU whose state is to be inspected.
+ *
+ * Returns: %true if paging is enabled, %false otherwise.
+ */
+bool cpu_paging_enabled(const CPUState *cpu);
+
+/**
+ * cpu_get_memory_mapping:
+ * @cpu: The CPU whose memory mappings are to be obtained.
+ * @list: Where to write the memory mappings to.
+ * @errp: Pointer for reporting an #Error.
+ */
+void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
+ Error **errp);
+
+/**
+ * cpu_write_elf64_note:
+ * @f: pointer to a function that writes memory to a file
+ * @cpu: The CPU whose memory is to be dumped
+ * @cpuid: ID number of the CPU
+ * @opaque: pointer to the CPUState struct
+ */
+int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
+ int cpuid, void *opaque);
+
+/**
+ * cpu_write_elf64_qemunote:
+ * @f: pointer to a function that writes memory to a file
+ * @cpu: The CPU whose memory is to be dumped
+ * @cpuid: ID number of the CPU
+ * @opaque: pointer to the CPUState struct
+ */
+int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
+ void *opaque);
+
+/**
+ * cpu_write_elf32_note:
+ * @f: pointer to a function that writes memory to a file
+ * @cpu: The CPU whose memory is to be dumped
+ * @cpuid: ID number of the CPU
+ * @opaque: pointer to the CPUState struct
+ */
+int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
+ int cpuid, void *opaque);
+
+/**
+ * cpu_write_elf32_qemunote:
+ * @f: pointer to a function that writes memory to a file
+ * @cpu: The CPU whose memory is to be dumped
+ * @cpuid: ID number of the CPU
+ * @opaque: pointer to the CPUState struct
+ */
+int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
+ void *opaque);
+
+/**
+ * cpu_get_crash_info:
+ * @cpu: The CPU to get crash information for
+ *
+ * Gets the previously saved crash information.
+ * Caller is responsible for freeing the data.
+ */
+GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
+
+/**
+ * CPUDumpFlags:
+ * @CPU_DUMP_CODE:
+ * @CPU_DUMP_FPU: dump FPU register state, not just integer
+ * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
+ */
+enum CPUDumpFlags {
+ CPU_DUMP_CODE = 0x00010000,
+ CPU_DUMP_FPU = 0x00020000,
+ CPU_DUMP_CCOP = 0x00040000,
+};
+
+/**
+ * cpu_dump_state:
+ * @cpu: The CPU whose state is to be dumped.
+ * @f: If non-null, dump to this stream, else to current print sink.
+ *
+ * Dumps CPU state.
+ */
+void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
+
+/**
+ * cpu_dump_statistics:
+ * @cpu: The CPU whose state is to be dumped.
+ * @flags: Flags what to dump.
+ *
+ * Dump CPU statistics to the current monitor if we have one, else to
+ * stdout.
+ */
+void cpu_dump_statistics(CPUState *cpu, int flags);
+
+#ifndef CONFIG_USER_ONLY
+/**
+ * cpu_get_phys_page_attrs_debug:
+ * @cpu: The CPU to obtain the physical page address for.
+ * @addr: The virtual address.
+ * @attrs: Updated on return with the memory transaction attributes to use
+ * for this access.
+ *
+ * Obtains the physical page corresponding to a virtual one, together
+ * with the corresponding memory transaction attributes to use for the access.
+ * Use it only for debugging because no protection checks are done.
+ *
+ * Returns: Corresponding physical page address or -1 if no page found.
+ */
+static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
+ MemTxAttrs *attrs)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ if (cc->get_phys_page_attrs_debug) {
+ return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
+ }
+ /* Fallback for CPUs which don't implement the _attrs_ hook */
+ *attrs = MEMTXATTRS_UNSPECIFIED;
+ return cc->get_phys_page_debug(cpu, addr);
+}
+
+/**
+ * cpu_get_phys_page_debug:
+ * @cpu: The CPU to obtain the physical page address for.
+ * @addr: The virtual address.
+ *
+ * Obtains the physical page corresponding to a virtual one.
+ * Use it only for debugging because no protection checks are done.
+ *
+ * Returns: Corresponding physical page address or -1 if no page found.
+ */
+static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
+{
+ MemTxAttrs attrs = {};
+
+ return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
+}
+
+/** cpu_asidx_from_attrs:
+ * @cpu: CPU
+ * @attrs: memory transaction attributes
+ *
+ * Returns the address space index specifying the CPU AddressSpace
+ * to use for a memory access with the given transaction attributes.
+ */
+static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ int ret = 0;
+
+ if (cc->asidx_from_attrs) {
+ ret = cc->asidx_from_attrs(cpu, attrs);
+ assert(ret < cpu->num_ases && ret >= 0);
+ }
+ return ret;
+}
+#endif
+
+/**
+ * cpu_list_add:
+ * @cpu: The CPU to be added to the list of CPUs.
+ */
+void cpu_list_add(CPUState *cpu);
+
+/**
+ * cpu_list_remove:
+ * @cpu: The CPU to be removed from the list of CPUs.
+ */
+void cpu_list_remove(CPUState *cpu);
+
+/**
+ * cpu_reset:
+ * @cpu: The CPU whose state is to be reset.
+ */
+void cpu_reset(CPUState *cpu);
+
+/**
+ * cpu_class_by_name:
+ * @typename: The CPU base type.
+ * @cpu_model: The model string without any parameters.
+ *
+ * Looks up a CPU #ObjectClass matching name @cpu_model.
+ *
+ * Returns: A #CPUClass or %NULL if not matching class is found.
+ */
+ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
+
+/**
+ * cpu_create:
+ * @typename: The CPU type.
+ *
+ * Instantiates a CPU and realizes the CPU.
+ *
+ * Returns: A #CPUState or %NULL if an error occurred.
+ */
+CPUState *cpu_create(const char *typename);
+
+/**
+ * parse_cpu_option:
+ * @cpu_option: The -cpu option including optional parameters.
+ *
+ * processes optional parameters and registers them as global properties
+ *
+ * Returns: type of CPU to create or prints error and terminates process
+ * if an error occurred.
+ */
+const char *parse_cpu_option(const char *cpu_option);
+
+/**
+ * cpu_has_work:
+ * @cpu: The vCPU to check.
+ *
+ * Checks whether the CPU has work to do.
+ *
+ * Returns: %true if the CPU has work, %false otherwise.
+ */
+static inline bool cpu_has_work(CPUState *cpu)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ g_assert(cc->has_work);
+ return cc->has_work(cpu);
+}
+
+/**
+ * qemu_cpu_is_self:
+ * @cpu: The vCPU to check against.
+ *
+ * Checks whether the caller is executing on the vCPU thread.
+ *
+ * Returns: %true if called from @cpu's thread, %false otherwise.
+ */
+bool qemu_cpu_is_self(CPUState *cpu);
+
+/**
+ * qemu_cpu_kick:
+ * @cpu: The vCPU to kick.
+ *
+ * Kicks @cpu's thread.
+ */
+void qemu_cpu_kick(CPUState *cpu);
+
+/**
+ * cpu_is_stopped:
+ * @cpu: The CPU to check.
+ *
+ * Checks whether the CPU is stopped.
+ *
+ * Returns: %true if run state is not running or if artificially stopped;
+ * %false otherwise.
+ */
+bool cpu_is_stopped(CPUState *cpu);
+
+/**
+ * do_run_on_cpu:
+ * @cpu: The vCPU to run on.
+ * @func: The function to be executed.
+ * @data: Data to pass to the function.
+ * @mutex: Mutex to release while waiting for @func to run.
+ *
+ * Used internally in the implementation of run_on_cpu.
+ */
+void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
+ QemuMutex *mutex);
+
+/**
+ * run_on_cpu:
+ * @cpu: The vCPU to run on.
+ * @func: The function to be executed.
+ * @data: Data to pass to the function.
+ *
+ * Schedules the function @func for execution on the vCPU @cpu.
+ */
+void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
+
+/**
+ * async_run_on_cpu:
+ * @cpu: The vCPU to run on.
+ * @func: The function to be executed.
+ * @data: Data to pass to the function.
+ *
+ * Schedules the function @func for execution on the vCPU @cpu asynchronously.
+ */
+void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
+
+/**
+ * async_safe_run_on_cpu:
+ * @cpu: The vCPU to run on.
+ * @func: The function to be executed.
+ * @data: Data to pass to the function.
+ *
+ * Schedules the function @func for execution on the vCPU @cpu asynchronously,
+ * while all other vCPUs are sleeping.
+ *
+ * Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
+ * BQL.
+ */
+void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
+
+/**
+ * qemu_get_cpu:
+ * @index: The CPUState@cpu_index value of the CPU to obtain.
+ *
+ * Gets a CPU matching @index.
+ *
+ * Returns: The CPU or %NULL if there is no matching CPU.
+ */
+CPUState *qemu_get_cpu(int index);
+
+/**
+ * cpu_exists:
+ * @id: Guest-exposed CPU ID to lookup.
+ *
+ * Search for CPU with specified ID.
+ *
+ * Returns: %true - CPU is found, %false - CPU isn't found.
+ */
+bool cpu_exists(int64_t id);
+
+/**
+ * cpu_by_arch_id:
+ * @id: Guest-exposed CPU ID of the CPU to obtain.
+ *
+ * Get a CPU with matching @id.
+ *
+ * Returns: The CPU or %NULL if there is no matching CPU.
+ */
+CPUState *cpu_by_arch_id(int64_t id);
+
+/**
+ * cpu_throttle_set:
+ * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
+ *
+ * Throttles all vcpus by forcing them to sleep for the given percentage of
+ * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
+ * (example: 10ms sleep for every 30ms awake).
+ *
+ * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
+ * Once the throttling starts, it will remain in effect until cpu_throttle_stop
+ * is called.
+ */
+void cpu_throttle_set(int new_throttle_pct);
+
+/**
+ * cpu_throttle_stop:
+ *
+ * Stops the vcpu throttling started by cpu_throttle_set.
+ */
+void cpu_throttle_stop(void);
+
+/**
+ * cpu_throttle_active:
+ *
+ * Returns: %true if the vcpus are currently being throttled, %false otherwise.
+ */
+bool cpu_throttle_active(void);
+
+/**
+ * cpu_throttle_get_percentage:
+ *
+ * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
+ *
+ * Returns: The throttle percentage in range 1 to 99.
+ */
+int cpu_throttle_get_percentage(void);
+
+#ifndef CONFIG_USER_ONLY
+
+typedef void (*CPUInterruptHandler)(CPUState *, int);
+
+extern CPUInterruptHandler cpu_interrupt_handler;
+
+/**
+ * cpu_interrupt:
+ * @cpu: The CPU to set an interrupt on.
+ * @mask: The interrupts to set.
+ *
+ * Invokes the interrupt handler.
+ */
+static inline void cpu_interrupt(CPUState *cpu, int mask)
+{
+ cpu_interrupt_handler(cpu, mask);
+}
+
+#else /* USER_ONLY */
+
+void cpu_interrupt(CPUState *cpu, int mask);
+
+#endif /* USER_ONLY */
+
+#ifdef NEED_CPU_H
+
+#ifdef CONFIG_SOFTMMU
+static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
+ bool is_write, bool is_exec,
+ int opaque, unsigned size)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ if (cc->do_unassigned_access) {
+ cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
+ }
+}
+
+static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
+ MMUAccessType access_type,
+ int mmu_idx, uintptr_t retaddr)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ cc->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr);
+}
+
+static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr,
+ vaddr addr, unsigned size,
+ MMUAccessType access_type,
+ int mmu_idx, MemTxAttrs attrs,
+ MemTxResult response,
+ uintptr_t retaddr)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ if (!cpu->ignore_memory_transaction_failures && cc->do_transaction_failed) {
+ cc->do_transaction_failed(cpu, physaddr, addr, size, access_type,
+ mmu_idx, attrs, response, retaddr);
+ }
+}
+#endif
+
+#endif /* NEED_CPU_H */
+
+/**
+ * cpu_set_pc:
+ * @cpu: The CPU to set the program counter for.
+ * @addr: Program counter value.
+ *
+ * Sets the program counter for a CPU.
+ */
+static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ cc->set_pc(cpu, addr);
+}
+
+/**
+ * cpu_reset_interrupt:
+ * @cpu: The CPU to clear the interrupt on.
+ * @mask: The interrupt mask to clear.
+ *
+ * Resets interrupts on the vCPU @cpu.
+ */
+void cpu_reset_interrupt(CPUState *cpu, int mask);
+
+/**
+ * cpu_exit:
+ * @cpu: The CPU to exit.
+ *
+ * Requests the CPU @cpu to exit execution.
+ */
+void cpu_exit(CPUState *cpu);
+
+/**
+ * cpu_resume:
+ * @cpu: The CPU to resume.
+ *
+ * Resumes CPU, i.e. puts CPU into runnable state.
+ */
+void cpu_resume(CPUState *cpu);
+
+/**
+ * cpu_remove:
+ * @cpu: The CPU to remove.
+ *
+ * Requests the CPU to be removed.
+ */
+void cpu_remove(CPUState *cpu);
+
+ /**
+ * cpu_remove_sync:
+ * @cpu: The CPU to remove.
+ *
+ * Requests the CPU to be removed and waits till it is removed.
+ */
+void cpu_remove_sync(CPUState *cpu);
+
+/**
+ * process_queued_cpu_work() - process all items on CPU work queue
+ * @cpu: The CPU which work queue to process.
+ */
+void process_queued_cpu_work(CPUState *cpu);
+
+/**
+ * cpu_exec_start:
+ * @cpu: The CPU for the current thread.
+ *
+ * Record that a CPU has started execution and can be interrupted with
+ * cpu_exit.
+ */
+void cpu_exec_start(CPUState *cpu);
+
+/**
+ * cpu_exec_end:
+ * @cpu: The CPU for the current thread.
+ *
+ * Record that a CPU has stopped execution and exclusive sections
+ * can be executed without interrupting it.
+ */
+void cpu_exec_end(CPUState *cpu);
+
+/**
+ * start_exclusive:
+ *
+ * Wait for a concurrent exclusive section to end, and then start
+ * a section of work that is run while other CPUs are not running
+ * between cpu_exec_start and cpu_exec_end. CPUs that are running
+ * cpu_exec are exited immediately. CPUs that call cpu_exec_start
+ * during the exclusive section go to sleep until this CPU calls
+ * end_exclusive.
+ */
+void start_exclusive(void);
+
+/**
+ * end_exclusive:
+ *
+ * Concludes an exclusive execution section started by start_exclusive.
+ */
+void end_exclusive(void);
+
+/**
+ * qemu_init_vcpu:
+ * @cpu: The vCPU to initialize.
+ *
+ * Initializes a vCPU.
+ */
+void qemu_init_vcpu(CPUState *cpu);
+
+#define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
+#define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
+#define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
+
+/**
+ * cpu_single_step:
+ * @cpu: CPU to the flags for.
+ * @enabled: Flags to enable.
+ *
+ * Enables or disables single-stepping for @cpu.
+ */
+void cpu_single_step(CPUState *cpu, int enabled);
+
+/* Breakpoint/watchpoint flags */
+#define BP_MEM_READ 0x01
+#define BP_MEM_WRITE 0x02
+#define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
+#define BP_STOP_BEFORE_ACCESS 0x04
+/* 0x08 currently unused */
+#define BP_GDB 0x10
+#define BP_CPU 0x20
+#define BP_ANY (BP_GDB | BP_CPU)
+#define BP_WATCHPOINT_HIT_READ 0x40
+#define BP_WATCHPOINT_HIT_WRITE 0x80
+#define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
+
+int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
+ CPUBreakpoint **breakpoint);
+int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
+void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
+void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
+
+/* Return true if PC matches an installed breakpoint. */
+static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
+{
+ CPUBreakpoint *bp;
+
+ if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
+ QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
+ if (bp->pc == pc && (bp->flags & mask)) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
+ int flags, CPUWatchpoint **watchpoint);
+int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
+ vaddr len, int flags);
+void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
+void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
+
+/**
+ * cpu_get_address_space:
+ * @cpu: CPU to get address space from
+ * @asidx: index identifying which address space to get
+ *
+ * Return the requested address space of this CPU. @asidx
+ * specifies which address space to read.
+ */
+AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
+
+void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
+ GCC_FMT_ATTR(2, 3);
+extern Property cpu_common_props[];
+void cpu_exec_initfn(CPUState *cpu);
+void cpu_exec_realizefn(CPUState *cpu, Error **errp);
+void cpu_exec_unrealizefn(CPUState *cpu);
+
+/**
+ * target_words_bigendian:
+ * Returns true if the (default) endianness of the target is big endian,
+ * false otherwise. Note that in target-specific code, you can use
+ * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
+ * code should normally never need to know about the endianness of the
+ * target, so please do *not* use this function unless you know very well
+ * what you are doing!
+ */
+bool target_words_bigendian(void);
+
+#ifdef NEED_CPU_H
+
+#ifdef CONFIG_SOFTMMU
+extern const VMStateDescription vmstate_cpu_common;
+#else
+#define vmstate_cpu_common vmstate_dummy
+#endif
+
+#define VMSTATE_CPU() { \
+ .name = "parent_obj", \
+ .size = sizeof(CPUState), \
+ .vmsd = &vmstate_cpu_common, \
+ .flags = VMS_STRUCT, \
+ .offset = 0, \
+}
+
+#endif /* NEED_CPU_H */
+
+#define UNASSIGNED_CPU_INDEX -1
+#define UNASSIGNED_CLUSTER_INDEX -1
+
+#endif
#define OPENPIC_H
#include "hw/sysbus.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define MAX_CPU 32
#define MAX_MSI 8
extern const PropertyInfo qdev_prop_pci_host_devaddr;
extern const PropertyInfo qdev_prop_uuid;
extern const PropertyInfo qdev_prop_arraylen;
+extern const PropertyInfo qdev_prop_audiodev;
extern const PropertyInfo qdev_prop_link;
extern const PropertyInfo qdev_prop_off_auto_pcibar;
extern const PropertyInfo qdev_prop_pcie_link_speed;
+ type_check(QemuUUID, typeof_field(_state, _field)), \
.set_default = true, \
}
+#define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
+ DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
#define DEFINE_PROP_END_OF_LIST() \
{}
+++ /dev/null
-/*
- * QEMU CPU model
- *
- * Copyright (c) 2012 SUSE LINUX Products GmbH
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see
- * <http://www.gnu.org/licenses/gpl-2.0.html>
- */
-#ifndef QEMU_CPU_H
-#define QEMU_CPU_H
-
-#include "hw/qdev-core.h"
-#include "disas/dis-asm.h"
-#include "exec/hwaddr.h"
-#include "exec/memattrs.h"
-#include "qapi/qapi-types-run-state.h"
-#include "qemu/bitmap.h"
-#include "qemu/rcu_queue.h"
-#include "qemu/queue.h"
-#include "qemu/thread.h"
-
-typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
- void *opaque);
-
-/**
- * vaddr:
- * Type wide enough to contain any #target_ulong virtual address.
- */
-typedef uint64_t vaddr;
-#define VADDR_PRId PRId64
-#define VADDR_PRIu PRIu64
-#define VADDR_PRIo PRIo64
-#define VADDR_PRIx PRIx64
-#define VADDR_PRIX PRIX64
-#define VADDR_MAX UINT64_MAX
-
-/**
- * SECTION:cpu
- * @section_id: QEMU-cpu
- * @title: CPU Class
- * @short_description: Base class for all CPUs
- */
-
-#define TYPE_CPU "cpu"
-
-/* Since this macro is used a lot in hot code paths and in conjunction with
- * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
- * an unchecked cast.
- */
-#define CPU(obj) ((CPUState *)(obj))
-
-#define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
-#define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
-
-typedef enum MMUAccessType {
- MMU_DATA_LOAD = 0,
- MMU_DATA_STORE = 1,
- MMU_INST_FETCH = 2
-} MMUAccessType;
-
-typedef struct CPUWatchpoint CPUWatchpoint;
-
-typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
- bool is_write, bool is_exec, int opaque,
- unsigned size);
-
-struct TranslationBlock;
-
-/**
- * CPUClass:
- * @class_by_name: Callback to map -cpu command line model name to an
- * instantiatable CPU type.
- * @parse_features: Callback to parse command line arguments.
- * @reset: Callback to reset the #CPUState to its initial state.
- * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
- * @has_work: Callback for checking if there is work to do.
- * @do_interrupt: Callback for interrupt handling.
- * @do_unassigned_access: Callback for unassigned access handling.
- * (this is deprecated: new targets should use do_transaction_failed instead)
- * @do_unaligned_access: Callback for unaligned access handling, if
- * the target defines #TARGET_ALIGNED_ONLY.
- * @do_transaction_failed: Callback for handling failed memory transactions
- * (ie bus faults or external aborts; not MMU faults)
- * @virtio_is_big_endian: Callback to return %true if a CPU which supports
- * runtime configurable endianness is currently big-endian. Non-configurable
- * CPUs can use the default implementation of this method. This method should
- * not be used by any callers other than the pre-1.0 virtio devices.
- * @memory_rw_debug: Callback for GDB memory access.
- * @dump_state: Callback for dumping state.
- * @dump_statistics: Callback for dumping statistics.
- * @get_arch_id: Callback for getting architecture-dependent CPU ID.
- * @get_paging_enabled: Callback for inquiring whether paging is enabled.
- * @get_memory_mapping: Callback for obtaining the memory mappings.
- * @set_pc: Callback for setting the Program Counter register. This
- * should have the semantics used by the target architecture when
- * setting the PC from a source such as an ELF file entry point;
- * for example on Arm it will also set the Thumb mode bit based
- * on the least significant bit of the new PC value.
- * If the target behaviour here is anything other than "set
- * the PC register to the value passed in" then the target must
- * also implement the synchronize_from_tb hook.
- * @synchronize_from_tb: Callback for synchronizing state from a TCG
- * #TranslationBlock. This is called when we abandon execution
- * of a TB before starting it, and must set all parts of the CPU
- * state which the previous TB in the chain may not have updated.
- * This always includes at least the program counter; some targets
- * will need to do more. If this hook is not implemented then the
- * default is to call @set_pc(tb->pc).
- * @tlb_fill: Callback for handling a softmmu tlb miss or user-only
- * address fault. For system mode, if the access is valid, call
- * tlb_set_page and return true; if the access is invalid, and
- * probe is true, return false; otherwise raise an exception and
- * do not return. For user-only mode, always raise an exception
- * and do not return.
- * @get_phys_page_debug: Callback for obtaining a physical address.
- * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
- * associated memory transaction attributes to use for the access.
- * CPUs which use memory transaction attributes should implement this
- * instead of get_phys_page_debug.
- * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
- * a memory access with the specified memory transaction attributes.
- * @gdb_read_register: Callback for letting GDB read a register.
- * @gdb_write_register: Callback for letting GDB write a register.
- * @debug_check_watchpoint: Callback: return true if the architectural
- * watchpoint whose address has matched should really fire.
- * @debug_excp_handler: Callback for handling debug exceptions.
- * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
- * 64-bit VM coredump.
- * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
- * note to a 32-bit VM coredump.
- * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
- * 32-bit VM coredump.
- * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
- * note to a 32-bit VM coredump.
- * @vmsd: State description for migration.
- * @gdb_num_core_regs: Number of core registers accessible to GDB.
- * @gdb_core_xml_file: File name for core registers GDB XML description.
- * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
- * before the insn which triggers a watchpoint rather than after it.
- * @gdb_arch_name: Optional callback that returns the architecture name known
- * to GDB. The caller must free the returned string with g_free.
- * @gdb_get_dynamic_xml: Callback to return dynamically generated XML for the
- * gdb stub. Returns a pointer to the XML contents for the specified XML file
- * or NULL if the CPU doesn't have a dynamically generated content for it.
- * @cpu_exec_enter: Callback for cpu_exec preparation.
- * @cpu_exec_exit: Callback for cpu_exec cleanup.
- * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
- * @disas_set_info: Setup architecture specific components of disassembly info
- * @adjust_watchpoint_address: Perform a target-specific adjustment to an
- * address before attempting to match it against watchpoints.
- *
- * Represents a CPU family or model.
- */
-typedef struct CPUClass {
- /*< private >*/
- DeviceClass parent_class;
- /*< public >*/
-
- ObjectClass *(*class_by_name)(const char *cpu_model);
- void (*parse_features)(const char *typename, char *str, Error **errp);
-
- void (*reset)(CPUState *cpu);
- int reset_dump_flags;
- bool (*has_work)(CPUState *cpu);
- void (*do_interrupt)(CPUState *cpu);
- CPUUnassignedAccess do_unassigned_access;
- void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
- MMUAccessType access_type,
- int mmu_idx, uintptr_t retaddr);
- void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
- unsigned size, MMUAccessType access_type,
- int mmu_idx, MemTxAttrs attrs,
- MemTxResult response, uintptr_t retaddr);
- bool (*virtio_is_big_endian)(CPUState *cpu);
- int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
- uint8_t *buf, int len, bool is_write);
- void (*dump_state)(CPUState *cpu, FILE *, int flags);
- GuestPanicInformation* (*get_crash_info)(CPUState *cpu);
- void (*dump_statistics)(CPUState *cpu, int flags);
- int64_t (*get_arch_id)(CPUState *cpu);
- bool (*get_paging_enabled)(const CPUState *cpu);
- void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
- Error **errp);
- void (*set_pc)(CPUState *cpu, vaddr value);
- void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
- bool (*tlb_fill)(CPUState *cpu, vaddr address, int size,
- MMUAccessType access_type, int mmu_idx,
- bool probe, uintptr_t retaddr);
- hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
- hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
- MemTxAttrs *attrs);
- int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
- int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg);
- int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
- bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
- void (*debug_excp_handler)(CPUState *cpu);
-
- int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
- int cpuid, void *opaque);
- int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
- void *opaque);
- int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
- int cpuid, void *opaque);
- int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
- void *opaque);
-
- const VMStateDescription *vmsd;
- const char *gdb_core_xml_file;
- gchar * (*gdb_arch_name)(CPUState *cpu);
- const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
- void (*cpu_exec_enter)(CPUState *cpu);
- void (*cpu_exec_exit)(CPUState *cpu);
- bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
-
- void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
- vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
- void (*tcg_initialize)(void);
-
- /* Keep non-pointer data at the end to minimize holes. */
- int gdb_num_core_regs;
- bool gdb_stop_before_watchpoint;
-} CPUClass;
-
-/*
- * Low 16 bits: number of cycles left, used only in icount mode.
- * High 16 bits: Set to -1 to force TCG to stop executing linked TBs
- * for this CPU and return to its top level loop (even in non-icount mode).
- * This allows a single read-compare-cbranch-write sequence to test
- * for both decrementer underflow and exceptions.
- */
-typedef union IcountDecr {
- uint32_t u32;
- struct {
-#ifdef HOST_WORDS_BIGENDIAN
- uint16_t high;
- uint16_t low;
-#else
- uint16_t low;
- uint16_t high;
-#endif
- } u16;
-} IcountDecr;
-
-typedef struct CPUBreakpoint {
- vaddr pc;
- int flags; /* BP_* */
- QTAILQ_ENTRY(CPUBreakpoint) entry;
-} CPUBreakpoint;
-
-struct CPUWatchpoint {
- vaddr vaddr;
- vaddr len;
- vaddr hitaddr;
- MemTxAttrs hitattrs;
- int flags; /* BP_* */
- QTAILQ_ENTRY(CPUWatchpoint) entry;
-};
-
-struct KVMState;
-struct kvm_run;
-
-struct hax_vcpu_state;
-
-#define TB_JMP_CACHE_BITS 12
-#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
-
-/* work queue */
-
-/* The union type allows passing of 64 bit target pointers on 32 bit
- * hosts in a single parameter
- */
-typedef union {
- int host_int;
- unsigned long host_ulong;
- void *host_ptr;
- vaddr target_ptr;
-} run_on_cpu_data;
-
-#define RUN_ON_CPU_HOST_PTR(p) ((run_on_cpu_data){.host_ptr = (p)})
-#define RUN_ON_CPU_HOST_INT(i) ((run_on_cpu_data){.host_int = (i)})
-#define RUN_ON_CPU_HOST_ULONG(ul) ((run_on_cpu_data){.host_ulong = (ul)})
-#define RUN_ON_CPU_TARGET_PTR(v) ((run_on_cpu_data){.target_ptr = (v)})
-#define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL)
-
-typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
-
-struct qemu_work_item;
-
-#define CPU_UNSET_NUMA_NODE_ID -1
-#define CPU_TRACE_DSTATE_MAX_EVENTS 32
-
-/**
- * CPUState:
- * @cpu_index: CPU index (informative).
- * @cluster_index: Identifies which cluster this CPU is in.
- * For boards which don't define clusters or for "loose" CPUs not assigned
- * to a cluster this will be UNASSIGNED_CLUSTER_INDEX; otherwise it will
- * be the same as the cluster-id property of the CPU object's TYPE_CPU_CLUSTER
- * QOM parent.
- * @nr_cores: Number of cores within this CPU package.
- * @nr_threads: Number of threads within this CPU.
- * @running: #true if CPU is currently running (lockless).
- * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
- * valid under cpu_list_lock.
- * @created: Indicates whether the CPU thread has been successfully created.
- * @interrupt_request: Indicates a pending interrupt request.
- * @halted: Nonzero if the CPU is in suspended state.
- * @stop: Indicates a pending stop request.
- * @stopped: Indicates the CPU has been artificially stopped.
- * @unplug: Indicates a pending CPU unplug request.
- * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
- * @singlestep_enabled: Flags for single-stepping.
- * @icount_extra: Instructions until next timer event.
- * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
- * requires that IO only be performed on the last instruction of a TB
- * so that interrupts take effect immediately.
- * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
- * AddressSpaces this CPU has)
- * @num_ases: number of CPUAddressSpaces in @cpu_ases
- * @as: Pointer to the first AddressSpace, for the convenience of targets which
- * only have a single AddressSpace
- * @env_ptr: Pointer to subclass-specific CPUArchState field.
- * @icount_decr_ptr: Pointer to IcountDecr field within subclass.
- * @gdb_regs: Additional GDB registers.
- * @gdb_num_regs: Number of total registers accessible to GDB.
- * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
- * @next_cpu: Next CPU sharing TB cache.
- * @opaque: User data.
- * @mem_io_pc: Host Program Counter at which the memory was accessed.
- * @mem_io_vaddr: Target virtual address at which the memory was accessed.
- * @kvm_fd: vCPU file descriptor for KVM.
- * @work_mutex: Lock to prevent multiple access to queued_work_*.
- * @queued_work_first: First asynchronous work pending.
- * @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes
- * to @trace_dstate).
- * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
- * @ignore_memory_transaction_failures: Cached copy of the MachineState
- * flag of the same name: allows the board to suppress calling of the
- * CPU do_transaction_failed hook function.
- *
- * State of one CPU core or thread.
- */
-struct CPUState {
- /*< private >*/
- DeviceState parent_obj;
- /*< public >*/
-
- int nr_cores;
- int nr_threads;
-
- struct QemuThread *thread;
-#ifdef _WIN32
- HANDLE hThread;
-#endif
- int thread_id;
- bool running, has_waiter;
- struct QemuCond *halt_cond;
- bool thread_kicked;
- bool created;
- bool stop;
- bool stopped;
- bool unplug;
- bool crash_occurred;
- bool exit_request;
- uint32_t cflags_next_tb;
- /* updates protected by BQL */
- uint32_t interrupt_request;
- int singlestep_enabled;
- int64_t icount_budget;
- int64_t icount_extra;
- uint64_t random_seed;
- sigjmp_buf jmp_env;
-
- QemuMutex work_mutex;
- struct qemu_work_item *queued_work_first, *queued_work_last;
-
- CPUAddressSpace *cpu_ases;
- int num_ases;
- AddressSpace *as;
- MemoryRegion *memory;
-
- void *env_ptr; /* CPUArchState */
- IcountDecr *icount_decr_ptr;
-
- /* Accessed in parallel; all accesses must be atomic */
- struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
-
- struct GDBRegisterState *gdb_regs;
- int gdb_num_regs;
- int gdb_num_g_regs;
- QTAILQ_ENTRY(CPUState) node;
-
- /* ice debug support */
- QTAILQ_HEAD(, CPUBreakpoint) breakpoints;
-
- QTAILQ_HEAD(, CPUWatchpoint) watchpoints;
- CPUWatchpoint *watchpoint_hit;
-
- void *opaque;
-
- /* In order to avoid passing too many arguments to the MMIO helpers,
- * we store some rarely used information in the CPU context.
- */
- uintptr_t mem_io_pc;
- vaddr mem_io_vaddr;
- /*
- * This is only needed for the legacy cpu_unassigned_access() hook;
- * when all targets using it have been converted to use
- * cpu_transaction_failed() instead it can be removed.
- */
- MMUAccessType mem_io_access_type;
-
- int kvm_fd;
- struct KVMState *kvm_state;
- struct kvm_run *kvm_run;
-
- /* Used for events with 'vcpu' and *without* the 'disabled' properties */
- DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);
- DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);
-
- /* TODO Move common fields from CPUArchState here. */
- int cpu_index;
- int cluster_index;
- uint32_t halted;
- uint32_t can_do_io;
- int32_t exception_index;
-
- /* shared by kvm, hax and hvf */
- bool vcpu_dirty;
-
- /* Used to keep track of an outstanding cpu throttle thread for migration
- * autoconverge
- */
- bool throttle_thread_scheduled;
-
- bool ignore_memory_transaction_failures;
-
- struct hax_vcpu_state *hax_vcpu;
-
- int hvf_fd;
-
- /* track IOMMUs whose translations we've cached in the TCG TLB */
- GArray *iommu_notifiers;
-};
-
-typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
-extern CPUTailQ cpus;
-
-#define first_cpu QTAILQ_FIRST_RCU(&cpus)
-#define CPU_NEXT(cpu) QTAILQ_NEXT_RCU(cpu, node)
-#define CPU_FOREACH(cpu) QTAILQ_FOREACH_RCU(cpu, &cpus, node)
-#define CPU_FOREACH_SAFE(cpu, next_cpu) \
- QTAILQ_FOREACH_SAFE_RCU(cpu, &cpus, node, next_cpu)
-
-extern __thread CPUState *current_cpu;
-
-static inline void cpu_tb_jmp_cache_clear(CPUState *cpu)
-{
- unsigned int i;
-
- for (i = 0; i < TB_JMP_CACHE_SIZE; i++) {
- atomic_set(&cpu->tb_jmp_cache[i], NULL);
- }
-}
-
-/**
- * qemu_tcg_mttcg_enabled:
- * Check whether we are running MultiThread TCG or not.
- *
- * Returns: %true if we are in MTTCG mode %false otherwise.
- */
-extern bool mttcg_enabled;
-#define qemu_tcg_mttcg_enabled() (mttcg_enabled)
-
-/**
- * cpu_paging_enabled:
- * @cpu: The CPU whose state is to be inspected.
- *
- * Returns: %true if paging is enabled, %false otherwise.
- */
-bool cpu_paging_enabled(const CPUState *cpu);
-
-/**
- * cpu_get_memory_mapping:
- * @cpu: The CPU whose memory mappings are to be obtained.
- * @list: Where to write the memory mappings to.
- * @errp: Pointer for reporting an #Error.
- */
-void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
- Error **errp);
-
-/**
- * cpu_write_elf64_note:
- * @f: pointer to a function that writes memory to a file
- * @cpu: The CPU whose memory is to be dumped
- * @cpuid: ID number of the CPU
- * @opaque: pointer to the CPUState struct
- */
-int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
- int cpuid, void *opaque);
-
-/**
- * cpu_write_elf64_qemunote:
- * @f: pointer to a function that writes memory to a file
- * @cpu: The CPU whose memory is to be dumped
- * @cpuid: ID number of the CPU
- * @opaque: pointer to the CPUState struct
- */
-int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
- void *opaque);
-
-/**
- * cpu_write_elf32_note:
- * @f: pointer to a function that writes memory to a file
- * @cpu: The CPU whose memory is to be dumped
- * @cpuid: ID number of the CPU
- * @opaque: pointer to the CPUState struct
- */
-int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
- int cpuid, void *opaque);
-
-/**
- * cpu_write_elf32_qemunote:
- * @f: pointer to a function that writes memory to a file
- * @cpu: The CPU whose memory is to be dumped
- * @cpuid: ID number of the CPU
- * @opaque: pointer to the CPUState struct
- */
-int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
- void *opaque);
-
-/**
- * cpu_get_crash_info:
- * @cpu: The CPU to get crash information for
- *
- * Gets the previously saved crash information.
- * Caller is responsible for freeing the data.
- */
-GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
-
-/**
- * CPUDumpFlags:
- * @CPU_DUMP_CODE:
- * @CPU_DUMP_FPU: dump FPU register state, not just integer
- * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
- */
-enum CPUDumpFlags {
- CPU_DUMP_CODE = 0x00010000,
- CPU_DUMP_FPU = 0x00020000,
- CPU_DUMP_CCOP = 0x00040000,
-};
-
-/**
- * cpu_dump_state:
- * @cpu: The CPU whose state is to be dumped.
- * @f: If non-null, dump to this stream, else to current print sink.
- *
- * Dumps CPU state.
- */
-void cpu_dump_state(CPUState *cpu, FILE *f, int flags);
-
-/**
- * cpu_dump_statistics:
- * @cpu: The CPU whose state is to be dumped.
- * @flags: Flags what to dump.
- *
- * Dump CPU statistics to the current monitor if we have one, else to
- * stdout.
- */
-void cpu_dump_statistics(CPUState *cpu, int flags);
-
-#ifndef CONFIG_USER_ONLY
-/**
- * cpu_get_phys_page_attrs_debug:
- * @cpu: The CPU to obtain the physical page address for.
- * @addr: The virtual address.
- * @attrs: Updated on return with the memory transaction attributes to use
- * for this access.
- *
- * Obtains the physical page corresponding to a virtual one, together
- * with the corresponding memory transaction attributes to use for the access.
- * Use it only for debugging because no protection checks are done.
- *
- * Returns: Corresponding physical page address or -1 if no page found.
- */
-static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
- MemTxAttrs *attrs)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- if (cc->get_phys_page_attrs_debug) {
- return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
- }
- /* Fallback for CPUs which don't implement the _attrs_ hook */
- *attrs = MEMTXATTRS_UNSPECIFIED;
- return cc->get_phys_page_debug(cpu, addr);
-}
-
-/**
- * cpu_get_phys_page_debug:
- * @cpu: The CPU to obtain the physical page address for.
- * @addr: The virtual address.
- *
- * Obtains the physical page corresponding to a virtual one.
- * Use it only for debugging because no protection checks are done.
- *
- * Returns: Corresponding physical page address or -1 if no page found.
- */
-static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
-{
- MemTxAttrs attrs = {};
-
- return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
-}
-
-/** cpu_asidx_from_attrs:
- * @cpu: CPU
- * @attrs: memory transaction attributes
- *
- * Returns the address space index specifying the CPU AddressSpace
- * to use for a memory access with the given transaction attributes.
- */
-static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
- int ret = 0;
-
- if (cc->asidx_from_attrs) {
- ret = cc->asidx_from_attrs(cpu, attrs);
- assert(ret < cpu->num_ases && ret >= 0);
- }
- return ret;
-}
-#endif
-
-/**
- * cpu_list_add:
- * @cpu: The CPU to be added to the list of CPUs.
- */
-void cpu_list_add(CPUState *cpu);
-
-/**
- * cpu_list_remove:
- * @cpu: The CPU to be removed from the list of CPUs.
- */
-void cpu_list_remove(CPUState *cpu);
-
-/**
- * cpu_reset:
- * @cpu: The CPU whose state is to be reset.
- */
-void cpu_reset(CPUState *cpu);
-
-/**
- * cpu_class_by_name:
- * @typename: The CPU base type.
- * @cpu_model: The model string without any parameters.
- *
- * Looks up a CPU #ObjectClass matching name @cpu_model.
- *
- * Returns: A #CPUClass or %NULL if not matching class is found.
- */
-ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
-
-/**
- * cpu_create:
- * @typename: The CPU type.
- *
- * Instantiates a CPU and realizes the CPU.
- *
- * Returns: A #CPUState or %NULL if an error occurred.
- */
-CPUState *cpu_create(const char *typename);
-
-/**
- * parse_cpu_option:
- * @cpu_option: The -cpu option including optional parameters.
- *
- * processes optional parameters and registers them as global properties
- *
- * Returns: type of CPU to create or prints error and terminates process
- * if an error occurred.
- */
-const char *parse_cpu_option(const char *cpu_option);
-
-/**
- * cpu_has_work:
- * @cpu: The vCPU to check.
- *
- * Checks whether the CPU has work to do.
- *
- * Returns: %true if the CPU has work, %false otherwise.
- */
-static inline bool cpu_has_work(CPUState *cpu)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- g_assert(cc->has_work);
- return cc->has_work(cpu);
-}
-
-/**
- * qemu_cpu_is_self:
- * @cpu: The vCPU to check against.
- *
- * Checks whether the caller is executing on the vCPU thread.
- *
- * Returns: %true if called from @cpu's thread, %false otherwise.
- */
-bool qemu_cpu_is_self(CPUState *cpu);
-
-/**
- * qemu_cpu_kick:
- * @cpu: The vCPU to kick.
- *
- * Kicks @cpu's thread.
- */
-void qemu_cpu_kick(CPUState *cpu);
-
-/**
- * cpu_is_stopped:
- * @cpu: The CPU to check.
- *
- * Checks whether the CPU is stopped.
- *
- * Returns: %true if run state is not running or if artificially stopped;
- * %false otherwise.
- */
-bool cpu_is_stopped(CPUState *cpu);
-
-/**
- * do_run_on_cpu:
- * @cpu: The vCPU to run on.
- * @func: The function to be executed.
- * @data: Data to pass to the function.
- * @mutex: Mutex to release while waiting for @func to run.
- *
- * Used internally in the implementation of run_on_cpu.
- */
-void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
- QemuMutex *mutex);
-
-/**
- * run_on_cpu:
- * @cpu: The vCPU to run on.
- * @func: The function to be executed.
- * @data: Data to pass to the function.
- *
- * Schedules the function @func for execution on the vCPU @cpu.
- */
-void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
-
-/**
- * async_run_on_cpu:
- * @cpu: The vCPU to run on.
- * @func: The function to be executed.
- * @data: Data to pass to the function.
- *
- * Schedules the function @func for execution on the vCPU @cpu asynchronously.
- */
-void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
-
-/**
- * async_safe_run_on_cpu:
- * @cpu: The vCPU to run on.
- * @func: The function to be executed.
- * @data: Data to pass to the function.
- *
- * Schedules the function @func for execution on the vCPU @cpu asynchronously,
- * while all other vCPUs are sleeping.
- *
- * Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
- * BQL.
- */
-void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
-
-/**
- * qemu_get_cpu:
- * @index: The CPUState@cpu_index value of the CPU to obtain.
- *
- * Gets a CPU matching @index.
- *
- * Returns: The CPU or %NULL if there is no matching CPU.
- */
-CPUState *qemu_get_cpu(int index);
-
-/**
- * cpu_exists:
- * @id: Guest-exposed CPU ID to lookup.
- *
- * Search for CPU with specified ID.
- *
- * Returns: %true - CPU is found, %false - CPU isn't found.
- */
-bool cpu_exists(int64_t id);
-
-/**
- * cpu_by_arch_id:
- * @id: Guest-exposed CPU ID of the CPU to obtain.
- *
- * Get a CPU with matching @id.
- *
- * Returns: The CPU or %NULL if there is no matching CPU.
- */
-CPUState *cpu_by_arch_id(int64_t id);
-
-/**
- * cpu_throttle_set:
- * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
- *
- * Throttles all vcpus by forcing them to sleep for the given percentage of
- * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
- * (example: 10ms sleep for every 30ms awake).
- *
- * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
- * Once the throttling starts, it will remain in effect until cpu_throttle_stop
- * is called.
- */
-void cpu_throttle_set(int new_throttle_pct);
-
-/**
- * cpu_throttle_stop:
- *
- * Stops the vcpu throttling started by cpu_throttle_set.
- */
-void cpu_throttle_stop(void);
-
-/**
- * cpu_throttle_active:
- *
- * Returns: %true if the vcpus are currently being throttled, %false otherwise.
- */
-bool cpu_throttle_active(void);
-
-/**
- * cpu_throttle_get_percentage:
- *
- * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
- *
- * Returns: The throttle percentage in range 1 to 99.
- */
-int cpu_throttle_get_percentage(void);
-
-#ifndef CONFIG_USER_ONLY
-
-typedef void (*CPUInterruptHandler)(CPUState *, int);
-
-extern CPUInterruptHandler cpu_interrupt_handler;
-
-/**
- * cpu_interrupt:
- * @cpu: The CPU to set an interrupt on.
- * @mask: The interrupts to set.
- *
- * Invokes the interrupt handler.
- */
-static inline void cpu_interrupt(CPUState *cpu, int mask)
-{
- cpu_interrupt_handler(cpu, mask);
-}
-
-#else /* USER_ONLY */
-
-void cpu_interrupt(CPUState *cpu, int mask);
-
-#endif /* USER_ONLY */
-
-#ifdef NEED_CPU_H
-
-#ifdef CONFIG_SOFTMMU
-static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
- bool is_write, bool is_exec,
- int opaque, unsigned size)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- if (cc->do_unassigned_access) {
- cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
- }
-}
-
-static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
- MMUAccessType access_type,
- int mmu_idx, uintptr_t retaddr)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- cc->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr);
-}
-
-static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr,
- vaddr addr, unsigned size,
- MMUAccessType access_type,
- int mmu_idx, MemTxAttrs attrs,
- MemTxResult response,
- uintptr_t retaddr)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- if (!cpu->ignore_memory_transaction_failures && cc->do_transaction_failed) {
- cc->do_transaction_failed(cpu, physaddr, addr, size, access_type,
- mmu_idx, attrs, response, retaddr);
- }
-}
-#endif
-
-#endif /* NEED_CPU_H */
-
-/**
- * cpu_set_pc:
- * @cpu: The CPU to set the program counter for.
- * @addr: Program counter value.
- *
- * Sets the program counter for a CPU.
- */
-static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- cc->set_pc(cpu, addr);
-}
-
-/**
- * cpu_reset_interrupt:
- * @cpu: The CPU to clear the interrupt on.
- * @mask: The interrupt mask to clear.
- *
- * Resets interrupts on the vCPU @cpu.
- */
-void cpu_reset_interrupt(CPUState *cpu, int mask);
-
-/**
- * cpu_exit:
- * @cpu: The CPU to exit.
- *
- * Requests the CPU @cpu to exit execution.
- */
-void cpu_exit(CPUState *cpu);
-
-/**
- * cpu_resume:
- * @cpu: The CPU to resume.
- *
- * Resumes CPU, i.e. puts CPU into runnable state.
- */
-void cpu_resume(CPUState *cpu);
-
-/**
- * cpu_remove:
- * @cpu: The CPU to remove.
- *
- * Requests the CPU to be removed.
- */
-void cpu_remove(CPUState *cpu);
-
- /**
- * cpu_remove_sync:
- * @cpu: The CPU to remove.
- *
- * Requests the CPU to be removed and waits till it is removed.
- */
-void cpu_remove_sync(CPUState *cpu);
-
-/**
- * process_queued_cpu_work() - process all items on CPU work queue
- * @cpu: The CPU which work queue to process.
- */
-void process_queued_cpu_work(CPUState *cpu);
-
-/**
- * cpu_exec_start:
- * @cpu: The CPU for the current thread.
- *
- * Record that a CPU has started execution and can be interrupted with
- * cpu_exit.
- */
-void cpu_exec_start(CPUState *cpu);
-
-/**
- * cpu_exec_end:
- * @cpu: The CPU for the current thread.
- *
- * Record that a CPU has stopped execution and exclusive sections
- * can be executed without interrupting it.
- */
-void cpu_exec_end(CPUState *cpu);
-
-/**
- * start_exclusive:
- *
- * Wait for a concurrent exclusive section to end, and then start
- * a section of work that is run while other CPUs are not running
- * between cpu_exec_start and cpu_exec_end. CPUs that are running
- * cpu_exec are exited immediately. CPUs that call cpu_exec_start
- * during the exclusive section go to sleep until this CPU calls
- * end_exclusive.
- */
-void start_exclusive(void);
-
-/**
- * end_exclusive:
- *
- * Concludes an exclusive execution section started by start_exclusive.
- */
-void end_exclusive(void);
-
-/**
- * qemu_init_vcpu:
- * @cpu: The vCPU to initialize.
- *
- * Initializes a vCPU.
- */
-void qemu_init_vcpu(CPUState *cpu);
-
-#define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
-#define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
-#define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
-
-/**
- * cpu_single_step:
- * @cpu: CPU to the flags for.
- * @enabled: Flags to enable.
- *
- * Enables or disables single-stepping for @cpu.
- */
-void cpu_single_step(CPUState *cpu, int enabled);
-
-/* Breakpoint/watchpoint flags */
-#define BP_MEM_READ 0x01
-#define BP_MEM_WRITE 0x02
-#define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
-#define BP_STOP_BEFORE_ACCESS 0x04
-/* 0x08 currently unused */
-#define BP_GDB 0x10
-#define BP_CPU 0x20
-#define BP_ANY (BP_GDB | BP_CPU)
-#define BP_WATCHPOINT_HIT_READ 0x40
-#define BP_WATCHPOINT_HIT_WRITE 0x80
-#define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
-
-int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
- CPUBreakpoint **breakpoint);
-int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
-void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
-void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
-
-/* Return true if PC matches an installed breakpoint. */
-static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
-{
- CPUBreakpoint *bp;
-
- if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
- QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
- if (bp->pc == pc && (bp->flags & mask)) {
- return true;
- }
- }
- }
- return false;
-}
-
-int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
- int flags, CPUWatchpoint **watchpoint);
-int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
- vaddr len, int flags);
-void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
-void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
-
-/**
- * cpu_get_address_space:
- * @cpu: CPU to get address space from
- * @asidx: index identifying which address space to get
- *
- * Return the requested address space of this CPU. @asidx
- * specifies which address space to read.
- */
-AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
-
-void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
- GCC_FMT_ATTR(2, 3);
-extern Property cpu_common_props[];
-void cpu_exec_initfn(CPUState *cpu);
-void cpu_exec_realizefn(CPUState *cpu, Error **errp);
-void cpu_exec_unrealizefn(CPUState *cpu);
-
-/**
- * target_words_bigendian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Note that in target-specific code, you can use
- * TARGET_WORDS_BIGENDIAN directly instead. On the other hand, common
- * code should normally never need to know about the endianness of the
- * target, so please do *not* use this function unless you know very well
- * what you are doing!
- */
-bool target_words_bigendian(void);
-
-#ifdef NEED_CPU_H
-
-#ifdef CONFIG_SOFTMMU
-extern const VMStateDescription vmstate_cpu_common;
-#else
-#define vmstate_cpu_common vmstate_dummy
-#endif
-
-#define VMSTATE_CPU() { \
- .name = "parent_obj", \
- .size = sizeof(CPUState), \
- .vmsd = &vmstate_cpu_common, \
- .flags = VMS_STRUCT, \
- .offset = 0, \
-}
-
-#endif /* NEED_CPU_H */
-
-#define UNASSIGNED_CPU_INDEX -1
-#define UNASSIGNED_CLUSTER_INDEX -1
-
-#endif
#ifndef QEMU_HW_ACCEL_H
#define QEMU_HW_ACCEL_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "sysemu/hax.h"
#include "sysemu/kvm.h"
#include "sysemu/whpx.h"
#define QEMU_KVM_H
#include "qemu/queue.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "exec/memattrs.h"
#ifdef NEED_CPU_H
/* Audio */
/*! Saves/restores number of played samples of audio out operation. */
-void replay_audio_out(int *played);
+void replay_audio_out(size_t *played);
/*! Saves/restores recorded samples of audio in operation. */
-void replay_audio_in(int *recorded, void *samples, int *wpos, int size);
+void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);
/* VM state operations */
#include "qemu/timer.h"
#include "qemu/sockets.h"
#include "monitor/monitor-internal.h"
-#include "monitor/qdev.h"
#include "qapi/error.h"
#include "qapi/clone-visitor.h"
#include "qapi/opts-visitor.h"
#include "qapi/qapi-commands-migration.h"
#include "qapi/qapi-commands-misc.h"
#include "qapi/qapi-commands-net.h"
-#include "qapi/qapi-commands-qdev.h"
#include "qapi/qapi-commands-rocker.h"
#include "qapi/qapi-commands-run-state.h"
#include "qapi/qapi-commands-tpm.h"
}
}
-void hmp_device_add(Monitor *mon, const QDict *qdict)
-{
- Error *err = NULL;
-
- qmp_device_add((QDict *)qdict, NULL, &err);
- hmp_handle_error(mon, &err);
-}
-
-void hmp_device_del(Monitor *mon, const QDict *qdict)
-{
- const char *id = qdict_get_str(qdict, "id");
- Error *err = NULL;
-
- qmp_device_del(id, &err);
- hmp_handle_error(mon, &err);
-}
-
void hmp_netdev_add(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
{
const char *path = qdict_get_str(qdict, "path");
- int has_freq = qdict_haskey(qdict, "freq");
- int freq = qdict_get_try_int(qdict, "freq", -1);
- int has_bits = qdict_haskey(qdict, "bits");
- int bits = qdict_get_try_int(qdict, "bits", -1);
- int has_channels = qdict_haskey(qdict, "nchannels");
- int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
+ int freq = qdict_get_try_int(qdict, "freq", 44100);
+ int bits = qdict_get_try_int(qdict, "bits", 16);
+ int nchannels = qdict_get_try_int(qdict, "nchannels", 2);
+ const char *audiodev = qdict_get_str(qdict, "audiodev");
CaptureState *s;
+ AudioState *as = audio_state_by_name(audiodev);
- s = g_malloc0 (sizeof (*s));
+ if (!as) {
+ monitor_printf(mon, "Audiodev '%s' not found\n", audiodev);
+ return;
+ }
- freq = has_freq ? freq : 44100;
- bits = has_bits ? bits : 16;
- nchannels = has_channels ? nchannels : 2;
+ s = g_malloc0 (sizeof (*s));
- if (wav_start_capture (s, path, freq, bits, nchannels)) {
+ if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
monitor_printf(mon, "Failed to add wave capture\n");
g_free (s);
return;
}
/*
- * Emit QMP response @rsp with ID @id to @mon.
+ * Emit QMP response @rsp to @mon.
* Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP.
* Nothing is emitted then.
*/
##
{ 'enum': 'PCIELinkWidth',
'data': [ '1', '2', '4', '8', '12', '16', '32' ] }
-
-##
-# @SysEmuTarget:
-#
-# The comprehensive enumeration of QEMU system emulation ("softmmu")
-# targets. Run "./configure --help" in the project root directory, and
-# look for the *-softmmu targets near the "--target-list" option. The
-# individual target constants are not documented here, for the time
-# being.
-#
-# Notes: The resulting QMP strings can be appended to the "qemu-system-"
-# prefix to produce the corresponding QEMU executable name. This
-# is true even for "qemu-system-x86_64".
-#
-# ppcemb: dropped in 3.1
-#
-# Since: 3.0
-##
-{ 'enum' : 'SysEmuTarget',
- 'data' : [ 'aarch64', 'alpha', 'arm', 'cris', 'hppa', 'i386', 'lm32',
- 'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64',
- 'mips64el', 'mipsel', 'moxie', 'nios2', 'or1k', 'ppc',
- 'ppc64', 'riscv32', 'riscv64', 's390x', 'sh4',
- 'sh4eb', 'sparc', 'sparc64', 'tricore', 'unicore32',
- 'x86_64', 'xtensa', 'xtensaeb' ] }
# = Machines
##
-{ 'include': 'common.json' }
+##
+# @SysEmuTarget:
+#
+# The comprehensive enumeration of QEMU system emulation ("softmmu")
+# targets. Run "./configure --help" in the project root directory, and
+# look for the *-softmmu targets near the "--target-list" option. The
+# individual target constants are not documented here, for the time
+# being.
+#
+# Notes: The resulting QMP strings can be appended to the "qemu-system-"
+# prefix to produce the corresponding QEMU executable name. This
+# is true even for "qemu-system-x86_64".
+#
+# ppcemb: dropped in 3.1
+#
+# Since: 3.0
+##
+{ 'enum' : 'SysEmuTarget',
+ 'data' : [ 'aarch64', 'alpha', 'arm', 'cris', 'hppa', 'i386', 'lm32',
+ 'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64',
+ 'mips64el', 'mipsel', 'moxie', 'nios2', 'or1k', 'ppc',
+ 'ppc64', 'riscv32', 'riscv64', 's390x', 'sh4',
+ 'sh4eb', 'sparc', 'sparc64', 'tricore', 'unicore32',
+ 'x86_64', 'xtensa', 'xtensaeb' ] }
##
# @CpuInfoArch:
##
{ 'command': 'query-current-machine', 'returns': 'CurrentMachineParams' }
+##
+# @TargetInfo:
+#
+# Information describing the QEMU target.
+#
+# @arch: the target architecture
+#
+# Since: 1.2.0
+##
+{ 'struct': 'TargetInfo',
+ 'data': { 'arch': 'SysEmuTarget' } }
+
+##
+# @query-target:
+#
+# Return information about the target for this QEMU
+#
+# Returns: TargetInfo
+#
+# Since: 1.2.0
+##
+{ 'command': 'query-target', 'returns': 'TargetInfo' }
+
##
# @NumaOptionsType:
#
##
{ 'command': 'query-fdsets', 'returns': ['FdsetInfo'] }
-##
-# @TargetInfo:
-#
-# Information describing the QEMU target.
-#
-# @arch: the target architecture
-#
-# Since: 1.2.0
-##
-{ 'struct': 'TargetInfo',
- 'data': { 'arch': 'SysEmuTarget' } }
-
-##
-# @query-target:
-#
-# Return information about the target for this QEMU
-#
-# Returns: TargetInfo
-#
-# Since: 1.2.0
-##
-{ 'command': 'query-target', 'returns': 'TargetInfo' }
-
##
# @AcpiTableOptions:
#
#include "qemu/osdep.h"
#include "hw/sysbus.h"
+#include "monitor/hmp.h"
#include "monitor/monitor.h"
#include "monitor/qdev.h"
#include "sysemu/arch_init.h"
}
}
+void hmp_device_add(Monitor *mon, const QDict *qdict)
+{
+ Error *err = NULL;
+
+ qmp_device_add((QDict *)qdict, NULL, &err);
+ hmp_handle_error(mon, &err);
+}
+
+void hmp_device_del(Monitor *mon, const QDict *qdict)
+{
+ const char *id = qdict_get_str(qdict, "id");
+ Error *err = NULL;
+
+ qmp_device_del(id, &err);
+ hmp_handle_error(mon, &err);
+}
+
BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
{
DeviceState *dev;
events are arriving in bulk. Possible causes for the latter are flaky
network connections, or scripts for automated testing.
+@item audiodev=@var{audiodev}
+
+Use the specified @var{audiodev} when the VNC client requests audio
+transmission. When not using an -audiodev argument, this option must
+be omitted, otherwise is must be present and specify a valid audiodev.
+
@end table
ETEXI
}
assert(ret == -ERANGE);
}
- /* fall through to JSON_FLOAT */
}
+ /* fall through to JSON_FLOAT */
case JSON_FLOAT:
/* FIXME dependent on locale; a pervasive issue in QEMU */
/* FIXME our lexer matches RFC 8259 in forbidding Inf or NaN,
qom-obj-y = object.o container.o qom-qobject.o
qom-obj-y += object_interfaces.o
-common-obj-y = cpu.o
common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
+++ /dev/null
-/*
- * QEMU CPU model
- *
- * Copyright (c) 2012-2014 SUSE LINUX Products GmbH
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see
- * <http://www.gnu.org/licenses/gpl-2.0.html>
- */
-
-#include "qemu/osdep.h"
-#include "qapi/error.h"
-#include "qom/cpu.h"
-#include "sysemu/hw_accel.h"
-#include "qemu/notify.h"
-#include "qemu/log.h"
-#include "qemu/main-loop.h"
-#include "exec/log.h"
-#include "qemu/error-report.h"
-#include "qemu/qemu-print.h"
-#include "sysemu/tcg.h"
-#include "hw/boards.h"
-#include "hw/qdev-properties.h"
-#include "trace-root.h"
-
-CPUInterruptHandler cpu_interrupt_handler;
-
-CPUState *cpu_by_arch_id(int64_t id)
-{
- CPUState *cpu;
-
- CPU_FOREACH(cpu) {
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- if (cc->get_arch_id(cpu) == id) {
- return cpu;
- }
- }
- return NULL;
-}
-
-bool cpu_exists(int64_t id)
-{
- return !!cpu_by_arch_id(id);
-}
-
-CPUState *cpu_create(const char *typename)
-{
- Error *err = NULL;
- CPUState *cpu = CPU(object_new(typename));
- object_property_set_bool(OBJECT(cpu), true, "realized", &err);
- if (err != NULL) {
- error_report_err(err);
- object_unref(OBJECT(cpu));
- exit(EXIT_FAILURE);
- }
- return cpu;
-}
-
-bool cpu_paging_enabled(const CPUState *cpu)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- return cc->get_paging_enabled(cpu);
-}
-
-static bool cpu_common_get_paging_enabled(const CPUState *cpu)
-{
- return false;
-}
-
-void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
- Error **errp)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- cc->get_memory_mapping(cpu, list, errp);
-}
-
-static void cpu_common_get_memory_mapping(CPUState *cpu,
- MemoryMappingList *list,
- Error **errp)
-{
- error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
-}
-
-/* Resetting the IRQ comes from across the code base so we take the
- * BQL here if we need to. cpu_interrupt assumes it is held.*/
-void cpu_reset_interrupt(CPUState *cpu, int mask)
-{
- bool need_lock = !qemu_mutex_iothread_locked();
-
- if (need_lock) {
- qemu_mutex_lock_iothread();
- }
- cpu->interrupt_request &= ~mask;
- if (need_lock) {
- qemu_mutex_unlock_iothread();
- }
-}
-
-void cpu_exit(CPUState *cpu)
-{
- atomic_set(&cpu->exit_request, 1);
- /* Ensure cpu_exec will see the exit request after TCG has exited. */
- smp_wmb();
- atomic_set(&cpu->icount_decr_ptr->u16.high, -1);
-}
-
-int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
- void *opaque)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- return (*cc->write_elf32_qemunote)(f, cpu, opaque);
-}
-
-static int cpu_common_write_elf32_qemunote(WriteCoreDumpFunction f,
- CPUState *cpu, void *opaque)
-{
- return 0;
-}
-
-int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
- int cpuid, void *opaque)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- return (*cc->write_elf32_note)(f, cpu, cpuid, opaque);
-}
-
-static int cpu_common_write_elf32_note(WriteCoreDumpFunction f,
- CPUState *cpu, int cpuid,
- void *opaque)
-{
- return -1;
-}
-
-int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
- void *opaque)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- return (*cc->write_elf64_qemunote)(f, cpu, opaque);
-}
-
-static int cpu_common_write_elf64_qemunote(WriteCoreDumpFunction f,
- CPUState *cpu, void *opaque)
-{
- return 0;
-}
-
-int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
- int cpuid, void *opaque)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- return (*cc->write_elf64_note)(f, cpu, cpuid, opaque);
-}
-
-static int cpu_common_write_elf64_note(WriteCoreDumpFunction f,
- CPUState *cpu, int cpuid,
- void *opaque)
-{
- return -1;
-}
-
-
-static int cpu_common_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg)
-{
- return 0;
-}
-
-static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg)
-{
- return 0;
-}
-
-static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp)
-{
- /* If no extra check is required, QEMU watchpoint match can be considered
- * as an architectural match.
- */
- return true;
-}
-
-static bool cpu_common_virtio_is_big_endian(CPUState *cpu)
-{
- return target_words_bigendian();
-}
-
-static void cpu_common_noop(CPUState *cpu)
-{
-}
-
-static bool cpu_common_exec_interrupt(CPUState *cpu, int int_req)
-{
- return false;
-}
-
-GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
- GuestPanicInformation *res = NULL;
-
- if (cc->get_crash_info) {
- res = cc->get_crash_info(cpu);
- }
- return res;
-}
-
-void cpu_dump_state(CPUState *cpu, FILE *f, int flags)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- if (cc->dump_state) {
- cpu_synchronize_state(cpu);
- cc->dump_state(cpu, f, flags);
- }
-}
-
-void cpu_dump_statistics(CPUState *cpu, int flags)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- if (cc->dump_statistics) {
- cc->dump_statistics(cpu, flags);
- }
-}
-
-void cpu_reset(CPUState *cpu)
-{
- CPUClass *klass = CPU_GET_CLASS(cpu);
-
- if (klass->reset != NULL) {
- (*klass->reset)(cpu);
- }
-
- trace_guest_cpu_reset(cpu);
-}
-
-static void cpu_common_reset(CPUState *cpu)
-{
- CPUClass *cc = CPU_GET_CLASS(cpu);
-
- if (qemu_loglevel_mask(CPU_LOG_RESET)) {
- qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
- log_cpu_state(cpu, cc->reset_dump_flags);
- }
-
- cpu->interrupt_request = 0;
- cpu->halted = 0;
- cpu->mem_io_pc = 0;
- cpu->mem_io_vaddr = 0;
- cpu->icount_extra = 0;
- atomic_set(&cpu->icount_decr_ptr->u32, 0);
- cpu->can_do_io = 1;
- cpu->exception_index = -1;
- cpu->crash_occurred = false;
- cpu->cflags_next_tb = -1;
-
- if (tcg_enabled()) {
- cpu_tb_jmp_cache_clear(cpu);
-
- tcg_flush_softmmu_tlb(cpu);
- }
-}
-
-static bool cpu_common_has_work(CPUState *cs)
-{
- return false;
-}
-
-ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model)
-{
- CPUClass *cc = CPU_CLASS(object_class_by_name(typename));
-
- assert(cpu_model && cc->class_by_name);
- return cc->class_by_name(cpu_model);
-}
-
-static void cpu_common_parse_features(const char *typename, char *features,
- Error **errp)
-{
- char *val;
- static bool cpu_globals_initialized;
- /* Single "key=value" string being parsed */
- char *featurestr = features ? strtok(features, ",") : NULL;
-
- /* should be called only once, catch invalid users */
- assert(!cpu_globals_initialized);
- cpu_globals_initialized = true;
-
- while (featurestr) {
- val = strchr(featurestr, '=');
- if (val) {
- GlobalProperty *prop = g_new0(typeof(*prop), 1);
- *val = 0;
- val++;
- prop->driver = typename;
- prop->property = g_strdup(featurestr);
- prop->value = g_strdup(val);
- qdev_prop_register_global(prop);
- } else {
- error_setg(errp, "Expected key=value format, found %s.",
- featurestr);
- return;
- }
- featurestr = strtok(NULL, ",");
- }
-}
-
-static void cpu_common_realizefn(DeviceState *dev, Error **errp)
-{
- CPUState *cpu = CPU(dev);
- Object *machine = qdev_get_machine();
-
- /* qdev_get_machine() can return something that's not TYPE_MACHINE
- * if this is one of the user-only emulators; in that case there's
- * no need to check the ignore_memory_transaction_failures board flag.
- */
- if (object_dynamic_cast(machine, TYPE_MACHINE)) {
- ObjectClass *oc = object_get_class(machine);
- MachineClass *mc = MACHINE_CLASS(oc);
-
- if (mc) {
- cpu->ignore_memory_transaction_failures =
- mc->ignore_memory_transaction_failures;
- }
- }
-
- if (dev->hotplugged) {
- cpu_synchronize_post_init(cpu);
- cpu_resume(cpu);
- }
-
- /* NOTE: latest generic point where the cpu is fully realized */
- trace_init_vcpu(cpu);
-}
-
-static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
-{
- CPUState *cpu = CPU(dev);
- /* NOTE: latest generic point before the cpu is fully unrealized */
- trace_fini_vcpu(cpu);
- cpu_exec_unrealizefn(cpu);
-}
-
-static void cpu_common_initfn(Object *obj)
-{
- CPUState *cpu = CPU(obj);
- CPUClass *cc = CPU_GET_CLASS(obj);
-
- cpu->cpu_index = UNASSIGNED_CPU_INDEX;
- cpu->cluster_index = UNASSIGNED_CLUSTER_INDEX;
- cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
- /* *-user doesn't have configurable SMP topology */
- /* the default value is changed by qemu_init_vcpu() for softmmu */
- cpu->nr_cores = 1;
- cpu->nr_threads = 1;
-
- qemu_mutex_init(&cpu->work_mutex);
- QTAILQ_INIT(&cpu->breakpoints);
- QTAILQ_INIT(&cpu->watchpoints);
-
- cpu_exec_initfn(cpu);
-}
-
-static void cpu_common_finalize(Object *obj)
-{
- CPUState *cpu = CPU(obj);
-
- qemu_mutex_destroy(&cpu->work_mutex);
-}
-
-static int64_t cpu_common_get_arch_id(CPUState *cpu)
-{
- return cpu->cpu_index;
-}
-
-static vaddr cpu_adjust_watchpoint_address(CPUState *cpu, vaddr addr, int len)
-{
- return addr;
-}
-
-static void generic_handle_interrupt(CPUState *cpu, int mask)
-{
- cpu->interrupt_request |= mask;
-
- if (!qemu_cpu_is_self(cpu)) {
- qemu_cpu_kick(cpu);
- }
-}
-
-CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
-
-static void cpu_class_init(ObjectClass *klass, void *data)
-{
- DeviceClass *dc = DEVICE_CLASS(klass);
- CPUClass *k = CPU_CLASS(klass);
-
- k->parse_features = cpu_common_parse_features;
- k->reset = cpu_common_reset;
- k->get_arch_id = cpu_common_get_arch_id;
- k->has_work = cpu_common_has_work;
- k->get_paging_enabled = cpu_common_get_paging_enabled;
- k->get_memory_mapping = cpu_common_get_memory_mapping;
- k->write_elf32_qemunote = cpu_common_write_elf32_qemunote;
- k->write_elf32_note = cpu_common_write_elf32_note;
- k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
- k->write_elf64_note = cpu_common_write_elf64_note;
- k->gdb_read_register = cpu_common_gdb_read_register;
- k->gdb_write_register = cpu_common_gdb_write_register;
- k->virtio_is_big_endian = cpu_common_virtio_is_big_endian;
- k->debug_excp_handler = cpu_common_noop;
- k->debug_check_watchpoint = cpu_common_debug_check_watchpoint;
- k->cpu_exec_enter = cpu_common_noop;
- k->cpu_exec_exit = cpu_common_noop;
- k->cpu_exec_interrupt = cpu_common_exec_interrupt;
- k->adjust_watchpoint_address = cpu_adjust_watchpoint_address;
- set_bit(DEVICE_CATEGORY_CPU, dc->categories);
- dc->realize = cpu_common_realizefn;
- dc->unrealize = cpu_common_unrealizefn;
- dc->props = cpu_common_props;
- /*
- * Reason: CPUs still need special care by board code: wiring up
- * IRQs, adding reset handlers, halting non-first CPUs, ...
- */
- dc->user_creatable = false;
-}
-
-static const TypeInfo cpu_type_info = {
- .name = TYPE_CPU,
- .parent = TYPE_DEVICE,
- .instance_size = sizeof(CPUState),
- .instance_init = cpu_common_initfn,
- .instance_finalize = cpu_common_finalize,
- .abstract = true,
- .class_size = sizeof(CPUClass),
- .class_init = cpu_class_init,
-};
-
-static void cpu_register_types(void)
-{
- type_register_static(&cpu_type_info);
-}
-
-type_init(cpu_register_types)
#include "replay-internal.h"
#include "audio/audio.h"
-void replay_audio_out(int *played)
+void replay_audio_out(size_t *played)
{
if (replay_mode == REPLAY_MODE_RECORD) {
g_assert(replay_mutex_locked());
replay_save_instructions();
replay_put_event(EVENT_AUDIO_OUT);
- replay_put_dword(*played);
+ replay_put_qword(*played);
} else if (replay_mode == REPLAY_MODE_PLAY) {
g_assert(replay_mutex_locked());
replay_account_executed_instructions();
if (replay_next_event_is(EVENT_AUDIO_OUT)) {
- *played = replay_get_dword();
+ *played = replay_get_qword();
replay_finish_event();
} else {
error_report("Missing audio out event in the replay log");
}
}
-void replay_audio_in(int *recorded, void *samples, int *wpos, int size)
+void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size)
{
int pos;
uint64_t left, right;
g_assert(replay_mutex_locked());
replay_save_instructions();
replay_put_event(EVENT_AUDIO_IN);
- replay_put_dword(*recorded);
- replay_put_dword(*wpos);
+ replay_put_qword(*recorded);
+ replay_put_qword(*wpos);
for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
; pos = (pos + 1) % size) {
audio_sample_to_uint64(samples, pos, &left, &right);
g_assert(replay_mutex_locked());
replay_account_executed_instructions();
if (replay_next_event_is(EVENT_AUDIO_IN)) {
- *recorded = replay_get_dword();
- *wpos = replay_get_dword();
+ *recorded = replay_get_qword();
+ *wpos = replay_get_qword();
for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
; pos = (pos + 1) % size) {
left = replay_get_qword();
/* Current version of the replay mechanism.
Increase it when file format changes. */
-#define REPLAY_VERSION 0xe02007
+#define REPLAY_VERSION 0xe02008
/* Size of replay log header */
#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
#ifndef QEMU_ALPHA_CPU_QOM_H
#define QEMU_ALPHA_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_ALPHA_CPU "alpha-cpu"
#ifndef QEMU_ARM_CPU_QOM_H
#define QEMU_ARM_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
struct arm_boot_info;
#ifndef QEMU_CRIS_CPU_QOM_H
#define QEMU_CRIS_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_CRIS_CPU "cris-cpu"
#ifndef QEMU_HPPA_CPU_QOM_H
#define QEMU_HPPA_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_HPPA_CPU "hppa-cpu"
#include "qemu/log.h"
#include "cpu.h"
#include "exec/helper-proto.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#ifndef CONFIG_USER_ONLY
static void eval_interrupt(HPPACPU *cpu)
#include "cpu.h"
#include "exec/exec-all.h"
#include "exec/helper-proto.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "trace.h"
#ifdef CONFIG_USER_ONLY
#ifndef QEMU_I386_CPU_QOM_H
#define QEMU_I386_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "qemu/notify.h"
#ifdef TARGET_X86_64
#ifndef QEMU_LM32_CPU_QOM_H
#define QEMU_LM32_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_LM32_CPU "lm32-cpu"
#ifndef QEMU_M68K_CPU_QOM_H
#define QEMU_M68K_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_M68K_CPU "m68k-cpu"
#ifndef QEMU_MICROBLAZE_CPU_QOM_H
#define QEMU_MICROBLAZE_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_MICROBLAZE_CPU "microblaze-cpu"
#ifndef QEMU_MIPS_CPU_QOM_H
#define QEMU_MIPS_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#ifdef TARGET_MIPS64
#define TYPE_MIPS_CPU "mips64-cpu"
struct {} end_reset_fields;
} CPUMoxieState;
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_MOXIE_CPU "moxie-cpu"
#define NIOS2_CPU_H
#include "exec/cpu-defs.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
typedef struct CPUNios2State CPUNios2State;
#if !defined(CONFIG_USER_ONLY)
#define OPENRISC_CPU_H
#include "exec/cpu-defs.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
/* cpu_openrisc_map_address_* in CPUOpenRISCTLBContext need this decl. */
struct OpenRISCCPU;
#ifndef QEMU_PPC_CPU_QOM_H
#define QEMU_PPC_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#ifdef TARGET_PPC64
#define TYPE_POWERPC_CPU "powerpc64-cpu"
case 0x1:
case 0x2:
access |= PAGE_WRITE;
- /* No break here */
+ /* fall through */
case 0x3:
access |= PAGE_READ;
break;
if (pr != 0) {
goto check_perms;
}
- /* No break here */
+ /* fall through */
case 0x3:
/* All accesses granted */
ctx->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
ret = -2;
break;
}
- /* No break here */
+ /* fall through */
case 0x1:
check_perms:
/* Check from TLB entry */
#ifndef RISCV_CPU_H
#define RISCV_CPU_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#include "exec/cpu-defs.h"
#include "fpu/softfloat-types.h"
#ifndef QEMU_S390_CPU_QOM_H
#define QEMU_S390_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_S390_CPU "s390x-cpu"
#include "cpu_features.h"
#include "gen-features.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
/* static CPU definition */
struct S390CPUDef {
#ifndef QEMU_SUPERH_CPU_QOM_H
#define QEMU_SUPERH_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_SUPERH_CPU "superh-cpu"
#ifndef QEMU_SPARC_CPU_QOM_H
#define QEMU_SPARC_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#ifdef TARGET_SPARC64
#define TYPE_SPARC_CPU "sparc64-cpu"
struct {} end_reset_fields;
} CPUTLGState;
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_TILEGX_CPU "tilegx-cpu"
#ifndef QEMU_TRICORE_CPU_QOM_H
#define QEMU_TRICORE_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_TRICORE_CPU "tricore-cpu"
#ifndef QEMU_UC32_CPU_QOM_H
#define QEMU_UC32_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_UNICORE32_CPU "unicore32-cpu"
#ifndef QEMU_XTENSA_CPU_QOM_H
#define QEMU_XTENSA_CPU_QOM_H
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#define TYPE_XTENSA_CPU "xtensa-cpu"
if (*end == ' ') {
end++;
}
- in = strndup(tail, end - tail);
+ in = g_strndup(tail, end - tail);
str = from_json_str(in, j, NULL);
g_assert(!str);
g_free(in);
}
if (end)
- *val = strndup(start, end - start);
+ *val = g_strndup(start, end - start);
else
- *val = strdup(start);
+ *val = g_strdup(start);
return 1;
}
if (errno || *end) {
fprintf(stderr, "%s (%05d): ERROR: cannot parse %s value %s\n",
argv0, gettid(), name, valstr);
- free(valstr);
+ g_free(valstr);
return -1;
}
- free(valstr);
+ g_free(valstr);
return 0;
}
# Targets: all
vcpu guest_cpu_exit(void)
-# qom/cpu.c
+# hw/core/cpu.c
# Reset the state of a virtual (guest) CPU
#
#include "control.h"
#include "event-internal.h"
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
/**
* trace_event_get_vcpu_state:
#include "qemu/main-loop.h"
#include "qemu/module.h"
#include <Carbon/Carbon.h>
-#include "qom/cpu.h"
+#include "hw/core/cpu.h"
#ifndef MAC_OS_X_VERSION_10_5
#define MAC_OS_X_VERSION_10_5 1050
ops.destroy = audio_capture_destroy;
ops.capture = audio_capture;
- vs->audio_cap = AUD_add_capture(&vs->as, &ops, vs);
+ vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
if (!vs->audio_cap) {
error_report("Failed to add audio capture");
}
},{
.name = "non-adaptive",
.type = QEMU_OPT_BOOL,
+ },{
+ .name = "audiodev",
+ .type = QEMU_OPT_STRING,
},
{ /* end of list */ }
},
const char *saslauthz;
int lock_key_sync = 1;
int key_delay_ms;
+ const char *audiodev;
if (!vd) {
error_setg(errp, "VNC display not active");
}
vd->ledstate = 0;
+ audiodev = qemu_opt_get(opts, "audiodev");
+ if (audiodev) {
+ vd->audio_state = audio_state_by_name(audiodev);
+ if (!vd->audio_state) {
+ error_setg(errp, "Audiodev '%s' not found", audiodev);
+ goto fail;
+ }
+ }
+
device_id = qemu_opt_get(opts, "display");
if (device_id) {
int head = qemu_opt_get_number(opts, "head", 0);
#ifdef CONFIG_VNC_SASL
VncDisplaySASL sasl;
#endif
+
+ AudioState *audio_state;
};
typedef struct VncTight {
switch (clock) {
case QEMU_CLOCK_REALTIME:
value -= rtc_realtime_clock_offset;
- /* no break */
+ /* fall through */
case QEMU_CLOCK_VIRTUAL:
value += rtc_ref_start_datetime;
break;