]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/src/drivers/sifive_fu540-c000_l2.c
Update RISCC-V-RV32-SiFive_HiFive1_FreedomStudio project to latest tools and metal...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / freedom-metal / src / drivers / sifive_fu540-c000_l2.c
index 5e66b6cda587986bca41f86bfe3153320e1f06c2..aafc6e5e366e53a7e10aa8f89981f809c3507d14 100644 (file)
@@ -2,25 +2,32 @@
 /* SPDX-License-Identifier: Apache-2.0 */
 
 #include <metal/machine/platform.h>
+
+#ifdef METAL_SIFIVE_FU540_C000_L2
+
+#include <stdint.h>
+#include <metal/io.h>
 #include <metal/drivers/sifive_fu540-c000_l2.h>
+#include <metal/machine.h>
 
 #define L2_CONFIG_WAYS_SHIFT    8
 #define L2_CONFIG_WAYS_MASK     (0xFF << L2_CONFIG_WAYS_SHIFT)
 
-#ifdef CONFIG_SIFIVE_FU540_C000_L2
+void __metal_driver_sifive_fu540_c000_l2_init(struct metal_cache *l2, int ways);
 
 static void metal_driver_sifive_fu540_c000_l2_init(void) __attribute__((constructor));
 static void metal_driver_sifive_fu540_c000_l2_init(void)
 {
 #ifdef __METAL_DT_SIFIVE_FU540_C000_L2_HANDLE
     /* Get the handle for the L2 cache controller */
-    struct __metal_driver_sifive_fu540_c000_l2 *l2 = __METAL_DT_SIFIVE_FU540_C000_L2_HANDLE;
+    struct metal_cache *l2 = __METAL_DT_SIFIVE_FU540_C000_L2_HANDLE;
     if(!l2) {
         return;
     }
 
     /* Get the number of available ways per bank */
-    uint32_t ways = __METAL_ACCESS_ONCE((__metal_io_u32 *)(l2->control_base + SIFIVE_FU540_C000_L2_CONFIG));
+    unsigned long control_base = __metal_driver_sifive_fu540_c000_l2_control_base(l2);
+    uint32_t ways = __METAL_ACCESS_ONCE((__metal_io_u32 *)(control_base + METAL_SIFIVE_FU540_C000_L2_CONFIG));
     ways = ((ways & L2_CONFIG_WAYS_MASK) >> L2_CONFIG_WAYS_SHIFT);
 
     /* Enable all the ways */
@@ -35,12 +42,9 @@ void __metal_driver_sifive_fu540_c000_l2_init(struct metal_cache *l2, int ways)
 
 int __metal_driver_sifive_fu540_c000_l2_get_enabled_ways(struct metal_cache *cache)
 {
-    struct __metal_driver_sifive_fu540_c000_l2 *l2 = (struct __metal_driver_sifive_fu540_c000_l2 *) cache;
-    if(!l2) {
-        return -1;
-    }
+    unsigned long control_base = __metal_driver_sifive_fu540_c000_l2_control_base(cache);
 
-    uint32_t way_enable = __METAL_ACCESS_ONCE((__metal_io_u32 *)(l2->control_base + SIFIVE_FU540_C000_L2_WAYENABLE));
+    uint32_t way_enable = __METAL_ACCESS_ONCE((__metal_io_u32 *)(control_base + METAL_SIFIVE_FU540_C000_L2_WAYENABLE));
 
     /* The stored number is the index, so add one */
     return (0xFF & way_enable) + 1;
@@ -48,10 +52,7 @@ int __metal_driver_sifive_fu540_c000_l2_get_enabled_ways(struct metal_cache *cac
 
 int __metal_driver_sifive_fu540_c000_l2_set_enabled_ways(struct metal_cache *cache, int ways)
 {
-    struct __metal_driver_sifive_fu540_c000_l2 *l2 = (struct __metal_driver_sifive_fu540_c000_l2 *) cache;
-    if(!l2) {
-        return -1;
-    }
+    unsigned long control_base = __metal_driver_sifive_fu540_c000_l2_control_base(cache);
 
     /* We can't decrease the number of enabled ways */
     if(metal_cache_get_enabled_ways(cache) > ways) {
@@ -62,7 +63,7 @@ int __metal_driver_sifive_fu540_c000_l2_set_enabled_ways(struct metal_cache *cac
     uint32_t value = 0xFF & (ways - 1);
 
     /* Set the number of enabled ways */
-    __METAL_ACCESS_ONCE((__metal_io_u32 *)(l2->control_base + SIFIVE_FU540_C000_L2_WAYENABLE)) = value;
+    __METAL_ACCESS_ONCE((__metal_io_u32 *)(control_base + METAL_SIFIVE_FU540_C000_L2_WAYENABLE)) = value;
 
     /* Make sure the number of ways was set correctly */
     if(metal_cache_get_enabled_ways(cache) != ways) {
@@ -79,3 +80,5 @@ __METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_fu540_c000_l2) = {
 };
 
 #endif
+
+typedef int no_empty_translation_units;