| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef __BDK_BDK_COREBOOT_H |
| 12 |
#define __BDK_BDK_COREBOOT_H |
| 13 |
|
| 14 |
#include <device/mmio.h> |
| 15 |
#include <delay.h> |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
static inline uint64_t bdk_ptr_to_phys(void *ptr) |
| 26 |
{ |
| 27 |
|
| 28 |
return (uint64_t)ptr; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
static inline void *bdk_phys_to_ptr(uint64_t physical_address) |
| 40 |
{ |
| 41 |
|
| 42 |
return (void *)physical_address; |
| 43 |
} |
| 44 |
|
| 45 |
static inline void bdk_write64_int64(uint64_t address, int64_t value) |
| 46 |
{ |
| 47 |
dmb(); |
| 48 |
*(volatile int64_t *)address = value; |
| 49 |
dmb(); |
| 50 |
} |
| 51 |
|
| 52 |
static inline void bdk_write64_uint64(uint64_t address, uint64_t value) |
| 53 |
{ |
| 54 |
write64(bdk_phys_to_ptr(address), value); |
| 55 |
} |
| 56 |
|
| 57 |
static inline void bdk_write64_int32(uint64_t address, int32_t value) |
| 58 |
{ |
| 59 |
dmb(); |
| 60 |
*(volatile int32_t *)address = value; |
| 61 |
dmb(); |
| 62 |
} |
| 63 |
|
| 64 |
static inline void bdk_write64_uint32(uint64_t address, uint32_t value) |
| 65 |
{ |
| 66 |
write32(bdk_phys_to_ptr(address), value); |
| 67 |
} |
| 68 |
|
| 69 |
static inline void bdk_write64_int16(uint64_t address, int16_t value) |
| 70 |
{ |
| 71 |
dmb(); |
| 72 |
*(volatile int16_t *)address = value; |
| 73 |
dmb(); |
| 74 |
} |
| 75 |
|
| 76 |
static inline void bdk_write64_uint16(uint64_t address, uint16_t value) |
| 77 |
{ |
| 78 |
write16(bdk_phys_to_ptr(address), value); |
| 79 |
} |
| 80 |
|
| 81 |
static inline void bdk_write64_int8(uint64_t address, int8_t value) |
| 82 |
{ |
| 83 |
dmb(); |
| 84 |
*(volatile int8_t *)address = value; |
| 85 |
dmb(); |
| 86 |
} |
| 87 |
|
| 88 |
static inline void bdk_write64_uint8(uint64_t address, uint8_t value) |
| 89 |
{ |
| 90 |
write8(bdk_phys_to_ptr(address), value); |
| 91 |
} |
| 92 |
|
| 93 |
static inline int64_t bdk_read64_int64(uint64_t address) |
| 94 |
{ |
| 95 |
return *(volatile int64_t *)bdk_phys_to_ptr(address); |
| 96 |
} |
| 97 |
|
| 98 |
static inline uint64_t bdk_read64_uint64(uint64_t address) |
| 99 |
{ |
| 100 |
return read64(bdk_phys_to_ptr(address)); |
| 101 |
} |
| 102 |
|
| 103 |
static inline int32_t bdk_read64_int32(uint64_t address) |
| 104 |
{ |
| 105 |
return *(volatile int32_t *)bdk_phys_to_ptr(address); |
| 106 |
} |
| 107 |
|
| 108 |
static inline uint32_t bdk_read64_uint32(uint64_t address) |
| 109 |
{ |
| 110 |
return read32(bdk_phys_to_ptr(address)); |
| 111 |
} |
| 112 |
|
| 113 |
static inline int16_t bdk_read64_int16(uint64_t address) |
| 114 |
{ |
| 115 |
return *(volatile int16_t *)bdk_phys_to_ptr(address); |
| 116 |
} |
| 117 |
|
| 118 |
static inline uint16_t bdk_read64_uint16(uint64_t address) |
| 119 |
{ |
| 120 |
return read16(bdk_phys_to_ptr(address)); |
| 121 |
} |
| 122 |
|
| 123 |
static inline int8_t bdk_read64_int8(uint64_t address) |
| 124 |
{ |
| 125 |
return *(volatile int8_t *)bdk_phys_to_ptr(address); |
| 126 |
} |
| 127 |
|
| 128 |
static inline uint8_t bdk_read64_uint8(uint64_t address) |
| 129 |
{ |
| 130 |
return read8(bdk_phys_to_ptr(address)); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
static inline uint32_t bdk_pop(uint32_t v) |
| 142 |
{ |
| 143 |
|
| 144 |
v = v - ((v >> 1) & 0x55555555); |
| 145 |
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); |
| 146 |
return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
static inline int bdk_dpop(uint64_t val) |
| 158 |
{ |
| 159 |
return bdk_pop(val & 0xffffffff) + bdk_pop(val >> 32); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
static inline void bdk_wait_usec(uint64_t usec) |
| 168 |
{ |
| 169 |
udelay((unsigned int)usec); |
| 170 |
} |
| 171 |
|
| 172 |
#endif |