diff options
author | Evan Lojewski <github@meklort.com> | 2019-02-14 22:20:51 -0700 |
---|---|---|
committer | Evan Lojewski <github@meklort.com> | 2019-02-14 22:20:51 -0700 |
commit | 0f2310b6f63487ed2fd43d9147afa73bb58bf2ed (patch) | |
tree | 73ec67611c46bdf27aac7e6bb87ce003996c56cb /simulator | |
parent | 351f71e17c4529d1856863d2044949dfd23240fc (diff) | |
download | bcm5719-ortega-0f2310b6f63487ed2fd43d9147afa73bb58bf2ed.tar.gz bcm5719-ortega-0f2310b6f63487ed2fd43d9147afa73bb58bf2ed.zip |
Clean up the HAL code slightly.
Diffstat (limited to 'simulator')
-rw-r--r-- | simulator/HAL.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/simulator/HAL.cpp b/simulator/HAL.cpp index dbf4b30..a77d798 100644 --- a/simulator/HAL.cpp +++ b/simulator/HAL.cpp @@ -16,8 +16,13 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> + +#include <string> + +using namespace std; + #define DEVICE_CONFIG "config" -#define BAR_STR "resource%d" +#define BAR_STR "resource" #define ARRAY_ELEMENTS(__x__) (sizeof(__x__) / sizeof(__x__[0])) @@ -74,12 +79,18 @@ void initHAL(const char *pci_path) { struct stat st; int memfd; - char *pConfigPath = - (char *)malloc(strlen("%s/" DEVICE_CONFIG) + strlen(pci_path) + 1); - sprintf(pConfigPath, "%s/" DEVICE_CONFIG, pci_path); + + string configPath = string(pci_path) + string("/") + string(DEVICE_CONFIG); + const char* pConfigPath = configPath.c_str(); FILE *pConfigFile = fopen(pConfigPath, "rb"); + if(!pConfigFile) + { + fprintf(stderr, "Unable to open PCI configuration %p\n", pConfigPath); + exit(-1); + } + pci_config_t config; if (fread(&config, sizeof(config), 1, pConfigFile)) @@ -87,12 +98,11 @@ void initHAL(const char *pci_path) if (is_supported(config.vendor_id, config.device_id)) { printf("Found supported device %x:%x at %s\n", config.vendor_id, - config.device_id, pConfigPath); + config.device_id, configPath.c_str()); for (unsigned int i = 0; i < ARRAY_ELEMENTS(config.BAR); i++) { - char *pBARPath = (char *)malloc(strlen("%s/" BAR_STR) + - strlen(pci_path) + 1); - sprintf(pBARPath, "%s/" BAR_STR, pci_path, i); + string BARPath = string(pci_path) + "/" BAR_STR + to_string(i); + const char* pBARPath = BARPath.c_str(); if ((memfd = open(pBARPath, O_RDWR | O_SYNC)) < 0) { @@ -124,11 +134,7 @@ void initHAL(const char *pci_path) { i++; } - - free(pBARPath); } - - free(pConfigPath); } } |