6 /* Describe the MPX Hardware Layout in here */
8 #define NR_MPX_BOUNDS_REGISTERS 4
12 #define MPX_BOUNDS_TABLE_ENTRY_SIZE_BYTES 16 /* 4 * 32-bits */
13 #define MPX_BOUNDS_TABLE_SIZE_BYTES (1ULL << 14) /* 16k */
14 #define MPX_BOUNDS_DIR_ENTRY_SIZE_BYTES 4
15 #define MPX_BOUNDS_DIR_SIZE_BYTES (1ULL << 22) /* 4MB */
17 #define MPX_BOUNDS_TABLE_BOTTOM_BIT 2
18 #define MPX_BOUNDS_TABLE_TOP_BIT 11
19 #define MPX_BOUNDS_DIR_BOTTOM_BIT 12
20 #define MPX_BOUNDS_DIR_TOP_BIT 31
25 * Linear Address of "pointer" (LAp)
27 * 3 -> 19: index in to bounds table
28 * 20 -> 47: index in to bounds directory
32 #define MPX_BOUNDS_TABLE_ENTRY_SIZE_BYTES 32
33 #define MPX_BOUNDS_TABLE_SIZE_BYTES (1ULL << 22) /* 4MB */
34 #define MPX_BOUNDS_DIR_ENTRY_SIZE_BYTES 8
35 #define MPX_BOUNDS_DIR_SIZE_BYTES (1ULL << 31) /* 2GB */
37 #define MPX_BOUNDS_TABLE_BOTTOM_BIT 3
38 #define MPX_BOUNDS_TABLE_TOP_BIT 19
39 #define MPX_BOUNDS_DIR_BOTTOM_BIT 20
40 #define MPX_BOUNDS_DIR_TOP_BIT 47
44 #define MPX_BOUNDS_DIR_NR_ENTRIES \
45 (MPX_BOUNDS_DIR_SIZE_BYTES/MPX_BOUNDS_DIR_ENTRY_SIZE_BYTES)
46 #define MPX_BOUNDS_TABLE_NR_ENTRIES \
47 (MPX_BOUNDS_TABLE_SIZE_BYTES/MPX_BOUNDS_TABLE_ENTRY_SIZE_BYTES)
49 #define MPX_BOUNDS_TABLE_ENTRY_VALID_BIT 0x1
53 char x
[MPX_BOUNDS_DIR_ENTRY_SIZE_BYTES
];
56 } __attribute__((packed
));
60 char x
[MPX_BOUNDS_TABLE_ENTRY_SIZE_BYTES
];
61 unsigned long contents
[1];
63 } __attribute__((packed
));
65 struct mpx_bounds_dir
{
66 struct mpx_bd_entry entries
[MPX_BOUNDS_DIR_NR_ENTRIES
];
67 } __attribute__((packed
));
69 struct mpx_bounds_table
{
70 struct mpx_bt_entry entries
[MPX_BOUNDS_TABLE_NR_ENTRIES
];
71 } __attribute__((packed
));
73 static inline unsigned long GET_BITS(unsigned long val
, int bottombit
, int topbit
)
75 int total_nr_bits
= topbit
- bottombit
;
76 unsigned long mask
= (1UL << total_nr_bits
)-1;
77 return (val
>> bottombit
) & mask
;
80 static inline unsigned long __vaddr_bounds_table_index(void *vaddr
)
82 return GET_BITS((unsigned long)vaddr
, MPX_BOUNDS_TABLE_BOTTOM_BIT
,
83 MPX_BOUNDS_TABLE_TOP_BIT
);
86 static inline unsigned long __vaddr_bounds_directory_index(void *vaddr
)
88 return GET_BITS((unsigned long)vaddr
, MPX_BOUNDS_DIR_BOTTOM_BIT
,
89 MPX_BOUNDS_DIR_TOP_BIT
);
92 static inline struct mpx_bd_entry
*mpx_vaddr_to_bd_entry(void *vaddr
,
93 struct mpx_bounds_dir
*bounds_dir
)
95 unsigned long index
= __vaddr_bounds_directory_index(vaddr
);
96 return &bounds_dir
->entries
[index
];
99 static inline int bd_entry_valid(struct mpx_bd_entry
*bounds_dir_entry
)
101 unsigned long __bd_entry
= (unsigned long)bounds_dir_entry
->contents
;
102 return (__bd_entry
& MPX_BOUNDS_TABLE_ENTRY_VALID_BIT
);
105 static inline struct mpx_bounds_table
*
106 __bd_entry_to_bounds_table(struct mpx_bd_entry
*bounds_dir_entry
)
108 unsigned long __bd_entry
= (unsigned long)bounds_dir_entry
->contents
;
109 assert(__bd_entry
& MPX_BOUNDS_TABLE_ENTRY_VALID_BIT
);
110 __bd_entry
&= ~MPX_BOUNDS_TABLE_ENTRY_VALID_BIT
;
111 return (struct mpx_bounds_table
*)__bd_entry
;
114 static inline struct mpx_bt_entry
*
115 mpx_vaddr_to_bt_entry(void *vaddr
, struct mpx_bounds_dir
*bounds_dir
)
117 struct mpx_bd_entry
*bde
= mpx_vaddr_to_bd_entry(vaddr
, bounds_dir
);
118 struct mpx_bounds_table
*bt
= __bd_entry_to_bounds_table(bde
);
119 unsigned long index
= __vaddr_bounds_table_index(vaddr
);
120 return &bt
->entries
[index
];
123 #endif /* _MPX_HW_H */