OBJS += rtl8139.o
OBJS += e1000.o
+ # Serial mouse
+ OBJS += msmouse.o
+
ifeq ($(TARGET_BASE_ARCH), i386)
# Hardware support
-OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o
-OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
+ifdef CONFIG_AUDIO
+OBJS+= $(SOUND_HW) pcspk.o
+CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
+endif
+OBJS+= ide.o pckbd.o ps2.o vga.o dma.o
+OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pc.o
OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o
OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
-CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
+ OBJS += device-hotplug.o pci-hotplug.o
endif
ifeq ($(TARGET_BASE_ARCH), ppc)
CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
- if (qemu_read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
+ if (!s->catalog_bitmap)
+ goto fail;
+ if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
s->catalog_size * 4)
goto fail;
for (i = 0; i < s->catalog_size; i++)
/* read offsets */
offsets_size=s->n_blocks*sizeof(uint64_t);
- s->offsets=(uint64_t*)qemu_malloc(offsets_size);
+ if(!(s->offsets=(uint64_t*)malloc(offsets_size)))
+ goto cloop_close;
- if(qemu_read_ok(s->fd,s->offsets,offsets_size)<0)
+ if(read(s->fd,s->offsets,offsets_size)<offsets_size)
goto cloop_close;
for(i=0;i<s->n_blocks;i++) {
s->offsets[i]=be64_to_cpu(s->offsets[i]);
s->catalog_size = le32_to_cpu(ph.catalog_entries);
s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
- if (qemu_read_ok(s->fd, s->catalog_bitmap, s->catalog_size * 4) < 0)
+ if (!s->catalog_bitmap)
+ goto fail;
+ if (read(s->fd, s->catalog_bitmap, s->catalog_size * 4) !=
+ s->catalog_size * 4)
goto fail;
for (i = 0; i < s->catalog_size; i++)
le32_to_cpus(&s->catalog_bitmap[i]);
return 0;
s = qemu_malloc(sizeof(PosixAioState));
- if (s == NULL)
- return -ENOMEM;
+ /* under some circumstances on Centos 4.3 (at least)
+ * SIGUSR2 is mistakenly blocked, which breaks badly */
+ sigemptyset(&enable);
+ sigaddset(&enable,SIGUSR2);
+ sigprocmask(SIG_UNBLOCK,&enable,0);
+
sigfillset(&act.sa_mask);
act.sa_flags = 0; /* do not restart syscalls to interrupt select() */
act.sa_handler = aio_signal_handler;
/* write RGD */
rgd_buf = qemu_malloc(gd_size);
- if (!rgd_buf)
- goto fail;
if (lseek(p_fd, rgd_offset, SEEK_SET) == -1)
goto fail_rgd;
- if (read(p_fd, rgd_buf, gd_size) != gd_size)
+ if (qemu_read_ok(p_fd, rgd_buf, gd_size) < 0)
goto fail_rgd;
if (lseek(snp_fd, rgd_offset, SEEK_SET) == -1)
goto fail_rgd;
/* write GD */
gd_buf = qemu_malloc(gd_size);
- if (!gd_buf)
- goto fail_rgd;
if (lseek(p_fd, gd_offset, SEEK_SET) == -1)
goto fail_gd;
- if (read(p_fd, gd_buf, gd_size) != gd_size)
+ if (qemu_read_ok(p_fd, gd_buf, gd_size) < 0)
goto fail_gd;
if (lseek(snp_fd, gd_offset, SEEK_SET) == -1)
goto fail_gd;
if (!drv)
return -ENOMEDIUM;
+ if (bdrv_check_request(bs, sector_num, nb_sectors))
+ return -EIO;
- if (bdrv_rw_badreq_sectors(bs, sector_num, nb_sectors))
- return -EDOM;
++ if (bdrv_check_request(bs, sector_num, nb_sectors))
++ return -EIO;
if (drv->bdrv_pread) {
int ret, len;
len = nb_sectors * 512;
BlockDriver *drv = bs->drv;
if (!drv)
return -ENOMEDIUM;
- if (bdrv_rw_badreq_sectors(bs, sector_num, nb_sectors))
- return -EDOM;
++ if (bdrv_check_request(bs, sector_num, nb_sectors))
++ return -EIO;
if (!drv->bdrv_write_compressed)
return -ENOTSUP;
return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
DisplayState *ds;
ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
- if (ds == NULL)
- return NULL;
- ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
+ ds->allocator = &default_allocator;
+ ds->surface = qemu_create_displaysurface(ds, 640, 480, 32, 640 * 4);
s = new_console(ds, GRAPHIC_CONSOLE);
if (s == NULL) {
return pf;
}
-DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize)
+DisplaySurface* defaultallocator_create_displaysurface(int width, int height, int bpp, int linesize)
{
DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface));
- if (surface == NULL) {
- fprintf(stderr, "defaultallocator_create_displaysurface: malloc failed\n");
- exit(1);
- }
surface->width = width;
surface->height = height;
ide_init_ioport(&d->ide_if[0], 0x1f0, 0x3f6);
ide_init_ioport(&d->ide_if[2], 0x170, 0x376);
- register_savevm("ide", 0, 2, pci_ide_save, pci_ide_load, d);
+ buffered_pio_init();
+
+ for (i = 0; i < 4; i++)
+ if (hd_table[i])
+ hd_table[i]->private = &d->dev;
+
+ register_savevm("ide", 0, 3, pci_ide_save, pci_ide_load, d);
}
/* hd_table must contain 4 block drivers */
#define MAX_IDE_BUS 2
+#ifdef HAS_TPM
+void tpm_tis_init(SetIRQFunc *set_irq, void *opaque, int irq);
+#endif
+
+ extern uint8_t *acpi_tables;
+ extern size_t acpi_tables_len;
+
static fdctrl_t *floppy_controller;
static RTCState *rtc_state;
static PITState *pit;
qemu_irq sci_irq);
void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
void acpi_bios_init(void);
+ int acpi_table_add(const char *table_desc);
+void acpi_php_add(int);
+void acpi_php_del(int);
+
/* hpet.c */
extern int no_hpet;
#include "console.h"
#include "net.h"
#include "virtio-net.h"
+ #include "sysemu.h"
+#include "exec-all.h"
+#include "qemu-xen.h"
+
//#define DEBUG_PCI
struct PCIBus {
target_phys_addr_t pci_mem_base;
static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU;
-static int pci_irq_index;
static PCIBus *first_bus;
- static int pcibus_load(QEMUFile *f, void *opaque, int version_id)
-static void pcibus_save(QEMUFile *f, void *opaque)
-{
- PCIBus *bus = (PCIBus *)opaque;
- int i;
-
- qemu_put_be32(f, bus->nirq);
- for (i = 0; i < bus->nirq; i++)
- qemu_put_be32(f, bus->irq_count[i]);
-}
-
+ static int pcibus_load(QEMUFile *f, void *opaque, int version_id)
{
- PCIBus *bus = (PCIBus *)opaque;
int i, nirq;
if (version_id != 1)
return pci_dev;
}
- void pci_register_io_region(PCIDevice *pci_dev, int region_num,
- uint32_t size, int type,
++int pci_devfn_in_use(PCIBus *bus, int devfn)
++{
++ return bus->devices[devfn] ? 1 : 0;
++}
++
+void pci_hide_device(PCIDevice *pci_dev)
+{
+ PCIBus *bus = pci_dev->bus;
+ bus->devices[pci_dev->devfn] = NULL;
+}
+
- pci_irq_index--;
+ static target_phys_addr_t pci_to_cpu_addr(target_phys_addr_t addr)
+ {
+ return addr + pci_mem_base;
+ }
+
+ static void pci_unregister_io_regions(PCIDevice *pci_dev)
+ {
+ PCIIORegion *r;
+ int i;
+
+ for(i = 0; i < PCI_NUM_REGIONS; i++) {
+ r = &pci_dev->io_regions[i];
+ if (!r->size || r->addr == -1)
+ continue;
+ if (r->type == PCI_ADDRESS_SPACE_IO) {
+ isa_unassign_ioport(r->addr, r->size);
+ } else {
+ cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+ r->size,
+ IO_MEM_UNASSIGNED);
+ }
+ }
+ }
+
+ int pci_unregister_device(PCIDevice *pci_dev)
+ {
+ int ret = 0;
+
+ if (pci_dev->unregister)
+ ret = pci_dev->unregister(pci_dev);
+ if (ret)
+ return ret;
+
+ pci_unregister_io_regions(pci_dev);
+
+ qemu_free_irqs(pci_dev->irq);
+ pci_dev->bus->devices[pci_dev->devfn] = NULL;
+ qemu_free(pci_dev);
+ return 0;
+ }
+
+ void pci_register_io_region(PCIDevice *pci_dev, int region_num,
+ uint32_t size, int type,
PCIMapIORegionFunc *map_func)
{
PCIIORegion *r;
qemu_check_nic_model_list(nd, pci_nic_models, default_model);
for (i = 0; pci_nic_models[i]; i++)
- if (strcmp(nd->model, pci_nic_models[i]) == 0)
- pci_nic_init_fns[i](bus, nd, devfn);
+ if (strcmp(nd->model, pci_nic_models[i]) == 0) {
+ pci_dev = pci_nic_init_fns[i](bus, nd, devfn);
+ if (pci_dev)
+ nd->private = pci_dev;
+ return pci_dev;
+ }
+
+ return NULL;
}
+void pci_unplug_netifs(void)
+{
+ PCIBus *bus;
+ PCIDevice *dev;
+ PCIIORegion *region;
+ int x;
+ int i;
+
+ /* We only support one PCI bus */
+ for (bus = first_bus; bus; bus = NULL) {
+ for (x = 0; x < 256; x++) {
+ dev = bus->devices[x];
+ if (dev &&
+ dev->config[0xa] == 0 &&
+ dev->config[0xb] == 2) {
+ /* Found a netif. Remove it from the bus. Note that
+ we don't free it here, since there could still be
+ references to it floating around. There are only
+ ever one or two structures leaked, and it's not
+ worth finding them all. */
+ bus->devices[x] = NULL;
+ for (i = 0; i < PCI_NUM_REGIONS; i++) {
+ region = &dev->io_regions[i];
+ if (region->addr == (uint32_t)-1 ||
+ region->size == 0)
+ continue;
+ fprintf(logfile, "region type %d at [%x,%x).\n",
+ region->type, region->addr,
+ region->addr+region->size);
+ if (region->type == PCI_ADDRESS_SPACE_IO) {
+ isa_unassign_ioport(region->addr, region->size);
+ } else if (region->type == PCI_ADDRESS_SPACE_MEM) {
+ unregister_iomem(region->addr);
+ }
+ }
+ }
+ }
+ }
+}
+
typedef struct {
PCIDevice dev;
PCIBus *bus;
/* do not access the following fields */
PCIConfigReadFunc *config_read;
PCIConfigWriteFunc *config_write;
- /* ??? This is a PC-specific hack, and should be removed. */
- int irq_index;
+ PCIUnregisterFunc *unregister;
/* IRQ objects for the INTA-INTD pins. */
qemu_irq *irq;
int instance_size, int devfn,
PCIConfigReadFunc *config_read,
PCIConfigWriteFunc *config_write);
+ int pci_unregister_device(PCIDevice *pci_dev);
+void pci_hide_device(PCIDevice *pci_dev);
+
void pci_register_io_region(PCIDevice *pci_dev, int region_num,
uint32_t size, int type,
PCIMapIORegionFunc *map_func);
if (lseek(fd, offset, SEEK_SET) < 0)
return NULL;
ptr = qemu_malloc(size);
- if (!ptr)
- return NULL;
- if (read(fd, ptr, size) != size) {
+ if (qemu_read_ok(fd, ptr, size) < 0) {
qemu_free(ptr);
return NULL;
}
*ep = hdr->ih_ep;
data = qemu_malloc(hdr->ih_size);
- if (!data)
- goto out;
- if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
+ if (qemu_read_ok(fd, data, hdr->ih_size) < 0) {
fprintf(stderr, "Error reading file\n");
goto out;
}
FdMigrationState *s;
FILE *f;
+#ifdef CONFIG_STUBDOM
+ dprintf("stubdom migration? no popen!");
+ return 0;
+#else
+
s = qemu_mallocz(sizeof(*s));
- if (s == NULL) {
- dprintf("Unable to allocate FdMigrationState\n");
- goto err;
- }
f = popen(command, "w");
if (f == NULL) {
pclose(f);
err_after_alloc:
qemu_free(s);
- err:
return NULL;
+#endif /*!CONFIG_STUBDOM*/
}
int exec_start_incoming_migration(const char *command)
TAPState *s;
s = qemu_mallocz(sizeof(TAPState));
- if (!s)
- return NULL;
s->fd = fd;
s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
+ s->next = head_net_tap;
+ head_net_tap = s;
+#ifndef CONFIG_STUBDOM
#ifdef HAVE_IOVEC
s->vc->fd_readv = tap_receive_iov;
+#endif
#endif
qemu_set_fd_handler(s->fd, tap_send, NULL, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
void net_cleanup(void);
int slirp_is_inited(void);
void net_client_check(void);
+void net_tap_shutdown_all(void);
+ void net_host_device_add(const char *device, const char *opts);
+ void net_host_device_remove(int vlan_id, const char *device);
+#ifndef DEFAULT_NETWORK_SCRIPT
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
+#endif
#ifdef __sun__
#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
#else
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
- #include <sys/time.h>
+#include <assert.h>
+ #include <time.h>
+ #include <string.h>
+ #include <stdlib.h>
+ #include <stdio.h>
#include "osdep.h"
+#include "qemu-common.h"
+
+#ifndef CONFIG_STUBDOM
+
#include "posix-aio-compat.h"
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
return 0;
}
-static int qemu_paio_submit(struct qemu_paiocb *aiocb, int is_write)
+static int qemu_paio_submit(struct qemu_paiocb *aiocb, qemu_paio_function fn)
{
- aiocb->is_write = is_write;
+ aiocb->function = fn;
aiocb->ret = -EINPROGRESS;
aiocb->active = 0;
- pthread_mutex_lock(&lock);
+ mutex_lock(&lock);
if (idle_threads == 0 && cur_threads < max_threads)
spawn_thread();
TAILQ_INSERT_TAIL(&request_list, aiocb, node);
CharDriverState *chr;
FDCharDriver *s;
+ socket_set_nonblock(fd_in);
+ socket_set_nonblock(fd_out);
+
chr = qemu_mallocz(sizeof(CharDriverState));
- if (!chr)
- return NULL;
s = qemu_mallocz(sizeof(FDCharDriver));
- if (!s) {
- free(chr);
- return NULL;
- }
s->fd_in = fd_in;
s->fd_out = fd_out;
chr->opaque = s;
fprintf(stderr, "Could not initialize SDL - exiting\n");
exit(1);
}
+#ifndef _WIN32
+ /* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */
+ signal(SIGINT, SIG_DFL);
+ signal(SIGQUIT, SIG_DFL);
+#endif
dcl = qemu_mallocz(sizeof(DisplayChangeListener));
- if (!dcl)
- exit(1);
dcl->dpy_update = sdl_update;
dcl->dpy_resize = sdl_resize;
dcl->dpy_refresh = sdl_refresh;
case IF_MTD:
case IF_VIRTIO:
break;
+ case IF_BLKTAP:
+ abort();
}
if (!file[0])
- return 0;
+ return -2;
bdrv_flags = 0;
if (snapshot) {
bdrv_flags |= BDRV_O_SNAPSHOT;
#endif
"-tb-size n set TB size\n"
"-incoming p prepare for incoming migration, listen on port p\n"
+ #ifndef _WIN32
+ "-chroot dir Chroot to dir just before starting the VM.\n"
+ "-runas user Change to user id user just before starting the VM.\n"
+ #endif
"\n"
+ "Options specific to the Xen version:\n"
+ "-videoram set amount of memory available to virtual video adapter\n"
+ "-direct-pci s specify pci passthrough, with configuration string s\n"
+ "-pciemulation name:vendorid:deviceid:command:status:revision:classcode:headertype:subvendorid:subsystemid:interruputline:interruputpin\n"
+ "-vncunused bind the VNC server to an unused port\n"
+ "-std-vga alias for -vga std\n"
+ "\n"
"During emulation, the following keys are useful:\n"
"ctrl-alt-f toggle full screen\n"
"ctrl-alt-n switch to virtual console 'n'\n"
const char *pid_file = NULL;
int autostart;
const char *incoming = NULL;
+ int fd = 0;
+ struct passwd *pwd = NULL;
+ const char *chroot_dir = NULL;
+ const char *run_as = NULL;
qemu_cache_utils_init(envp);
+ logfile = stderr; /* initial value */
+
+#if !defined(__sun__) && !defined(CONFIG_STUBDOM)
+ struct rlimit rl;
+ /* Maximise rlimits. Needed where default constraints are tight (*BSD). */
+ if (getrlimit(RLIMIT_STACK, &rl) != 0) {
+ perror("getrlimit(RLIMIT_STACK)");
+ exit(1);
+ }
+ rl.rlim_cur = rl.rlim_max;
+ if (setrlimit(RLIMIT_STACK, &rl) != 0)
+ perror("setrlimit(RLIMIT_STACK)");
+ if (getrlimit(RLIMIT_DATA, &rl) != 0) {
+ perror("getrlimit(RLIMIT_DATA)");
+ exit(1);
+ }
+ rl.rlim_cur = rl.rlim_max;
+ if (setrlimit(RLIMIT_DATA, &rl) != 0)
+ perror("setrlimit(RLIMIT_DATA)");
+ rl.rlim_cur = RLIM_INFINITY;
+ rl.rlim_max = RLIM_INFINITY;
+ if (setrlimit(RLIMIT_RSS, &rl) != 0)
+ perror("setrlimit(RLIMIT_RSS)");
+ rl.rlim_cur = RLIM_INFINITY;
+ rl.rlim_max = RLIM_INFINITY;
+ if (setrlimit(RLIMIT_MEMLOCK, &rl) != 0)
+ perror("setrlimit(RLIMIT_MEMLOCK)");
+#endif
LIST_INIT (&vm_change_state_head);
#ifndef _WIN32
}
}
+ if (strlen(direct_pci_str) > 0)
+ direct_pci = direct_pci_str;
+
machine->init(ram_size, vga_ram_size, boot_devices,
- kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
+ kernel_filename, kernel_cmdline, initrd_filename, cpu_model,
+ direct_pci);
+ current_machine = machine;
+
/* Set KVM's vcpu state to qemu's initial CPUState. */
if (kvm_enabled()) {
int ret;