diff --git a/qnx/src/ipc3x_dev/ti/syslink/resources/RscTable.c b/qnx/src/ipc3x_dev/ti/syslink/resources/RscTable.c
index 90cbf6dfaff7fae02c964eb8c1bd8bd52889de65..ba812c2867495ac564d7f2d2ace9cb1bdf9d8263 100644 (file)
*
* ============================================================================
*
- * Copyright (c) 2012, Texas Instruments Incorporated
+ * Copyright (c) 2012-2014, Texas Instruments Incorporated
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
UInt32 size;
} Carveout_Elem;
-typedef struct Carveout_Object_tag {
- UInt32 addr;
- UInt32 size;
- List_Handle freeBlocks;
-} Carveout_Object;
-
/*!
* @brief RscTable Header
*/
/*!< Resource table length. */
UInt32 rscTableDA;
/*!< Resource table device address. */
- Carveout_Object * carveout[SYSLINK_MAX_MEMENTRIES];
- /*!< Carveouts for this table. */
- UInt32 numCarveouts;
- /*!< Carveouts for this table. */
SysLink_MemEntry memEntries[SYSLINK_MAX_MEMENTRIES];
/*!< Memory Entries for the remote processor. */
UInt32 numMemEntries;
return (RscTable_Handle)obj;
}
-/* Helper functions for processing carveout */
-Int Carveout_register (RscTable_Object *obj, UInt32 id, Ptr carveOut,
- UInt32 carveOutLen)
-{
- Int status = 0;
- Carveout_Object * cout = NULL;
- List_Params params;
-
- cout = Memory_alloc(NULL, sizeof(Carveout_Object), 0, NULL);
- if (cout) {
- cout->addr = (UInt32)carveOut;
- cout->size = carveOutLen;
- List_Params_init(¶ms);
- cout->freeBlocks = List_create(¶ms);
- if (cout->freeBlocks == NULL) {
- status = RSCTABLE_E_MEMORY;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_register",
- status,
- "Unable to create free list");
- Memory_free(NULL, cout, sizeof(Carveout_Object));
- cout = NULL;
- }
- else {
- // Add the whole of the memory to the free list
- Carveout_Elem * elem = Memory_alloc(NULL, sizeof(Carveout_Elem),
- 0, NULL);
- if (elem) {
- elem->addr = cout->addr;
- elem->size = cout->size;
- List_put(cout->freeBlocks, (List_Elem *)elem);
- }
- else {
- status = RSCTABLE_E_MEMORY;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_register",
- status,
- "Unable to allocate elem");
- List_delete(&cout->freeBlocks);
- Memory_free(NULL, cout, sizeof(Carveout_Object));
- cout = NULL;
- }
- }
- }
- else {
- status = RSCTABLE_E_MEMORY;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_register",
- status,
- "Unable to allocate carveout structure");
- }
-
- obj->carveout[id] = cout;
- obj->numCarveouts++;
- return status;
-}
-
-Int Carveout_unregister (RscTable_Object *obj, UInt32 id)
-{
- Int status = 0;
- List_Elem * elem = NULL;
-
- if (obj->carveout[id]) {
- if (obj->carveout[id]->freeBlocks) {
- while ((elem = List_get(obj->carveout[id]->freeBlocks)))
- Memory_free(NULL, elem, sizeof(Carveout_Elem));
- List_delete(&obj->carveout[id]->freeBlocks);
- }
-
- Memory_free(NULL, obj->carveout[id], sizeof(Carveout_Object));
- obj->carveout[id] = NULL;
- obj->numCarveouts--;
- }
- else {
- status = RSCTABLE_E_INVALIDARG;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_unregister",
- status,
- "No carveout associated with obj");
- }
-
- return status;
-}
-
// allocate any addr
Int Chunk_allocate (RscTable_Object *obj, UInt32 size, UInt32 * pa)
{
return status;
}
-// allocate any addr from a specified carveout
-Int Carveout_allocate (RscTable_Object *obj, UInt32 size, UInt32 * pa)
-{
- Int status = 0;
- Carveout_Object * cout = NULL;
- List_Elem * elem = NULL;
- Bool found = FALSE;
- UInt i = 0;
-
- if (!pa || !obj || !obj->numCarveouts) {
- status = RSCTABLE_E_INVALIDARG;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_allocate",
- status,
- "Invalid arg passed");
- }
- else {
- for (i = 0; i < obj->numCarveouts; i++) {
- *pa = 0;
- cout = obj->carveout[i];
-
- // search for a free block with sufficient size
- List_traverse(elem, cout->freeBlocks) {
- if (((Carveout_Elem *)elem)->size >= size) {
- found = TRUE;
- break;
- }
- }
- if (found) {
- UInt32 rem = 0;
- UInt32 addr = 0;
-
- // found a spot for our request
- addr = ((Carveout_Elem *)elem)->addr;
- rem = ((Carveout_Elem *)elem)->size - size;
- if (rem) {
- ((Carveout_Elem *)elem)->addr += size;
- ((Carveout_Elem *)elem)->size = rem;
- }
- else {
- List_remove(cout->freeBlocks, elem);
- Memory_free (NULL, elem, sizeof(Carveout_Elem));
- }
- *pa = addr;
- break;
- }
- }
- if (i == obj->numCarveouts) {
- status = RSCTABLE_E_MEMORY;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_allocate",
- status,
- "Not enough room in carveout");
- }
- }
- return status;
-}
-
-// allocate specific addr
-Int Carveout_reserve (RscTable_Object *obj, UInt32 size, UInt32 pa)
-{
- Int status = 0;
- Carveout_Object * cout = NULL;
- List_Elem * elem = NULL;
- Bool found = FALSE;
- UInt i = 0;
-
- if (!pa || !obj || !obj->numCarveouts) {
- status = RSCTABLE_E_INVALIDARG;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_reserve",
- status,
- "Invalid arg passed");
- }
- else {
- for (i = 0; i < obj->numCarveouts; i++) {
- cout = obj->carveout[i];
-
- // search for a free block with sufficient size
- List_traverse(elem, cout->freeBlocks) {
- if ((((Carveout_Elem *)elem)->addr <= pa) &&
- ((((Carveout_Elem *)elem)->addr +
- ((Carveout_Elem *)elem)->size) >= (pa + size))) {
- found = TRUE;
- break;
- }
- }
- if (found) {
- UInt32 rem_start = 0;
- UInt32 rem_end = 0;
-
- // found a spot for our request
- if (((Carveout_Elem *)elem)->addr < pa) {
- // there is free mem at the beginning of the block
- rem_start = pa - ((Carveout_Elem *)elem)->addr;
- }
- if (((Carveout_Elem *)elem)->addr + ((Carveout_Elem *)elem)->size >
- (pa + size)) {
- // there is free mem at the end of the block
- rem_end = ((Carveout_Elem *)elem)->addr +
- ((Carveout_Elem *)elem)->size - (pa + size);
- }
- // now carve up the block
- if (rem_start) {
- ((Carveout_Elem *)elem)->size = rem_start;
- }
- else if (rem_end) {
- ((Carveout_Elem *)elem)->size = rem_end;
- ((Carveout_Elem *)elem)->addr = pa + size;
- }
- else {
- List_remove(cout->freeBlocks, elem);
- Memory_free (NULL, elem, sizeof(Carveout_Elem));
- }
- if (rem_start && rem_end) {
- Carveout_Elem * c_elem = NULL;
- c_elem = Memory_alloc (NULL, sizeof(Carveout_Elem), 0, NULL);
- if (c_elem) {
- c_elem->size = rem_end;
- c_elem->addr = pa + size;
- List_insert(cout->freeBlocks, (List_Elem *)&c_elem->elem,
- elem->next);
- }
- else {
- /* add mem back to free block */
- ((Carveout_Elem *)elem)->size += (size + rem_end);
- status = RSCTABLE_E_MEMORY;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_reserve",
- status,
- "Unable to allocate elem");
- }
- }
- break;
- }
- }
- if (i == obj->numCarveouts) {
- status = RSCTABLE_E_MEMORY;
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "Carveout_reserve",
- status,
- "Specified addr/size not available");
-
- }
- }
- return status;
-}
-
Int
-RscTable_process (UInt16 procId, Bool mmuEnabled, UInt32 numCarveouts,
- Ptr carveOut[], UInt32 carveOutLen[], Bool tryAlloc,
- UInt32 * numBlocks)
+RscTable_process (UInt16 procId, Bool tryAlloc, UInt32 * numBlocks)
{
Int status = 0;
Int ret = 0;
obj->numMemEntries = 0;
- // Register carveout mem regions if provided
- if (numCarveouts && carveOut && carveOutLen) {
- for (i = 0; i < numCarveouts; i++) {
- status = Carveout_register(obj, i, carveOut[i], carveOutLen[i]);
- if (status < 0) {
- GT_setFailureReason (curTrace,
- GT_4CLASS,
- "RscTable_process",
- status,
- "Carveout_register failed");
- return status;
- }
- }
- }
-
// TODO: Check the version
printf("RscTable_process: RscTable version is [%d]\n", table->ver);
// TODO: need to allocate this mem from carveout
struct fw_rsc_carveout * cout = (struct fw_rsc_carveout *)entry;
UInt32 pa = 0;
- if (cout->pa == 0)
- if (mmuEnabled)
- ret = Chunk_allocate (obj, cout->len, &pa);
- else {
- ret = Carveout_reserve (obj, cout->len, cout->da);
- pa = cout->da;
- }
- else
- ret = Carveout_reserve (obj, cout->len, cout->pa);
+ if (cout->pa == 0) {
+ ret = Chunk_allocate (obj, cout->len, &pa);
+ }
if (!ret) {
cout->pa = pa;
if (obj->numMemEntries == SYSLINK_MAX_MEMENTRIES) {
obj->memEntries[obj->numMemEntries].masterPhysAddr =
cout->pa;
obj->memEntries[obj->numMemEntries].size = cout->len;
- //if (mmuEnabled) {
- obj->memEntries[obj->numMemEntries].map = TRUE;
- obj->memEntries[obj->numMemEntries].mapMask =
- ProcMgr_SLAVEVIRT;
- //}
- //else
- // obj->memEntries[obj->numMemEntries].map = FALSE;
+ obj->memEntries[obj->numMemEntries].map = TRUE;
+ obj->memEntries[obj->numMemEntries].mapMask =
+ ProcMgr_SLAVEVIRT;
obj->memEntries[obj->numMemEntries].isCached = FALSE;
obj->memEntries[obj->numMemEntries].isValid = TRUE;
obj->numMemEntries++;
printf ("RscTable_process: carveout [%s] @ da [0x%08x] pa [0x%08x] len [0x%x]\n", cout->name, cout->da, cout->pa, cout->len);
break;
}
+ case TYPE_INTMEM :
+ {
+ struct fw_rsc_carveout * cout = (struct fw_rsc_carveout *)entry;
+
+ if (obj->numMemEntries == SYSLINK_MAX_MEMENTRIES) {
+ ret = -1;
+ }
+ else {
+ obj->memEntries[obj->numMemEntries].slaveVirtAddr =
+ cout->da;
+ obj->memEntries[obj->numMemEntries].masterPhysAddr =
+ cout->pa;
+ obj->memEntries[obj->numMemEntries].size = cout->len;
+ /* do not map to slave MMU */
+ obj->memEntries[obj->numMemEntries].map = FALSE;
+ obj->memEntries[obj->numMemEntries].mapMask =
+ ProcMgr_SLAVEVIRT;
+ obj->memEntries[obj->numMemEntries].isCached = FALSE;
+ obj->memEntries[obj->numMemEntries].isValid = TRUE;
+ obj->numMemEntries++;
+ }
+ printf ("RscTable_process: intmem [%s] @ da [0x%08x]"
+ " pa [0x%08x] len [0x%x]\n", cout->name, cout->da,
+ cout->pa, cout->len);
+ break;
+ }
case TYPE_DEVMEM :
{
// only care about mem in DDR for now
struct fw_rsc_devmem * dmem = (struct fw_rsc_devmem *)entry;
- UInt32 pa = 0;
if (dmem->pa >= DDR_MEM) {
// HACK: treat vring mem specially, vring is always the
// first devmem entry, may change in future
ret = -1;
}
- else if (obj->vringPa != dmem->pa &&
- (!tryAlloc || !mmuEnabled)) {
+ else if (obj->vringPa != dmem->pa && (!tryAlloc)) {
// defined pa does not match allocated pa, and
// either the mmu is disabled or the platform has
// not given permission to allocate on our own
dmem->pa = obj->vringPa;
}
}
- else {
- ret = Carveout_reserve (obj, dmem->len, dmem->pa);
- if (ret && mmuEnabled && tryAlloc) {
- ret = Carveout_allocate (obj, dmem->len, &pa);
- if (!ret) dmem->pa = pa;
- }
- }
}
if (!ret) {
if (obj->numMemEntries == SYSLINK_MAX_MEMENTRIES) {
obj->memEntries[obj->numMemEntries].masterPhysAddr =
dmem->pa;
obj->memEntries[obj->numMemEntries].size = dmem->len;
- //if (mmuEnabled) {
- obj->memEntries[obj->numMemEntries].map = TRUE;
- obj->memEntries[obj->numMemEntries].mapMask =
- ProcMgr_SLAVEVIRT;
- //}
- //else
- // obj->memEntries[obj->numMemEntries].map = FALSE;
+ obj->memEntries[obj->numMemEntries].map = TRUE;
+ obj->memEntries[obj->numMemEntries].mapMask =
+ ProcMgr_SLAVEVIRT;
obj->memEntries[obj->numMemEntries].isCached = FALSE;
obj->memEntries[obj->numMemEntries].isValid = TRUE;
obj->numMemEntries++;
vring = (struct fw_rsc_vdev_vring *)
((UInt32)vdev + sizeof(*vdev) +
(sizeof(*vring) * j));
+ /*
+ * Making a copy of original vring, given obj->vrings[j].da
+ * is used as slave virtual address in RscTable_getInfo(),
+ * and that is what the original vring definition contains.
+ */
Memory_copy (&obj->vrings[j], vring, sizeof (*vring));
printf ("RscTable_process: vring [%d] @ [0x%08x]\n",
vring->num, vring->da);
vr_size += ROUND_UP(MessageQCopy_RINGSIZE, 0x4000);
vr_bufs_size += (vring->num) * RPMSG_BUF_SIZE;
}
- if (!ret)
+ if (!ret) {
// HACK: round up to multiple of 1MB, because we know this
// is the size of the remote entry
- if (mmuEnabled)
- ret = Chunk_allocate(obj,
- ROUND_UP(vr_size + vr_bufs_size, 0x100000),
- &pa);
- else
- ret = Carveout_allocate(obj,
- ROUND_UP(vr_size + vr_bufs_size, 0x100000),
- &pa);
+ ret = Chunk_allocate(obj,
+ ROUND_UP(vr_size + vr_bufs_size, 0x100000),
+ &pa);
+ }
else if (obj->vrings) {
Memory_free (NULL, obj->vrings,
sizeof(*vring) * obj->numVrings);
obj->vringPa = pa;
obj->vringBufsPa = pa + vr_size;
+
+ /*
+ * Override the vring 'da' field in resource table.
+ * This allows the slave to look it up when creating
+ * the VirtQueues
+ */
+ for (j = 0; j < vdev->num_of_vrings; j++) {
+ vring = (struct fw_rsc_vdev_vring *)
+ ((UInt32)vdev + sizeof(*vdev) +
+ (sizeof(*vring) * j));
+ vring->da = obj->vringPa + (j *
+ vr_size / vdev->num_of_vrings);
+ }
}
break;
}
- case TYPE_CRASHDUMP :
- // what to do with this?
- break;
default :
break;
}
obj->numMemEntries = 0;
}
*numBlocks = obj->numMemEntries;
- // Can un-register the carveout now? Don't need it anymore?
- for (i = 0; i < numCarveouts; i++)
- Carveout_unregister(obj, i);
return status;
}