if (model->getMetadata()->getProgramSize() > 0) {
HWmem * hwmem_prog = new HWmem (new HWmemDevice);
hwmem_prog->setDriverAPI (api_.get());
+ hwmem_prog->setContiguous (true);
model->setProgramData (hwmem_prog);
/** @brief HWmem constructor */
HWmem::HWmem (const HWmemImpl* impl)
: impl_ (impl), api_ (nullptr), dmabuf_ (-1), base_addr_ (nullptr),
- offset_ (0), size_ (0), parent_ (nullptr)
+ offset_ (0), size_ (0), contiguous_(false), parent_ (nullptr)
{
}
}
if (hwmem->getDmabuf () >= 0) {
- hwmem->getDriverAPI()->dealloc (hwmem->getDmabuf ());
+ hwmem->getDriverAPI()->dealloc (hwmem->getDmabuf (), hwmem->isContiguous());
hwmem->setDmabuf (-1);
hwmem->setSize (0);
return -EBUSY;
}
- int dmabuf = hwmem->getDriverAPI()->alloc (ALIGNED_SIZE (size));
+ int dmabuf = hwmem->getDriverAPI()->alloc (ALIGNED_SIZE (size),
+ hwmem->isContiguous());
if (dmabuf < 0)
return dmabuf;
if (hwmem->getDmabuf() < 0)
return -EINVAL;
- hwmem->getDriverAPI()->dealloc (hwmem->getDmabuf());
+ hwmem->getDriverAPI()->dealloc (hwmem->getDmabuf(), hwmem->isContiguous());
hwmem->setDmabuf (-1);
hwmem->setSize (0);
return 0;
void *getBaseAddr () const { return base_addr_; }
HWmem *getParent () const { return parent_; }
bool isExternal () const { return nullptr != dynamic_cast<const HWmemExternal *>(impl_); }
+ bool isContiguous () const { return contiguous_; }
/** set private member variables */
void setDriverAPI (const DriverAPI* api) { api_ = api; }
void setOffset (size_t offset) { offset_ = offset; }
void setBaseAddr (void *base_addr) { base_addr_ = base_addr; }
void setParent (HWmem *hwmem) { parent_ = hwmem; }
+ void setContiguous (bool contiguous) { contiguous_ = contiguous; }
/** the below APIs require its HWmem impl. */
char *getData ();
size_t offset_; /**< offset of hwmem (starting from base address) */
size_t size_; /**< size of hwmem */
+ bool contiguous_; /**< Force physically-contiguous mapping (no iommu) */
+
HWmem *parent_; /**< optional. used only for HWmemChunk */
};
virtual uint32_t numRequests () const { return 0; }
/** @brief allocate memory with the given size. return dmabuf fd */
- virtual int alloc (size_t size) const { return -EPERM; }
+ virtual int alloc (size_t size, bool contiguous = false) const { return -EPERM; }
/** @brief deallocate memory with the corresponding dmabuf fd */
- virtual int dealloc (int dmabuf) const { return -EPERM; }
+ virtual int dealloc (int dmabuf, bool contiguous = false) const { return -EPERM; }
/** @brief get memory status */
virtual int getMemoryStatus (size_t *alloc, size_t *free) const { return -EPERM; }
device_state_t isReady () const;
uint32_t numRequests () const;
- int alloc (size_t size) const;
- int dealloc (int dmabuf) const;
+ int alloc (size_t size, bool contiguous) const;
+ int dealloc (int dmabuf, bool contiguous) const;
int getMemoryStatus (size_t *alloc, size_t *free) const;
void *mmap (int dmabuf, size_t size) const;
int open ();
device_state_t isReady () const;
- int alloc (size_t size) const;
- int dealloc (int dmabuf) const;
+ int alloc (size_t size, bool contiguous) const;
+ int dealloc (int dmabuf, bool contiguous) const;
int getMemoryStatus (size_t *alloc_total, size_t *free_total) const;
void *mmap (int dmabuf, size_t size) const;
/**
* @brief allocate memory with the given size
* @param[in] size the memory size
+ * @param[in] contiguous contiguous mapping; don't care in emulation
* @return dmabuf fd (>= 0) if no error. otherwise a negative errno.
*/
int
-TrinityEmulAPI::alloc (size_t size) const
+TrinityEmulAPI::alloc (size_t size, bool contiguous) const
{
if (!initialized())
return -EPERM;
/**
* @brief deallocate memory with the corresponding dmabuf fd
* @param[in] dmabuf the dmabuf fd to be deallocated
+ * @param[in] contiguous contiguous mapping; don't care in emulation
* @return 0 if no error. otherwise a negative errno.
*/
int
-TrinityEmulAPI::dealloc (int dmabuf) const
+TrinityEmulAPI::dealloc (int dmabuf, bool contiguous) const
{
if (!initialized())
return -EPERM;
/**
* @brief allocate memory with the given size
* @param[in] size the memory size
+ * @param[in] contiguous contiguous mapping
* @return dmabuf fd (>= 0) if no error. otherwise a negative errno.
*/
int
-TrinityVision2API::alloc (size_t size) const
+TrinityVision2API::alloc (size_t size, bool contiguous) const
{
+ struct trinity_ioctl_hwmem hwmem;
int ret;
if (!this->initialized())
return -EPERM;
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_ALLOC, &size);
+ hwmem.type = contiguous ? HWMEM_DMA_CONT : HWMEM_DMA_IOMMU;
+ hwmem.size = size;
+
+ ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_ALLOC, &hwmem);
if (ret < 0)
return -errno;
/**
* @brief deallocate memory with the corresponding dmabuf fd
* @param[in] dmabuf the dmabuf fd to be deallocated
+ * @param[in] contiguous contiguous mapping
* @return 0 if no error. otherwise a negative errno.
*/
int
-TrinityVision2API::dealloc (int dmabuf) const
+TrinityVision2API::dealloc (int dmabuf, bool contiguous) const
{
+ struct trinity_ioctl_hwmem hwmem;
int ret;
if (!this->initialized())
return -EPERM;
- ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_DEALLOC, &dmabuf);
+ hwmem.type = contiguous ? HWMEM_DMA_CONT : HWMEM_DMA_IOMMU;
+ hwmem.dbuf_fd = dmabuf;
+
+ ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_HWMEM_DEALLOC, &hwmem);
if (ret < 0)
return -errno;