[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] ioemu: backport upstream's qemu_memalign.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1202981198 0
# Node ID 866e90d5deb4c47134d63607eb48b9119d940720
# Parent  eefd66912b65ca85eeef18c5ab5b19fe48f69e28
ioemu: backport upstream's qemu_memalign.
Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
---
 tools/ioemu/block-vbd.c    |    4 ++--
 tools/ioemu/hw/fdc.c       |    7 ++++++-
 tools/ioemu/hw/ide.c       |    2 +-
 tools/ioemu/hw/scsi-disk.c |    2 +-
 tools/ioemu/osdep.c        |   20 ++++++++++++++++++++
 tools/ioemu/osdep.h        |    1 +
 6 files changed, 31 insertions(+), 5 deletions(-)

diff -r eefd66912b65 -r 866e90d5deb4 tools/ioemu/block-vbd.c
--- a/tools/ioemu/block-vbd.c   Thu Feb 14 09:24:35 2008 +0000
+++ b/tools/ioemu/block-vbd.c   Thu Feb 14 09:26:38 2008 +0000
@@ -227,7 +227,7 @@ static int vbd_read(BlockDriverState *bs
      * copying */
     if (!((uintptr_t)buf & (SECTOR_SIZE-1)))
        return vbd_aligned_io(bs, sector_num, buf, nb_sectors, 0);
-    iobuf = memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
+    iobuf = qemu_memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
     ret = vbd_aligned_io(bs, sector_num, iobuf, nb_sectors, 0);
     memcpy(buf, iobuf, nb_sectors * SECTOR_SIZE);
     free(iobuf);
@@ -246,7 +246,7 @@ static int vbd_write(BlockDriverState *b
     int ret;
     if (!((uintptr_t)buf & (SECTOR_SIZE-1)))
        return vbd_aligned_io(bs, sector_num, (uint8_t*) buf, nb_sectors, 1);
-    iobuf = memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
+    iobuf = qemu_memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
     memcpy(iobuf, buf, nb_sectors * SECTOR_SIZE);
     ret = vbd_aligned_io(bs, sector_num, iobuf, nb_sectors, 1);
     free(iobuf);
diff -r eefd66912b65 -r 866e90d5deb4 tools/ioemu/hw/fdc.c
--- a/tools/ioemu/hw/fdc.c      Thu Feb 14 09:24:35 2008 +0000
+++ b/tools/ioemu/hw/fdc.c      Thu Feb 14 09:26:38 2008 +0000
@@ -378,7 +378,7 @@ struct fdctrl_t {
     uint8_t cur_drv;
     uint8_t bootsel;
     /* Command FIFO */
-    uint8_t fifo[FD_SECTOR_LEN];
+    uint8_t *fifo;
     uint32_t data_pos;
     uint32_t data_len;
     uint8_t data_state;
@@ -497,6 +497,11 @@ fdctrl_t *fdctrl_init (int irq_lvl, int 
     fdctrl = qemu_mallocz(sizeof(fdctrl_t));
     if (!fdctrl)
         return NULL;
+    fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
+    if (fdctrl->fifo == NULL) {
+        qemu_free(fdctrl);
+        return NULL;
+    }
     fdctrl->result_timer = qemu_new_timer(vm_clock, 
                                           fdctrl_result_timer, fdctrl);
 
diff -r eefd66912b65 -r 866e90d5deb4 tools/ioemu/hw/ide.c
--- a/tools/ioemu/hw/ide.c      Thu Feb 14 09:24:35 2008 +0000
+++ b/tools/ioemu/hw/ide.c      Thu Feb 14 09:26:38 2008 +0000
@@ -2306,7 +2306,7 @@ static void ide_init2(IDEState *ide_stat
 
     for(i = 0; i < 2; i++) {
         s = ide_state + i;
-        s->io_buffer = memalign(getpagesize(), MAX_MULT_SECTORS*512 + 4);
+        s->io_buffer = qemu_memalign(getpagesize(), MAX_MULT_SECTORS*512 + 4);
         if (i == 0)
             s->bs = hd0;
         else
diff -r eefd66912b65 -r 866e90d5deb4 tools/ioemu/hw/scsi-disk.c
--- a/tools/ioemu/hw/scsi-disk.c        Thu Feb 14 09:24:35 2008 +0000
+++ b/tools/ioemu/hw/scsi-disk.c        Thu Feb 14 09:26:38 2008 +0000
@@ -81,7 +81,7 @@ static SCSIRequest *scsi_new_request(SCS
         free_requests = r->next;
     } else {
         r = qemu_malloc(sizeof(SCSIRequest));
-       r->dma_buf = memalign(getpagesize(), SCSI_DMA_BUF_SIZE);
+       r->dma_buf = qemu_memalign(getpagesize(), SCSI_DMA_BUF_SIZE);
     }
     r->dev = s;
     r->tag = tag;
diff -r eefd66912b65 -r 866e90d5deb4 tools/ioemu/osdep.c
--- a/tools/ioemu/osdep.c       Thu Feb 14 09:24:35 2008 +0000
+++ b/tools/ioemu/osdep.c       Thu Feb 14 09:26:38 2008 +0000
@@ -61,6 +61,10 @@ void *qemu_malloc(size_t size)
 }
 
 #if defined(_WIN32)
+void *qemu_memalign(size_t alignment, size_t size)
+{
+    return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
+}
 
 void *qemu_vmalloc(size_t size)
 {
@@ -172,6 +176,22 @@ void kqemu_vfree(void *ptr)
 
 #endif
 
+void *qemu_memalign(size_t alignment, size_t size)
+{
+#if defined(_POSIX_C_SOURCE)
+    int ret;
+    void *ptr;
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0)
+        return NULL;
+    return ptr;
+#elif defined(_BSD)
+    return valloc(size);
+#else
+    return memalign(alignment, size);
+#endif
+}
+
 /* alloc shared memory pages */
 void *qemu_vmalloc(size_t size)
 {
diff -r eefd66912b65 -r 866e90d5deb4 tools/ioemu/osdep.h
--- a/tools/ioemu/osdep.h       Thu Feb 14 09:24:35 2008 +0000
+++ b/tools/ioemu/osdep.h       Thu Feb 14 09:26:38 2008 +0000
@@ -14,6 +14,7 @@ void qemu_free(void *ptr);
 void qemu_free(void *ptr);
 char *qemu_strdup(const char *str);
 
+void *qemu_memalign(size_t alignment, size_t size);
 void *qemu_vmalloc(size_t size);
 void qemu_vfree(void *ptr);
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.