Skip to content

Commit

Permalink
Replace uintptr_t with metal_cpureg_t type.
Browse files Browse the repository at this point in the history
  • Loading branch information
NandkumarJoshi committed Jul 14, 2020
1 parent 9466b76 commit d80d086
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
9 changes: 9 additions & 0 deletions metal/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

struct metal_cpu;

/*!
* @brief Typedef for CPU register-size datatype.
*/
#if __riscv_xlen == 32
typedef uint32_t metal_cpureg_t;
#else
typedef uint64_t metal_cpureg_t;
#endif

/*!
* @brief Function signature for exception handlers
*/
Expand Down
8 changes: 4 additions & 4 deletions metal/hpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int metal_hpm_disable(struct metal_cpu *cpu);
* [XLEN-1:8] - Event selection mask [7:0] - Event class
* @return 0 If no error.*/
int metal_hpm_set_event(struct metal_cpu *cpu, metal_hpm_counter counter,
uintptr_t bitmask);
metal_cpureg_t bitmask);

/*! @brief Writes specified value into event selector register.
* Counter will start incrementing from the moment events are set.
Expand All @@ -153,7 +153,7 @@ int metal_hpm_set_event(struct metal_cpu *cpu, metal_hpm_counter counter,
* [XLEN-1:8] - Event selection mask [7:0] - Event class
* @return 0 If no error.*/
int metal_hpm_assign_event(struct metal_cpu *cpu, metal_hpm_counter counter,
uintptr_t regval);
metal_cpureg_t regval);

/*! @brief Get events selection bit-mask set for specified counter.
* @param cpu The CPU device handle.
Expand All @@ -162,7 +162,7 @@ int metal_hpm_assign_event(struct metal_cpu *cpu, metal_hpm_counter counter,
* refer core reference manual for details.
* @return 0 If no error.*/
int metal_hpm_get_event(struct metal_cpu *cpu, metal_hpm_counter counter,
uintptr_t *bitmask);
metal_cpureg_t *bitmask);

/*! @brief Clear event selector bits as per specified bit-mask.
* @param cpu The CPU device handle.
Expand All @@ -171,7 +171,7 @@ int metal_hpm_get_event(struct metal_cpu *cpu, metal_hpm_counter counter,
* refer core reference manual for details.
* @return 0 If no error.*/
int metal_hpm_clr_event(struct metal_cpu *cpu, metal_hpm_counter counter,
uintptr_t bitmask);
metal_cpureg_t bitmask);

/*! @brief Enable counter access to next lower privilege mode.
* @param cpu The CPU device handle.
Expand Down
22 changes: 11 additions & 11 deletions src/hpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int metal_hpm_init(struct metal_cpu *gcpu) {
/* Check if counters are initialized or pointer is NULL */
if ((gcpu) && (cpu->hpm_count == 0)) {
metal_hpm_counter n;
uintptr_t bitmask;
metal_cpureg_t bitmask;
/* Count number of available hardware performance counters */
cpu->hpm_count = METAL_HPM_COUNT_MAX;

Expand Down Expand Up @@ -125,7 +125,7 @@ unsigned int metal_hpm_get_count(struct metal_cpu *gcpu) {

int metal_hpm_disable(struct metal_cpu *gcpu) {
struct __metal_driver_cpu *cpu = (void *)gcpu;
uintptr_t temp = 0, val = 0;
metal_cpureg_t temp = 0, val = 0;

/* Check if pointer is NULL */
if (gcpu) {
Expand All @@ -151,9 +151,9 @@ int metal_hpm_disable(struct metal_cpu *gcpu) {
}

int metal_hpm_set_event(struct metal_cpu *gcpu, metal_hpm_counter counter,
uintptr_t bitmask) {
metal_cpureg_t bitmask) {
struct __metal_driver_cpu *cpu = (void *)gcpu;
uintptr_t val;
metal_cpureg_t val;

/* Return error if counter is out of range or pointer is NULL */
if ((gcpu) && (counter >= cpu->hpm_count))
Expand All @@ -171,7 +171,7 @@ int metal_hpm_set_event(struct metal_cpu *gcpu, metal_hpm_counter counter,
}

int metal_hpm_assign_event(struct metal_cpu *gcpu, metal_hpm_counter counter,
uintptr_t regval) {
metal_cpureg_t regval) {
struct __metal_driver_cpu *cpu = (void *)gcpu;

/* Return error if counter is out of range or pointer is NULL */
Expand All @@ -190,9 +190,9 @@ int metal_hpm_assign_event(struct metal_cpu *gcpu, metal_hpm_counter counter,
}

int metal_hpm_get_event(struct metal_cpu *gcpu, metal_hpm_counter counter,
uintptr_t *bitmask) {
metal_cpureg_t *bitmask) {
struct __metal_driver_cpu *cpu = (void *)gcpu;
uintptr_t val = 0;
metal_cpureg_t val = 0;

/* Return error if counter is out of range or pointer is NULL */
if ((gcpu) && (bitmask) && (counter >= cpu->hpm_count))
Expand All @@ -211,9 +211,9 @@ int metal_hpm_get_event(struct metal_cpu *gcpu, metal_hpm_counter counter,
}

int metal_hpm_clr_event(struct metal_cpu *gcpu, metal_hpm_counter counter,
uintptr_t bitmask) {
metal_cpureg_t bitmask) {
struct __metal_driver_cpu *cpu = (void *)gcpu;
uintptr_t val = 0;
metal_cpureg_t val = 0;

/* Return error if counter is out of range or pointer is NULL */
if ((gcpu) && (counter >= cpu->hpm_count))
Expand All @@ -232,7 +232,7 @@ int metal_hpm_clr_event(struct metal_cpu *gcpu, metal_hpm_counter counter,

int metal_hpm_enable_access(struct metal_cpu *gcpu, metal_hpm_counter counter) {
struct __metal_driver_cpu *cpu = (void *)gcpu;
uintptr_t temp = 0, val = 0;
metal_cpureg_t temp = 0, val = 0;

/* Return error if counter is out of range or pointer is NULL */
if ((gcpu) && (counter >= cpu->hpm_count))
Expand All @@ -257,7 +257,7 @@ int metal_hpm_enable_access(struct metal_cpu *gcpu, metal_hpm_counter counter) {
int metal_hpm_disable_access(struct metal_cpu *gcpu,
metal_hpm_counter counter) {
struct __metal_driver_cpu *cpu = (void *)gcpu;
uintptr_t temp = 0, val = 0;
metal_cpureg_t temp = 0, val = 0;

/* Return error if counter is out of range or pointer is NULL */
if ((gcpu) && (counter >= cpu->hpm_count))
Expand Down

0 comments on commit d80d086

Please sign in to comment.