summaryrefslogtreecommitdiffstats
path: root/simulator/HAL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'simulator/HAL.cpp')
-rw-r--r--simulator/HAL.cpp88
1 files changed, 43 insertions, 45 deletions
diff --git a/simulator/HAL.cpp b/simulator/HAL.cpp
index 4305dd8..77349ba 100644
--- a/simulator/HAL.cpp
+++ b/simulator/HAL.cpp
@@ -1,34 +1,29 @@
-#include <stdint.h>
+#include "../libs/NVRam/bcm5719_NVM.h"
+#include "pci_config.h"
+
+#include <bcm5719_DEVICE.h>
+#include <dirent.h>
+#include <endian.h>
+#include <errno.h>
+#include <fcntl.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-
#include <string.h>
-
-#include <sys/types.h>
-#include <dirent.h>
#include <sys/mman.h>
-
-#include <endian.h>
-
#include <sys/stat.h>
-#include <fcntl.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <errno.h>
-
-#include "pci_config.h"
-
-
-#include <bcm5719_DEVICE.h>
-#include "../libs/NVRam/bcm5719_NVM.h"
-#define DEVICE_CONFIG "config"
+#define DEVICE_CONFIG "config"
#define BAR_STR "resource%d"
-#define ARRAY_ELEMENTS(__x__) (sizeof(__x__)/sizeof(__x__[0]))
+#define ARRAY_ELEMENTS(__x__) (sizeof(__x__) / sizeof(__x__[0]))
-typedef struct {
- uint16_t vendor_id;
- uint16_t device_id;
+typedef struct
+{
+ uint16_t vendor_id;
+ uint16_t device_id;
} devices_t;
devices_t gSupportedDevices[] = {
@@ -37,11 +32,10 @@ devices_t gSupportedDevices[] = {
bool is_supported(uint16_t vendor_id, uint16_t device_id)
{
- for(unsigned int i = 0; i < ARRAY_ELEMENTS(gSupportedDevices); i++)
+ for (unsigned int i = 0; i < ARRAY_ELEMENTS(gSupportedDevices); i++)
{
devices_t *pDevice = &gSupportedDevices[i];
- if( vendor_id == pDevice->vendor_id &&
- device_id == pDevice->device_id)
+ if (vendor_id == pDevice->vendor_id && device_id == pDevice->device_id)
{
return true;
}
@@ -66,9 +60,8 @@ uint32_t get_bar_addr(uint32_t bar)
return (bar & BAR_ADDR_MASK);
}
-#define MAX_NUM_BARS 8
-uint8_t* bar[MAX_NUM_BARS] = {0};
-
+#define MAX_NUM_BARS 8
+uint8_t *bar[MAX_NUM_BARS] = {0};
uint32_t read_device_chipid(uint32_t)
{
@@ -76,29 +69,31 @@ uint32_t read_device_chipid(uint32_t)
return 1123;
}
-void initHAL(const char* pci_path)
+void initHAL(const char *pci_path)
{
struct stat st;
int memfd;
- char* pConfigPath = (char*)malloc(strlen("%s/" DEVICE_CONFIG) + strlen(pci_path) + 1);
+ char *pConfigPath =
+ (char *)malloc(strlen("%s/" DEVICE_CONFIG) + strlen(pci_path) + 1);
sprintf(pConfigPath, "%s/" DEVICE_CONFIG, pci_path);
- FILE* pConfigFile = fopen(pConfigPath, "rb");
+ FILE *pConfigFile = fopen(pConfigPath, "rb");
pci_config_t config;
- if(fread(&config, sizeof(config), 1, pConfigFile))
+ if (fread(&config, sizeof(config), 1, pConfigFile))
{
- if(is_supported(config.vendor_id, config.device_id))
+ 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);
- for(unsigned int i = 0; i < ARRAY_ELEMENTS(config.BAR); i++)
+ printf("Found supported device %x:%x at %s\n", config.vendor_id,
+ config.device_id, pConfigPath);
+ for (unsigned int i = 0; i < ARRAY_ELEMENTS(config.BAR); i++)
{
- char* pBARPath = (char*)malloc(strlen("%s/" BAR_STR) + strlen(pci_path) + 1);
+ char *pBARPath = (char *)malloc(strlen("%s/" BAR_STR) +
+ strlen(pci_path) + 1);
sprintf(pBARPath, "%s/" BAR_STR, pci_path, i);
-
- if ((memfd = open(pBARPath, O_RDWR | O_SYNC)) < 0 )
+ if ((memfd = open(pBARPath, O_RDWR | O_SYNC)) < 0)
{
printf("Error opening %s file. \n", pBARPath);
close(memfd);
@@ -109,19 +104,22 @@ void initHAL(const char* pci_path)
printf("mmaping BAR[%d]: %s\n", i, pBARPath);
}
- if (fstat(memfd, &st) < 0) {
+ if (fstat(memfd, &st) < 0)
+ {
fprintf(stderr, "error: couldn't stat file\n");
exit(-1);
}
- bar[i] = (uint8_t*)mmap(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, 0); // PROT_WRITE
- if(bar[i] == MAP_FAILED)
+ bar[i] = (uint8_t *)mmap(0, st.st_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, memfd, 0); // PROT_WRITE
+ if (bar[i] == MAP_FAILED)
{
- printf("Unable to mmap %s: %s\n", pBARPath, strerror(errno));
+ printf("Unable to mmap %s: %s\n", pBARPath,
+ strerror(errno));
exit(-1);
}
- if(is_bar_64bit(config.BAR[i]))
+ if (is_bar_64bit(config.BAR[i]))
{
i++;
}
@@ -133,13 +131,13 @@ void initHAL(const char* pci_path)
}
}
- uint8_t* DEVICEBase = (uint8_t*)bar[0];
+ uint8_t *DEVICEBase = (uint8_t *)bar[0];
extern void init_bcm5719_DEVICE(void);
- extern void init_bcm5719_DEVICE_mmap(void*);
+ extern void init_bcm5719_DEVICE_mmap(void *);
extern void init_bcm5719_APE(void);
extern void init_bcm5719_NVM(void);
- extern void init_bcm5719_NVM_mmap(void*);
+ extern void init_bcm5719_NVM_mmap(void *);
init_bcm5719_DEVICE();
init_bcm5719_DEVICE_mmap(DEVICEBase);
init_bcm5719_APE();
OpenPOWER on IntegriCloud