blob: 1f78e48ead3196e1bdff6a00ae73d021427c039c [file] [log] [blame]
Madhukar Pappireddy464f2462021-08-03 11:23:07 -05001/*
2 * Copyright 2021 The Hafnium Authors.
3 *
4 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
7 */
8
9#pragma once
10
11#include <stdatomic.h>
12
13#include "hf/arch/types.h"
14
15#include "vmapi/hf/ffa.h"
16
17/**
Daniel Boulby801f8ef2022-06-27 14:21:01 +010018 * Macros for accessing the bitmap tracking interrupts.
19 */
20/* The number of bits in each element of the interrupt bitfields. */
21#define INTERRUPT_REGISTER_BITS 32
22
23#define INTID_INDEX(intid) (intid / INTERRUPT_REGISTER_BITS)
24#define INTID_MASK(v, intid) (v << (intid % INTERRUPT_REGISTER_BITS))
25
26/**
Madhukar Pappireddy464f2462021-08-03 11:23:07 -050027 * Attributes encoding in the manifest:
28
29 * Field Bit(s)
30 * ---------------------------
31 * Priority 7:0
32 * Security_State 8
33 * Config(Edge/Level) 9
34 * Type(SPI/PPI/SGI) 11:10
35 * Reserved 31:12
36 *
37 * Implementation defined Encodings for various fields:
38 *
39 * Security_State:
40 * - Secure: 1
41 * - Non-secure: 0
42 *
43 * Configuration:
44 * - Edge triggered: 0
45 * - Level triggered: 1
46 * Type:
47 * - SPI: 0b10
48 * - PPI: 0b01
49 * - SGI: 0b00
50 *
51 */
52
53#define INT_DESC_TYPE_SPI 2
54#define INT_DESC_TYPE_PPI 1
55#define INT_DESC_TYPE_SGI 0
56
57/** Interrupt Descriptor field masks and shifts. */
58
59#define INT_DESC_PRIORITY_SHIFT 0
60#define INT_DESC_SEC_STATE_SHIFT 8
61#define INT_DESC_CONFIG_SHIFT 9
62#define INT_DESC_TYPE_SHIFT 10
63
64struct interrupt_descriptor {
65 uint32_t interrupt_id;
66
67 /**
68 * Bit fields Position
69 * ---------------------
70 * reserved: 7:4
71 * type: 3:2
72 * config: 1
73 * sec_state: 0
74 */
75 uint8_t type_config_sec_state;
76 uint8_t priority;
77 bool valid;
78};
79
80/**
81 * Helper APIs for accessing interrupt_descriptor member variables.
82 */
83static inline uint32_t interrupt_desc_get_id(
84 struct interrupt_descriptor int_desc)
85{
86 return int_desc.interrupt_id;
87}
88
89static inline uint8_t interrupt_desc_get_sec_state(
90 struct interrupt_descriptor int_desc)
91{
92 return ((int_desc.type_config_sec_state >> 0) & 1U);
93}
94
95static inline uint8_t interrupt_desc_get_config(
96 struct interrupt_descriptor int_desc)
97{
98 return ((int_desc.type_config_sec_state >> 1) & 1U);
99}
100
101static inline uint8_t interrupt_desc_get_type(
102 struct interrupt_descriptor int_desc)
103{
104 return ((int_desc.type_config_sec_state >> 2) & 3U);
105}
106
107static inline uint8_t interrupt_desc_get_priority(
108 struct interrupt_descriptor int_desc)
109{
110 return int_desc.priority;
111}
112
113static inline bool interrupt_desc_get_valid(
114 struct interrupt_descriptor int_desc)
115{
116 return int_desc.valid;
117}
118
119static inline void interrupt_desc_set_id(struct interrupt_descriptor *int_desc,
120 uint32_t interrupt_id)
121{
122 int_desc->interrupt_id = interrupt_id;
123}
124
125static inline void interrupt_desc_set_type_config_sec_state(
126 struct interrupt_descriptor *int_desc, uint8_t value)
127{
128 int_desc->type_config_sec_state = value;
129}
130
131static inline void interrupt_desc_set_priority(
132 struct interrupt_descriptor *int_desc, uint8_t priority)
133{
134 int_desc->priority = priority;
135}
136
137static inline void interrupt_desc_set_valid(
138 struct interrupt_descriptor *int_desc, bool valid)
139{
140 int_desc->valid = valid;
141}