aboutsummaryrefslogtreecommitdiff
path: root/src/vendorcode/cavium/bdk/libbdk-hal/bdk-l2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vendorcode/cavium/bdk/libbdk-hal/bdk-l2c.c')
-rw-r--r--src/vendorcode/cavium/bdk/libbdk-hal/bdk-l2c.c152
1 files changed, 19 insertions, 133 deletions
diff --git a/src/vendorcode/cavium/bdk/libbdk-hal/bdk-l2c.c b/src/vendorcode/cavium/bdk/libbdk-hal/bdk-l2c.c
index b1e2a88ce1..6c163da2d4 100644
--- a/src/vendorcode/cavium/bdk/libbdk-hal/bdk-l2c.c
+++ b/src/vendorcode/cavium/bdk/libbdk-hal/bdk-l2c.c
@@ -41,6 +41,8 @@
#include "libbdk-arch/bdk-csrs-l2c.h"
#include "libbdk-arch/bdk-csrs-l2c_cbc.h"
#include "libbdk-arch/bdk-csrs-mio_fus.h"
+#include "libbdk-hal/bdk-l2c.h"
+#include "libbdk-hal/bdk-utils.h"
typedef struct
{
@@ -51,56 +53,6 @@ typedef struct
static l2_node_state_t l2_node_state[BDK_NUMA_MAX_NODES];
-/**
- * Perform one time initialization of L2 for improved
- * performance. This can be called after L2 is in use.
- *
- * @return Zero on success, negative on failure.
- */
-int bdk_l2c_initialize(bdk_node_t node)
-{
- if (CAVIUM_IS_MODEL(CAVIUM_CN8XXX))
- {
- /* Tell L2 to give the IOB statically higher priority compared to the
- cores. This avoids conditions where IO blocks might be starved under
- very high L2 loads */
- BDK_CSR_MODIFY(c, node, BDK_L2C_CTL,
- c.s.rsp_arb_mode = 1;
- c.s.xmc_arb_mode = 0);
- }
-
- if (CAVIUM_IS_MODEL(CAVIUM_CN88XX_PASS1_X) && !bdk_is_platform(BDK_PLATFORM_ASIM))
- {
- /* Errata: (L2C-22279) RCAS/RSTC which hits S/S can use wrong compare data */
- BDK_CSR_MODIFY(c, node, BDK_L2C_CTL,
- c.s.dissblkdty = 1);
- /* Errata: (L2C-22249) Broadcast invals can cause starvation on the INV bus */
- for (int i = 0; i < 4; i++)
- BDK_CSR_MODIFY(c, node, BDK_L2C_CBCX_SCRATCH(i),
- c.s.invdly = 1);
- }
-
- // FIXME: Disable partial writes on pass 2 until it is debugged
- if (CAVIUM_IS_MODEL(CAVIUM_CN88XX_PASS2_X) && !bdk_is_platform(BDK_PLATFORM_ASIM))
- {
- BDK_CSR_MODIFY(c, node, BDK_L2C_CTL,
- c.s.dissblkdty = 1);
- }
-
- if (CAVIUM_IS_MODEL(CAVIUM_CN8XXX) && bdk_is_platform(BDK_PLATFORM_EMULATOR))
- {
- /* The emulator requires L2C_CTL[DISSBLKDTY] to be set */
- BDK_CSR_MODIFY(c, node, BDK_L2C_CTL,
- c.s.dissblkdty = 1);
- }
- return 0;
-}
-
-int bdk_l2c_get_core_way_partition(bdk_node_t node, int core)
-{
- return (BDK_CSR_READ(node, BDK_L2C_WPAR_PPX(core)) & 0xffff);
-}
-
int bdk_l2c_set_core_way_partition(bdk_node_t node, int core, uint32_t mask)
{
uint32_t valid_mask = (1 << bdk_l2c_get_num_assoc(node)) - 1;
@@ -120,82 +72,11 @@ int bdk_l2c_set_hw_way_partition(bdk_node_t node, uint32_t mask)
return 0;
}
-
int bdk_l2c_get_hw_way_partition(bdk_node_t node)
{
return (BDK_CSR_READ(node, BDK_L2C_WPAR_IOBX(0)) & 0xffff);
}
-
-int bdk_l2c_lock_mem_region(bdk_node_t node, uint64_t start, uint64_t len)
-{
- /* Round start/end to cache line boundaries */
- len += start & BDK_CACHE_LINE_MASK;
- start &= ~BDK_CACHE_LINE_MASK;
- len = (len + BDK_CACHE_LINE_MASK) & ~BDK_CACHE_LINE_MASK;
- void *ptr = (start) ? bdk_phys_to_ptr(start) : NULL;
-
- while (len)
- {
- BDK_CACHE_LCK_L2(ptr);
- ptr += BDK_CACHE_LINE_SIZE;
- len -= BDK_CACHE_LINE_SIZE;
- }
- l2_node_state[node].is_locked = true;
- return 0;
-}
-
-void bdk_l2c_flush(bdk_node_t node)
-{
- /* The number of ways can be reduced with fuses, but the equations below
- assume the max number of ways */
- const int MAX_WAYS = 16;
- int num_sets = bdk_l2c_get_num_sets(node);
- int num_ways = bdk_l2c_get_num_assoc(node);
-
- int is_rtg = 1; /* Clear remote tags */
- for (int l2_way = 0; l2_way < num_ways; l2_way++)
- {
- for (int l2_set = 0; l2_set < num_sets; l2_set++)
- {
- uint64_t encoded = 128 * (l2_set + num_sets * (l2_way + (is_rtg * MAX_WAYS)));
- BDK_CACHE_WBI_L2_INDEXED(encoded);
- }
- }
-
- is_rtg = 0; /* Clear local tags */
- for (int l2_way = 0; l2_way < num_ways; l2_way++)
- {
- for (int l2_set = 0; l2_set < num_sets; l2_set++)
- {
- uint64_t encoded = 128 * (l2_set + num_sets * (l2_way + (is_rtg * MAX_WAYS)));
- BDK_CACHE_WBI_L2_INDEXED(encoded);
- }
- }
- l2_node_state[node].is_locked = false;
-}
-
-int bdk_l2c_unlock_mem_region(bdk_node_t node, uint64_t start, uint64_t len)
-{
- /* Round start/end to cache line boundaries */
- len += start & BDK_CACHE_LINE_MASK;
- start &= ~BDK_CACHE_LINE_MASK;
- len = (len + BDK_CACHE_LINE_MASK) & ~BDK_CACHE_LINE_MASK;
- void *ptr = (start) ? bdk_phys_to_ptr(start) : NULL;
-
- while (len > 0)
- {
- /* Must use invalidate version to release lock */
- BDK_CACHE_WBI_L2(ptr);
- ptr += BDK_CACHE_LINE_SIZE;
- len -= BDK_CACHE_LINE_SIZE;
- }
-
- l2_node_state[node].is_locked = false;
- return 0;
-}
-
-
int bdk_l2c_get_cache_size_bytes(bdk_node_t node)
{
return bdk_l2c_get_num_sets(node) * bdk_l2c_get_num_assoc(node) * BDK_CACHE_LINE_SIZE;
@@ -254,17 +135,22 @@ int bdk_l2c_get_num_assoc(bdk_node_t node)
return l2_node_state[node].ways;
}
-/**
- * Return true if the BDK has locked itself in L2
- *
- * @return
- */
-int bdk_l2c_is_locked(bdk_node_t node)
+int bdk_l2c_unlock_mem_region(bdk_node_t node, uint64_t start, uint64_t len)
{
- /* Determining the lock state of L2 requires reading exact tags from L2
- which varies per chip. Rather than deal with that complexity, we just
- keep a flag around saying if the L2 lock functions have been called.
- This works for the BDK as its use of locking is very simple */
- return l2_node_state[node].is_locked;
-}
+ /* Round start/end to cache line boundaries */
+ len += start & BDK_CACHE_LINE_MASK;
+ start &= ~BDK_CACHE_LINE_MASK;
+ len = (len + BDK_CACHE_LINE_MASK) & ~BDK_CACHE_LINE_MASK;
+ void *ptr = (start) ? bdk_phys_to_ptr(start) : NULL;
+ while (len > 0)
+ {
+ /* Must use invalidate version to release lock */
+ BDK_CACHE_WBI_L2(ptr);
+ ptr += BDK_CACHE_LINE_SIZE;
+ len -= BDK_CACHE_LINE_SIZE;
+ }
+
+ l2_node_state[node].is_locked = false;
+ return 0;
+}