1 | /********************************************************************** |
---|
2 | * \file io.h |
---|
3 | * \date 5 September 2012 |
---|
4 | * \author Cesar Fuguet / Alain Greiner |
---|
5 | * |
---|
6 | * Utility functions to write or read memory mapped hardware registers |
---|
7 | *********************************************************************/ |
---|
8 | |
---|
9 | #ifndef IO_H |
---|
10 | #define IO_H |
---|
11 | |
---|
12 | #include <defs.h> |
---|
13 | |
---|
14 | /********************************************************************** |
---|
15 | * Read an 32 bits memory mapped hardware register |
---|
16 | * with physical address extension to access cluster_io |
---|
17 | *********************************************************************/ |
---|
18 | static inline unsigned int ioread32(void * addr) |
---|
19 | { |
---|
20 | unsigned int value; |
---|
21 | unsigned int ext = CLUSTER_IO; |
---|
22 | |
---|
23 | asm volatile( |
---|
24 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cluster_io */ |
---|
25 | "lw %0, 0(%1) \n" /* value <= *(ext\addr) */ |
---|
26 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
27 | : "=r" (value) |
---|
28 | : "r" (addr), "r" (ext) ); |
---|
29 | |
---|
30 | return value; |
---|
31 | } |
---|
32 | |
---|
33 | /********************************************************************** |
---|
34 | * Read an 16 bits memory mapped hardware register |
---|
35 | *********************************************************************/ |
---|
36 | static inline unsigned short ioread16(void * addr) |
---|
37 | { |
---|
38 | return *(volatile unsigned short *) addr; |
---|
39 | } |
---|
40 | |
---|
41 | /********************************************************************** |
---|
42 | * Read an 8 bits memory mapped hardware register |
---|
43 | *********************************************************************/ |
---|
44 | static inline unsigned char ioread8(void * addr) |
---|
45 | { |
---|
46 | return *(volatile unsigned char *) addr; |
---|
47 | } |
---|
48 | |
---|
49 | /********************************************************************** |
---|
50 | * Write an 32 bits memory mapped hardware register |
---|
51 | * with physical address extension to access cluster_io |
---|
52 | *********************************************************************/ |
---|
53 | static inline void iowrite32(void * addr, unsigned int value) |
---|
54 | { |
---|
55 | unsigned int ext = CLUSTER_IO; |
---|
56 | |
---|
57 | asm volatile( |
---|
58 | "mtc2 %2, $24 \n" /* PADDR_EXT <= cluster_io */ |
---|
59 | "sw %0, 0(%1) \n" /* *(ext\addr) <= value */ |
---|
60 | "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ |
---|
61 | "sync \n" /* sync barrier */ |
---|
62 | : |
---|
63 | : "r" (value), "r" (addr), "r" (ext) ); |
---|
64 | } |
---|
65 | |
---|
66 | /********************************************************************** |
---|
67 | * Write an 16 bits memory mapped hardware register |
---|
68 | *********************************************************************/ |
---|
69 | static inline void iowrite16(void * addr, unsigned short value) |
---|
70 | { |
---|
71 | *(volatile unsigned short *) addr = value; |
---|
72 | asm volatile("sync" ::: "memory"); |
---|
73 | } |
---|
74 | |
---|
75 | /********************************************************************** |
---|
76 | * Write an 8 bits memory mapped hardware register |
---|
77 | *********************************************************************/ |
---|
78 | static inline void iowrite8(void * addr, unsigned char value) |
---|
79 | { |
---|
80 | *(volatile unsigned char *) addr = value; |
---|
81 | asm volatile("sync" ::: "memory"); |
---|
82 | } |
---|
83 | |
---|
84 | #endif |
---|