Exemple #1
0
/* Create a RAM device */
struct vdevice *dev_create_ram (vm_instance_t * vm, char *name, m_pa_t paddr,
    m_uint32_t len)
{
    struct vdevice *dev;

    if (!(dev = dev_create (name)))
        return NULL;

    dev->phys_addr = paddr;
    dev->phys_len = len;
    //dev->flags = VDEVICE_FLAG_CACHING;
    dev->host_addr = (m_iptr_t) m_memalign (4096, dev->phys_len);

    if (!dev->host_addr) {
        free (dev);
        return NULL;
    }

    vm_bind_device (vm, dev);
    return dev;
}
Exemple #2
0
/* Create a new chunk */
static vm_chunk_t *vm_chunk_create(vm_instance_t *vm)
{
   vm_chunk_t *chunk;
   size_t area_len;
   
   if (!(chunk = malloc(sizeof(*chunk))))
      return NULL;

   area_len = VM_CHUNK_AREA_SIZE * VM_PAGE_SIZE;

   if (!(chunk->area = m_memalign(VM_PAGE_SIZE,area_len))) {
      free(chunk);
      return NULL;
   }

   chunk->page_alloc = 0;
   chunk->page_total = VM_CHUNK_AREA_SIZE;

   chunk->next = vm->chunks;
   vm->chunks = chunk;
   return chunk;
}
/* Create a new MV64460 controller */
int dev_mv64460_init(vm_instance_t *vm,char *name,
                     m_uint64_t paddr,m_uint32_t len)
{
   struct mv64460_data *d;
   int i;

   if (!(d = malloc(sizeof(*d)))) {
      fprintf(stderr,"mv64460: unable to create device data.\n");
      return(-1);
   }

   memset(d,0,sizeof(*d));
   pthread_mutex_init(&d->lock,NULL);
   d->name = name;
   d->vm = vm;
   d->bus[0] = vm->pci_bus[0];
   d->bus[1] = vm->pci_bus[1];

   for(i=0;i<MV64460_SDMA_CHANNELS;i++)
      d->sdma[i].id = i;

   vm_object_init(&d->vm_obj);
   d->vm_obj.name = name;
   d->vm_obj.data = d;
   d->vm_obj.shutdown = (vm_shutdown_t)dev_mv64460_shutdown;

   dev_init(&d->dev);
   d->dev.name      = name;
   d->dev.priv_data = d;
   d->dev.phys_addr = paddr;
   d->dev.phys_len  = len;
   d->dev.handler   = dev_mv64460_access;

   /* Create the SRAM device */
   dev_init(&d->sram_dev);
   d->sram_dev.name = "mv64460_sram";
   d->sram_dev.phys_len = MV64460_SRAM_SIZE;
   d->sram_dev.flags = VDEVICE_FLAG_CACHING;
   d->sram_dev.host_addr = (m_iptr_t)m_memalign(4096,d->sram_dev.phys_len);

   if (!d->sram_dev.host_addr) {
      fprintf(stderr,"mv64460: unable to create SRAM data.\n");
      return(-1);
   }

   /* Add the controller as a PCI device */
   if (!pci_dev_lookup(d->bus[0],0,0,0)) {
      d->pci_dev = pci_dev_add(d->bus[0],name,
                               PCI_VENDOR_MARVELL,PCI_PRODUCT_MARVELL_MV64460,
                               0,0,-1,d,NULL,pci_mv64460_read,NULL);
      if (!d->pci_dev) {
         fprintf(stderr,"mv64460: unable to create PCI device.\n");
         return(-1);
      }
   }

   /* TEST */
   pci_dev_add(d->bus[1],name,
               PCI_VENDOR_MARVELL,PCI_PRODUCT_MARVELL_MV64460,
               0,0,-1,d,NULL,pci_mv64460_read,NULL);

   /* Map this device to the VM */
   vm_bind_device(vm,&d->dev);
   vm_object_add(vm,&d->vm_obj);
   return(0);
}