blob: 94943ed232f61cbbcea7747c21729438866d0414 [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/**
18 * Attributes encoding in the manifest:
19
20 * Field Bit(s)
21 * ---------------------------
22 * Priority 7:0
23 * Security_State 8
24 * Config(Edge/Level) 9
25 * Type(SPI/PPI/SGI) 11:10
26 * Reserved 31:12
27 *
28 * Implementation defined Encodings for various fields:
29 *
30 * Security_State:
31 * - Secure: 1
32 * - Non-secure: 0
33 *
34 * Configuration:
35 * - Edge triggered: 0
36 * - Level triggered: 1
37 * Type:
38 * - SPI: 0b10
39 * - PPI: 0b01
40 * - SGI: 0b00
41 *
42 */
43
44#define INT_DESC_TYPE_SPI 2
45#define INT_DESC_TYPE_PPI 1
46#define INT_DESC_TYPE_SGI 0
47
48/** Interrupt Descriptor field masks and shifts. */
49
50#define INT_DESC_PRIORITY_SHIFT 0
51#define INT_DESC_SEC_STATE_SHIFT 8
52#define INT_DESC_CONFIG_SHIFT 9
53#define INT_DESC_TYPE_SHIFT 10
54
55struct interrupt_descriptor {
56 uint32_t interrupt_id;
57
58 /**
59 * Bit fields Position
60 * ---------------------
61 * reserved: 7:4
62 * type: 3:2
63 * config: 1
64 * sec_state: 0
65 */
66 uint8_t type_config_sec_state;
67 uint8_t priority;
68 bool valid;
69};
70
71/**
72 * Helper APIs for accessing interrupt_descriptor member variables.
73 */
74static inline uint32_t interrupt_desc_get_id(
75 struct interrupt_descriptor int_desc)
76{
77 return int_desc.interrupt_id;
78}
79
80static inline uint8_t interrupt_desc_get_sec_state(
81 struct interrupt_descriptor int_desc)
82{
83 return ((int_desc.type_config_sec_state >> 0) & 1U);
84}
85
86static inline uint8_t interrupt_desc_get_config(
87 struct interrupt_descriptor int_desc)
88{
89 return ((int_desc.type_config_sec_state >> 1) & 1U);
90}
91
92static inline uint8_t interrupt_desc_get_type(
93 struct interrupt_descriptor int_desc)
94{
95 return ((int_desc.type_config_sec_state >> 2) & 3U);
96}
97
98static inline uint8_t interrupt_desc_get_priority(
99 struct interrupt_descriptor int_desc)
100{
101 return int_desc.priority;
102}
103
104static inline bool interrupt_desc_get_valid(
105 struct interrupt_descriptor int_desc)
106{
107 return int_desc.valid;
108}
109
110static inline void interrupt_desc_set_id(struct interrupt_descriptor *int_desc,
111 uint32_t interrupt_id)
112{
113 int_desc->interrupt_id = interrupt_id;
114}
115
116static inline void interrupt_desc_set_type_config_sec_state(
117 struct interrupt_descriptor *int_desc, uint8_t value)
118{
119 int_desc->type_config_sec_state = value;
120}
121
122static inline void interrupt_desc_set_priority(
123 struct interrupt_descriptor *int_desc, uint8_t priority)
124{
125 int_desc->priority = priority;
126}
127
128static inline void interrupt_desc_set_valid(
129 struct interrupt_descriptor *int_desc, bool valid)
130{
131 int_desc->valid = valid;
132}