ia64/xen-unstable

changeset 17060:866e90d5deb4

ioemu: backport upstream's qemu_memalign.
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 14 09:26:38 2008 +0000 (2008-02-14)
parents eefd66912b65
children 80428fb872be
files tools/ioemu/block-vbd.c tools/ioemu/hw/fdc.c tools/ioemu/hw/ide.c tools/ioemu/hw/scsi-disk.c tools/ioemu/osdep.c tools/ioemu/osdep.h
line diff
     1.1 --- a/tools/ioemu/block-vbd.c	Thu Feb 14 09:24:35 2008 +0000
     1.2 +++ b/tools/ioemu/block-vbd.c	Thu Feb 14 09:26:38 2008 +0000
     1.3 @@ -227,7 +227,7 @@ static int vbd_read(BlockDriverState *bs
     1.4       * copying */
     1.5      if (!((uintptr_t)buf & (SECTOR_SIZE-1)))
     1.6  	return vbd_aligned_io(bs, sector_num, buf, nb_sectors, 0);
     1.7 -    iobuf = memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
     1.8 +    iobuf = qemu_memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
     1.9      ret = vbd_aligned_io(bs, sector_num, iobuf, nb_sectors, 0);
    1.10      memcpy(buf, iobuf, nb_sectors * SECTOR_SIZE);
    1.11      free(iobuf);
    1.12 @@ -246,7 +246,7 @@ static int vbd_write(BlockDriverState *b
    1.13      int ret;
    1.14      if (!((uintptr_t)buf & (SECTOR_SIZE-1)))
    1.15  	return vbd_aligned_io(bs, sector_num, (uint8_t*) buf, nb_sectors, 1);
    1.16 -    iobuf = memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
    1.17 +    iobuf = qemu_memalign(PAGE_SIZE, nb_sectors * SECTOR_SIZE);
    1.18      memcpy(iobuf, buf, nb_sectors * SECTOR_SIZE);
    1.19      ret = vbd_aligned_io(bs, sector_num, iobuf, nb_sectors, 1);
    1.20      free(iobuf);
     2.1 --- a/tools/ioemu/hw/fdc.c	Thu Feb 14 09:24:35 2008 +0000
     2.2 +++ b/tools/ioemu/hw/fdc.c	Thu Feb 14 09:26:38 2008 +0000
     2.3 @@ -378,7 +378,7 @@ struct fdctrl_t {
     2.4      uint8_t cur_drv;
     2.5      uint8_t bootsel;
     2.6      /* Command FIFO */
     2.7 -    uint8_t fifo[FD_SECTOR_LEN];
     2.8 +    uint8_t *fifo;
     2.9      uint32_t data_pos;
    2.10      uint32_t data_len;
    2.11      uint8_t data_state;
    2.12 @@ -497,6 +497,11 @@ fdctrl_t *fdctrl_init (int irq_lvl, int 
    2.13      fdctrl = qemu_mallocz(sizeof(fdctrl_t));
    2.14      if (!fdctrl)
    2.15          return NULL;
    2.16 +    fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
    2.17 +    if (fdctrl->fifo == NULL) {
    2.18 +        qemu_free(fdctrl);
    2.19 +        return NULL;
    2.20 +    }
    2.21      fdctrl->result_timer = qemu_new_timer(vm_clock, 
    2.22                                            fdctrl_result_timer, fdctrl);
    2.23  
     3.1 --- a/tools/ioemu/hw/ide.c	Thu Feb 14 09:24:35 2008 +0000
     3.2 +++ b/tools/ioemu/hw/ide.c	Thu Feb 14 09:26:38 2008 +0000
     3.3 @@ -2306,7 +2306,7 @@ static void ide_init2(IDEState *ide_stat
     3.4  
     3.5      for(i = 0; i < 2; i++) {
     3.6          s = ide_state + i;
     3.7 -        s->io_buffer = memalign(getpagesize(), MAX_MULT_SECTORS*512 + 4);
     3.8 +        s->io_buffer = qemu_memalign(getpagesize(), MAX_MULT_SECTORS*512 + 4);
     3.9          if (i == 0)
    3.10              s->bs = hd0;
    3.11          else
     4.1 --- a/tools/ioemu/hw/scsi-disk.c	Thu Feb 14 09:24:35 2008 +0000
     4.2 +++ b/tools/ioemu/hw/scsi-disk.c	Thu Feb 14 09:26:38 2008 +0000
     4.3 @@ -81,7 +81,7 @@ static SCSIRequest *scsi_new_request(SCS
     4.4          free_requests = r->next;
     4.5      } else {
     4.6          r = qemu_malloc(sizeof(SCSIRequest));
     4.7 -	r->dma_buf = memalign(getpagesize(), SCSI_DMA_BUF_SIZE);
     4.8 +	r->dma_buf = qemu_memalign(getpagesize(), SCSI_DMA_BUF_SIZE);
     4.9      }
    4.10      r->dev = s;
    4.11      r->tag = tag;
     5.1 --- a/tools/ioemu/osdep.c	Thu Feb 14 09:24:35 2008 +0000
     5.2 +++ b/tools/ioemu/osdep.c	Thu Feb 14 09:26:38 2008 +0000
     5.3 @@ -61,6 +61,10 @@ void *qemu_malloc(size_t size)
     5.4  }
     5.5  
     5.6  #if defined(_WIN32)
     5.7 +void *qemu_memalign(size_t alignment, size_t size)
     5.8 +{
     5.9 +    return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
    5.10 +}
    5.11  
    5.12  void *qemu_vmalloc(size_t size)
    5.13  {
    5.14 @@ -172,6 +176,22 @@ void kqemu_vfree(void *ptr)
    5.15  
    5.16  #endif
    5.17  
    5.18 +void *qemu_memalign(size_t alignment, size_t size)
    5.19 +{
    5.20 +#if defined(_POSIX_C_SOURCE)
    5.21 +    int ret;
    5.22 +    void *ptr;
    5.23 +    ret = posix_memalign(&ptr, alignment, size);
    5.24 +    if (ret != 0)
    5.25 +        return NULL;
    5.26 +    return ptr;
    5.27 +#elif defined(_BSD)
    5.28 +    return valloc(size);
    5.29 +#else
    5.30 +    return memalign(alignment, size);
    5.31 +#endif
    5.32 +}
    5.33 +
    5.34  /* alloc shared memory pages */
    5.35  void *qemu_vmalloc(size_t size)
    5.36  {
     6.1 --- a/tools/ioemu/osdep.h	Thu Feb 14 09:24:35 2008 +0000
     6.2 +++ b/tools/ioemu/osdep.h	Thu Feb 14 09:26:38 2008 +0000
     6.3 @@ -14,6 +14,7 @@ void *qemu_mallocz(size_t size);
     6.4  void qemu_free(void *ptr);
     6.5  char *qemu_strdup(const char *str);
     6.6  
     6.7 +void *qemu_memalign(size_t alignment, size_t size);
     6.8  void *qemu_vmalloc(size_t size);
     6.9  void qemu_vfree(void *ptr);
    6.10