[850] | 1 | /** |
---|
| 2 | * \file io.h |
---|
| 3 | * \date 5 September 2012 |
---|
| 4 | * \author Cesar Fuguet |
---|
| 5 | * |
---|
| 6 | * Utility functions to write or read memory mapped hardware registers |
---|
| 7 | */ |
---|
| 8 | #ifndef IO_H |
---|
| 9 | #define IO_H |
---|
| 10 | |
---|
| 11 | #include <cpu.h> |
---|
| 12 | |
---|
| 13 | /** |
---|
| 14 | * \brief Read an 32 bits memory mapped hardware register |
---|
| 15 | * |
---|
| 16 | * \note interrupts should be disabled while executing this function |
---|
| 17 | */ |
---|
| 18 | static inline unsigned int ioread32(uint64_t paddr) |
---|
| 19 | { |
---|
| 20 | uint32_t value; |
---|
| 21 | uint32_t msb = paddr >> CLUSTER_OFFSET_BITS; |
---|
| 22 | uint32_t lsb = paddr & ((1ULL << CLUSTER_OFFSET_BITS)-1); |
---|
| 23 | |
---|
[857] | 24 | asm volatile("mfc2 $8, $24 \n" /* t0 <= DATA_PADDR_EXT */ |
---|
| 25 | "mtc2 %2, $24 \n" /* DATA_PADDR_EXT <= msb */ |
---|
[850] | 26 | "lw %0, 0(%1) \n" /* value <= *paddr */ |
---|
[857] | 27 | "mtc2 $8, $24 \n" /* DATA_PADDR_EXT <= 0 */ |
---|
[850] | 28 | : "=r"(value) |
---|
| 29 | : "r"(lsb), "r"(msb) |
---|
[857] | 30 | : "$8", "memory"); |
---|
[850] | 31 | |
---|
| 32 | return value; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * \brief Write an 32 bits memory mapped hardware register |
---|
| 37 | * |
---|
| 38 | * \note interrupts should be disabled while executing this function |
---|
| 39 | */ |
---|
| 40 | static inline void iowrite32(uint64_t paddr, uint32_t value) |
---|
| 41 | { |
---|
| 42 | uint32_t msb = paddr >> CLUSTER_OFFSET_BITS; |
---|
| 43 | uint32_t lsb = paddr & ((1ULL << CLUSTER_OFFSET_BITS)-1); |
---|
| 44 | |
---|
[857] | 45 | asm volatile("mfc2 $8, $24 \n" /* t0 <= DATA_PADDR_EXT */ |
---|
| 46 | "mtc2 %2, $24 \n" /* DATA_PADDR_EXT <= msb */ |
---|
[850] | 47 | "sw %0, 0(%1) \n" /* value <= *paddr */ |
---|
[857] | 48 | "mtc2 $8, $24 \n" /* DATA_PADDR_EXT <= 0 */ |
---|
[850] | 49 | "sync \n" |
---|
| 50 | : /* no outputs */ |
---|
| 51 | : "r"(value), "r"(lsb), "r"(msb) |
---|
[857] | 52 | : "$8", "memory"); |
---|
[850] | 53 | } |
---|
| 54 | |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | /* |
---|
| 58 | * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|
| 59 | */ |
---|