Skip to content

Commit

Permalink
Fix #281, cleanup memory range table
Browse files Browse the repository at this point in the history
A number of cleanup items related to the PSP memory range API

- Make the table itself an internal object - should only be accessed
via the PSP API.
- Update to use size_t instead of uint32
- Update the Linux/RTEMS implementation to use full range (SIZE_MAX).
  • Loading branch information
jphickey committed Mar 29, 2021
1 parent 73366d4 commit 42f0914
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 70 deletions.
18 changes: 3 additions & 15 deletions fsw/inc/cfe_psp.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,6 @@
** Type Definitions
*/

/*
** Memory table type
*/
typedef struct
{
uint32 MemoryType;
uint32 WordSize;
cpuaddr StartAddr;
uint32 Size;
uint32 Attributes;
} CFE_PSP_MemTable_t;

/*
** Function prototypes
*/
Expand Down Expand Up @@ -394,11 +382,11 @@ int32 CFE_PSP_MemWrite32(cpuaddr MemoryAddress, uint32 uint32Value);
int32 CFE_PSP_MemCpy(void *dest, const void *src, uint32 n);
int32 CFE_PSP_MemSet(void *dest, uint8 value, uint32 n);

int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType);
int32 CFE_PSP_MemValidateRange(cpuaddr Address, size_t Size, uint32 MemoryType);
uint32 CFE_PSP_MemRanges(void);
int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, uint32 Size, uint32 WordSize,
int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, size_t Size, size_t WordSize,
uint32 Attributes);
int32 CFE_PSP_MemRangeGet(uint32 RangeNum, uint32 *MemoryType, cpuaddr *StartAddr, uint32 *Size, uint32 *WordSize,
int32 CFE_PSP_MemRangeGet(uint32 RangeNum, uint32 *MemoryType, cpuaddr *StartAddr, size_t *Size, size_t *WordSize,
uint32 *Attributes);

int32 CFE_PSP_EepromWrite8(cpuaddr MemoryAddress, uint8 ByteValue);
Expand Down
14 changes: 3 additions & 11 deletions fsw/inc/cfe_psp_configdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ typedef const struct
*/
typedef const struct
{
uint32 PSP_WatchdogMin; /**< PSP Minimum watchdog in milliseconds */
uint32 PSP_WatchdogMax; /**< PSP Maximum watchdog in milliseconds */
uint32 PSP_MemTableSize; /**< Size of PSP memory table */
uint32 PSP_ExceptionLogSize; /**< Size of PSP exception log */
CFE_PSP_MemTable_t *PSP_MemoryTable; /**< Pointer to PSP memory table (forward reference) */
uint32 PSP_WatchdogMin; /**< PSP Minimum watchdog in milliseconds */
uint32 PSP_WatchdogMax; /**< PSP Maximum watchdog in milliseconds */
uint32 PSP_ExceptionLogSize; /**< Size of PSP exception log */

/**
* Number of EEPROM banks on this platform
Expand All @@ -77,10 +75,4 @@ typedef const struct
*/
extern Target_PspConfigData GLOBAL_PSP_CONFIGDATA;

/**
* Extern reference to the psp memory table
* Allows the actual instantiation to be done outside this module
*/
extern CFE_PSP_MemTable_t CFE_PSP_MemoryTable[];

#endif /* CFE_PSP_CONFIG_H_ */
11 changes: 11 additions & 0 deletions fsw/mcp750-vxworks/src/cfe_psp_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
extern unsigned int GetWrsKernelTextStart(void);
extern unsigned int GetWrsKernelTextEnd(void);

/*
* The system memory table is instantiated in a separate file cfe_psp_memtab.c
*/
extern CFE_PSP_MemTable_t MCP750_MemoryTable[];

/*
** Global variables
*/
Expand Down Expand Up @@ -408,6 +413,12 @@ void CFE_PSP_SetupReservedMemoryMap(void)

OS_printf("CFE_PSP: MCP750 Reserved Memory Block at 0x%08lx, Total Size = 0x%lx\n",
(unsigned long)MCP750_ReservedMemBlock.BlockPtr, (unsigned long)MCP750_ReservedMemBlock.BlockSize);

/*
* Set up pointer to system memory table
*/
CFE_PSP_ReservedMemoryMap.SysMemoryTable = MCP750_MemoryTable;
CFE_PSP_ReservedMemoryMap.SysMemoryTableSize = CFE_PSP_MEM_TABLE_SIZE;
}

/******************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion fsw/mcp750-vxworks/src/cfe_psp_memtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
#include "common_types.h"
#include "cfe_psp.h"
#include "cfe_psp_config.h"
#include "cfe_psp_memory.h"

/*
** Valid memory map for this target.
** If you need to add more entries, increase CFE_PSP_MEM_TABLE_SIZE in the osconfig.h file.
*/
CFE_PSP_MemTable_t CFE_PSP_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = {
CFE_PSP_MemTable_t MCP750_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = {
{CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, 0x8000000, CFE_PSP_MEM_ATTR_READWRITE},
{CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE},
{CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE},
Expand Down
11 changes: 11 additions & 0 deletions fsw/pc-linux/src/cfe_psp_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ void CFE_PSP_InitUserReservedArea(void);
extern unsigned int _init;
extern unsigned int _fini;

/*
* The system memory table is instantiated in a separate file cfe_psp_memtab.c
*/
extern CFE_PSP_MemTable_t PcLinux_MemoryTable[];

/*
** Global variables
*/
Expand Down Expand Up @@ -674,6 +679,12 @@ void CFE_PSP_SetupReservedMemoryMap(void)
CFE_PSP_InitResetArea();
CFE_PSP_InitVolatileDiskMem();
CFE_PSP_InitUserReservedArea();

/*
* Set up pointer to system memory table
*/
CFE_PSP_ReservedMemoryMap.SysMemoryTable = PcLinux_MemoryTable;
CFE_PSP_ReservedMemoryMap.SysMemoryTableSize = CFE_PSP_MEM_TABLE_SIZE;
}

int32 CFE_PSP_InitProcessorReservedMemory(uint32 RestartType)
Expand Down
5 changes: 3 additions & 2 deletions fsw/pc-linux/src/cfe_psp_memtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
#include "osapi.h"
#include "cfe_psp.h"
#include "cfe_psp_config.h"
#include "cfe_psp_memory.h"

/*
** Valid memory map for this target.
** If you need to add more entries, increase CFE_PSP_MEM_TABLE_SIZE in the osconfig.h file.
*/
CFE_PSP_MemTable_t CFE_PSP_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = {
{CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, 0xFFFFFFFF, CFE_PSP_MEM_ATTR_READWRITE},
CFE_PSP_MemTable_t PcLinux_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = {
{CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, SIZE_MAX, CFE_PSP_MEM_ATTR_READWRITE},
{CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE},
{CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE},
{CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE},
Expand Down
11 changes: 11 additions & 0 deletions fsw/pc-rtems/src/cfe_psp_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ typedef struct
** External Declarations
*/

/*
* The system memory table is instantiated in a separate file cfe_psp_memtab.c
*/
extern CFE_PSP_MemTable_t PcRtems_MemoryTable[];

/*
** Global variables
*/
Expand Down Expand Up @@ -418,6 +423,12 @@ void CFE_PSP_SetupReservedMemoryMap(void)
* (prefer this over removing the increment, as it is safer if another block is added)
*/
OS_printf("CFE_PSP: PSP reserved memory ends at: 0x%08lX\n", (unsigned long)ReservedMemoryAddr);

/*
* Set up pointer to system memory table
*/
CFE_PSP_ReservedMemoryMap.SysMemoryTable = PcRtems_MemoryTable;
CFE_PSP_ReservedMemoryMap.SysMemoryTableSize = CFE_PSP_MEM_TABLE_SIZE;
}

/******************************************************************************
Expand Down
5 changes: 3 additions & 2 deletions fsw/pc-rtems/src/cfe_psp_memtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
#include "osapi.h"
#include "cfe_psp.h"
#include "cfe_psp_config.h"
#include "cfe_psp_memory.h"

/*
** Valid memory map for this target.
** If you need to add more entries, increase CFE_PSP_MEM_TABLE_SIZE in the osconfig.h file.
*/
CFE_PSP_MemTable_t CFE_PSP_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = {
{CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, 0xFFFFFFFF, CFE_PSP_MEM_ATTR_READWRITE},
CFE_PSP_MemTable_t PcRtems_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = {
{CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, SIZE_MAX, CFE_PSP_MEM_ATTR_READWRITE},
{CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE},
{CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE},
{CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE},
Expand Down
22 changes: 22 additions & 0 deletions fsw/shared/inc/cfe_psp_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
#include "cfe_psp_config.h"
#include "cfe_psp_exceptionstorage_types.h"

/*
** Memory table type
*/
typedef struct
{
uint32 MemoryType;
size_t WordSize;
cpuaddr StartAddr;
size_t Size;
uint32 Attributes;
} CFE_PSP_MemTable_t;

typedef struct
{
void * BlockPtr;
Expand All @@ -58,6 +70,16 @@ typedef struct
CFE_PSP_MemoryBlock_t VolatileDiskMemory;
CFE_PSP_MemoryBlock_t CDSMemory;
CFE_PSP_MemoryBlock_t UserReservedMemory;

/**
* \brief The system memory table
*
* This is the table used for CFE_PSP_MemRangeGet/Set and related ops
* that allow CFE applications to query the general system memory map.
*/
CFE_PSP_MemTable_t *SysMemoryTable;
size_t SysMemoryTableSize;

} CFE_PSP_ReservedMemoryMap_t;

/**
Expand Down
6 changes: 2 additions & 4 deletions fsw/shared/src/cfe_psp_configdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
* code such as CFE core or apps would not be able to \#include the
* PSP cfe_psp_config.h or psp_version.h files
*/
Target_PspConfigData GLOBAL_PSP_CONFIGDATA = {.PSP_WatchdogMin = CFE_PSP_WATCHDOG_MIN,
.PSP_WatchdogMax = CFE_PSP_WATCHDOG_MAX,
.PSP_MemTableSize = CFE_PSP_MEM_TABLE_SIZE,
.PSP_MemoryTable = CFE_PSP_MemoryTable,
Target_PspConfigData GLOBAL_PSP_CONFIGDATA = {.PSP_WatchdogMin = CFE_PSP_WATCHDOG_MIN,
.PSP_WatchdogMax = CFE_PSP_WATCHDOG_MAX,

.HW_NumEepromBanks = CFE_PSP_NUM_EEPROM_BANKS,

Expand Down
73 changes: 39 additions & 34 deletions fsw/shared/src/cfe_psp_memrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@
*/

#include "cfe_psp.h"

/*
* The "extern" declaration for the MemRange table is in the configdata header
*/
#include "cfe_psp_config.h"
#include "cfe_psp_configdata.h"
#include "cfe_psp_memory.h"

/*
** Name: CFE_PSP_MemValidateRange
Expand Down Expand Up @@ -68,15 +63,16 @@
** CFE_PSP_INVALID_MEM_RANGE -- The Memory range associated with the address is not large enough to contain
** Address + Size.
*/
int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType)
int32 CFE_PSP_MemValidateRange(cpuaddr Address, size_t Size, uint32 MemoryType)
{
cpuaddr StartAddressToTest = Address;
cpuaddr EndAddressToTest = Address + Size - 1;
cpuaddr StartAddressInTable;
cpuaddr EndAddressInTable;
uint32 TypeInTable;
int32 ReturnCode = CFE_PSP_INVALID_MEM_ADDR;
uint32 i;
cpuaddr StartAddressToTest = Address;
cpuaddr EndAddressToTest = Address + Size - 1;
cpuaddr StartAddressInTable;
cpuaddr EndAddressInTable;
uint32 TypeInTable;
int32 ReturnCode = CFE_PSP_INVALID_MEM_ADDR;
size_t i;
CFE_PSP_MemTable_t *SysMemPtr;

/*
** Before searching table, do a preliminary parameter validation
Expand All @@ -91,16 +87,17 @@ int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType)
return (CFE_PSP_INVALID_MEM_RANGE);
}

for (i = 0; i < CFE_PSP_MEM_TABLE_SIZE; i++)
SysMemPtr = CFE_PSP_ReservedMemoryMap.SysMemoryTable;
for (i = 0; i < CFE_PSP_ReservedMemoryMap.SysMemoryTableSize; ++i)
{
/*
** Only look at valid memory table entries
*/
if (CFE_PSP_MemoryTable[i].MemoryType != CFE_PSP_MEM_INVALID)
if (SysMemPtr->MemoryType != CFE_PSP_MEM_INVALID)
{
StartAddressInTable = CFE_PSP_MemoryTable[i].StartAddr;
EndAddressInTable = CFE_PSP_MemoryTable[i].StartAddr + CFE_PSP_MemoryTable[i].Size - 1;
TypeInTable = CFE_PSP_MemoryTable[i].MemoryType;
StartAddressInTable = SysMemPtr->StartAddr;
EndAddressInTable = SysMemPtr->StartAddr + SysMemPtr->Size - 1;
TypeInTable = SysMemPtr->MemoryType;

/*
** Step 1: Get the Address to Fit within the range
Expand Down Expand Up @@ -152,6 +149,8 @@ int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType)
}
} /* End if MemoryType != CFE_PSP_MEM_INVALID */

++SysMemPtr;

} /* End for */
return (ReturnCode);
}
Expand All @@ -176,7 +175,7 @@ int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType)
*/
uint32 CFE_PSP_MemRanges(void)
{
return (CFE_PSP_MEM_TABLE_SIZE);
return (CFE_PSP_ReservedMemoryMap.SysMemoryTableSize);
}

/*
Expand Down Expand Up @@ -215,11 +214,12 @@ uint32 CFE_PSP_MemRanges(void)
** CFE_PSP_INVALID_MEM_WORDSIZE -- The WordSIze parameter is not one of the predefined types.
** CFE_PSP_INVALID_MEM_ATTR -- The Attributes parameter is not one of the predefined types.
*/
int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, uint32 Size, uint32 WordSize,
int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, size_t Size, size_t WordSize,
uint32 Attributes)
{
CFE_PSP_MemTable_t *SysMemPtr;

if (RangeNum >= CFE_PSP_MEM_TABLE_SIZE)
if (RangeNum >= CFE_PSP_ReservedMemoryMap.SysMemoryTableSize)
{
return (CFE_PSP_INVALID_MEM_RANGE);
}
Expand All @@ -244,11 +244,13 @@ int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr,
/*
** Parameters check out, add the range
*/
CFE_PSP_MemoryTable[RangeNum].MemoryType = MemoryType;
CFE_PSP_MemoryTable[RangeNum].StartAddr = StartAddr;
CFE_PSP_MemoryTable[RangeNum].Size = Size;
CFE_PSP_MemoryTable[RangeNum].WordSize = WordSize;
CFE_PSP_MemoryTable[RangeNum].Attributes = Attributes;
SysMemPtr = &CFE_PSP_ReservedMemoryMap.SysMemoryTable[RangeNum];

SysMemPtr->MemoryType = MemoryType;
SysMemPtr->StartAddr = StartAddr;
SysMemPtr->Size = Size;
SysMemPtr->WordSize = WordSize;
SysMemPtr->Attributes = Attributes;

return (CFE_PSP_SUCCESS);
}
Expand Down Expand Up @@ -284,25 +286,28 @@ int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr,
** CFE_PSP_INVALID_POINTER -- Parameter error
** CFE_PSP_INVALID_MEM_RANGE -- The index into the table is invalid
*/
int32 CFE_PSP_MemRangeGet(uint32 RangeNum, uint32 *MemoryType, cpuaddr *StartAddr, uint32 *Size, uint32 *WordSize,
int32 CFE_PSP_MemRangeGet(uint32 RangeNum, uint32 *MemoryType, cpuaddr *StartAddr, size_t *Size, size_t *WordSize,
uint32 *Attributes)
{
CFE_PSP_MemTable_t *SysMemPtr;

if (MemoryType == NULL || StartAddr == NULL || Size == NULL || WordSize == NULL || Attributes == NULL)
{
return (CFE_PSP_INVALID_POINTER);
}

if (RangeNum >= CFE_PSP_MEM_TABLE_SIZE)
if (RangeNum >= CFE_PSP_ReservedMemoryMap.SysMemoryTableSize)
{
return (CFE_PSP_INVALID_MEM_RANGE);
}

*MemoryType = CFE_PSP_MemoryTable[RangeNum].MemoryType;
*StartAddr = CFE_PSP_MemoryTable[RangeNum].StartAddr;
*Size = CFE_PSP_MemoryTable[RangeNum].Size;
*WordSize = CFE_PSP_MemoryTable[RangeNum].WordSize;
*Attributes = CFE_PSP_MemoryTable[RangeNum].Attributes;
SysMemPtr = &CFE_PSP_ReservedMemoryMap.SysMemoryTable[RangeNum];

*MemoryType = SysMemPtr->MemoryType;
*StartAddr = SysMemPtr->StartAddr;
*Size = SysMemPtr->Size;
*WordSize = SysMemPtr->WordSize;
*Attributes = SysMemPtr->Attributes;

return (CFE_PSP_SUCCESS);
}
2 changes: 1 addition & 1 deletion ut-stubs/ut_psp_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ int32 CFE_PSP_MemRead8(cpuaddr Address, uint8 *Data)
** Returns either a user-defined status flag or OS_SUCCESS.
**
******************************************************************************/
int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType)
int32 CFE_PSP_MemValidateRange(cpuaddr Address, size_t Size, uint32 MemoryType)
{
int32 status;

Expand Down

0 comments on commit 42f0914

Please sign in to comment.