add support to GIC ITS, and the MSI service base on it
[lunaix-os.git] / lunaix-os / arch / aarch64 / includes / asm / soc / gic.h
index 35b9dc5e55aeed92d8997af6c018b1cdd0bd0ec5..840700dfdb2b4c7a1424fff2e8e571eef6c6daa2 100644 (file)
@@ -4,9 +4,13 @@
 #include <lunaix/types.h>
 #include <lunaix/ds/bitmap.h>
 #include <lunaix/ds/hashtable.h>
+
+#include <hal/devtree.h>
+
 #include <asm/aa64_gic.h>
 #include <asm-generic/isrm.h>
 
+// nr of cpus, must be 1
 #define NR_CPU      1
 #define gic_bmp     PREP_BITMAP(gicreg_t, gic_intr, BMP_ORIENT_LSB)
 
@@ -63,6 +67,7 @@ struct gic_int_param
     enum gic_tri_type trigger;
     enum gic_grp_type group;
     unsigned int priority;
+    unsigned int rel_intid;
     int cpu_id;
     bool as_nmi;
     bool ext_range;
@@ -143,19 +148,82 @@ struct gic_pe
     };
 };
 
-struct gic_its
+struct gic_its_regs
 {
     gicreg_t base[FRAME_LEN];        // control regs
     gicreg_t trn_space[FRAME_LEN];   // translation space
 } compact align(4);
 
-struct gic_its_v41
+struct gic_its_regs_v41
 {
     gicreg_t base[FRAME_LEN];        // control regs
     gicreg_t trn_space[FRAME_LEN];   // translation space
     gicreg_t vsgi_space[FRAME_LEN];  // vSGI space (v4.1+)
 } compact align(4);
 
+struct gic_its_cmdqeue
+{
+    gicreg64_t base;
+    gicreg_t   wr_ptr;
+    gicreg_t   rd_ptr;  
+} compact align(4);
+
+struct gic_its_cmd
+{
+    gicreg64_t dw[4];
+};
+
+struct gic_its_devmap
+{
+    struct hlist_node node;
+    unsigned int devid;
+    unsigned int next_evtid;
+};
+
+struct gic_its
+{
+    struct llist_header its;
+
+    struct {
+        unsigned int nr_devid;
+        unsigned int nr_evtid;
+        unsigned int nr_cid;
+        unsigned int sz_itte;
+
+        bool pta;
+        bool ext_cids;
+    };
+
+    union {
+        struct gic_its_regs* reg;
+        struct gic_its_regs_v41* reg_v41;
+        ptr_t  reg_ptr;
+    };
+
+    struct {
+        union {
+            struct gic_its_cmdqeue *cmd_queue;
+            ptr_t  cmd_queue_ptr;
+        };
+        
+        union {
+            struct gic_its_cmd *cmds;
+            ptr_t cmds_ptr;
+        };
+
+        unsigned int max_cmd;
+    };
+
+    union {
+        struct {
+            gicreg_t base[8];
+        } *tables;
+        ptr_t  table_ptr;
+    };
+
+    DECLARE_HASHTABLE(devmaps, 8);
+};
+
 typedef unsigned char lpi_entry_t;
 
 struct arm_gic
@@ -175,17 +243,13 @@ struct arm_gic
 
     struct {
         gicreg_t* dist_base;
-        union {
-            struct gic_its* its;
-            struct gic_its_v41* its_v41;
-        };
     } mmrs;
 
+    struct llist_header its;
+
     struct {
-        union {
-            ptr_t prop;
-            lpi_entry_t* property;
-        };
+        ptr_t prop_pa;
+        lpi_entry_t* prop_table;
         
         ptr_t pend;
         BITMAP(gic_bmp) pendings;
@@ -201,4 +265,24 @@ struct arm_gic
     } idomain;
 };
 
+void
+gic_create_from_dt(struct arm_gic* gic);
+
+unsigned int;
+gic_dtprop_interpret(struct gic_int_param* param, 
+                     struct dt_prop_val* val, int width);
+
+struct gic_its*
+gic_its_create(struct arm_gic* gic, ptr_t regs);
+
+void
+gic_configure_its(struct arm_gic* gic);
+
+struct gic_interrupt*
+gic_install_int(struct gic_int_param* param, isr_cb handler, bool alloc);
+
+unsigned int
+gic_its_map_lpi(struct gic_its* its, 
+                unsigned int devid, unsigned int lpid);
+
 #endif /* __LUNAIX_GIC_H */