]>
Commit | Line | Data |
---|---|---|
1599121b AF |
1 | /* |
2 | * Register Definition API | |
3 | * | |
4 | * Copyright (c) 2016 Xilinx Inc. | |
5 | * Copyright (c) 2013 Peter Crosthwaite <[email protected]> | |
6 | * | |
7 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
8 | * the COPYING file in the top-level directory. | |
9 | */ | |
10 | ||
11 | #ifndef REGISTER_H | |
12 | #define REGISTER_H | |
13 | ||
14 | #include "exec/memory.h" | |
15 | ||
16 | typedef struct RegisterInfo RegisterInfo; | |
17 | typedef struct RegisterAccessInfo RegisterAccessInfo; | |
18 | ||
19 | /** | |
20 | * Access description for a register that is part of guest accessible device | |
21 | * state. | |
22 | * | |
23 | * @name: String name of the register | |
24 | * @ro: whether or not the bit is read-only | |
25 | * @w1c: bits with the common write 1 to clear semantic. | |
26 | * @reset: reset value. | |
27 | * @cor: Bits that are clear on read | |
28 | * @rsvd: Bits that are reserved and should not be changed | |
29 | * | |
30 | * @pre_write: Pre write callback. Passed the value that's to be written, | |
31 | * immediately before the actual write. The returned value is what is written, | |
32 | * giving the handler a chance to modify the written value. | |
33 | * @post_write: Post write callback. Passed the written value. Most write side | |
34 | * effects should be implemented here. | |
35 | * | |
36 | * @post_read: Post read callback. Passes the value that is about to be returned | |
37 | * for a read. The return value from this function is what is ultimately read, | |
38 | * allowing this function to modify the value before return to the client. | |
39 | */ | |
40 | ||
41 | struct RegisterAccessInfo { | |
42 | const char *name; | |
43 | uint64_t ro; | |
44 | uint64_t w1c; | |
45 | uint64_t reset; | |
46 | uint64_t cor; | |
47 | uint64_t rsvd; | |
48 | uint64_t unimp; | |
49 | ||
50 | uint64_t (*pre_write)(RegisterInfo *reg, uint64_t val); | |
51 | void (*post_write)(RegisterInfo *reg, uint64_t val); | |
52 | ||
53 | uint64_t (*post_read)(RegisterInfo *reg, uint64_t val); | |
54 | }; | |
55 | ||
56 | /** | |
57 | * A register that is part of guest accessible state | |
58 | * @data: pointer to the register data. Will be cast | |
59 | * to the relevant uint type depending on data_size. | |
60 | * @data_size: Size of the register in bytes. Must be | |
61 | * 1, 2, 4 or 8 | |
62 | * | |
63 | * @access: Access description of this register | |
64 | * | |
65 | * @debug: Whether or not verbose debug is enabled | |
66 | * @prefix: String prefix for log and debug messages | |
67 | * | |
68 | * @opaque: Opaque data for the register | |
69 | */ | |
70 | ||
71 | struct RegisterInfo { | |
72 | /* <public> */ | |
73 | void *data; | |
74 | int data_size; | |
75 | ||
76 | const RegisterAccessInfo *access; | |
77 | ||
78 | void *opaque; | |
79 | }; | |
80 | ||
81 | /** | |
82 | * write a value to a register, subject to its restrictions | |
83 | * @reg: register to write to | |
84 | * @val: value to write | |
85 | * @we: write enable mask | |
86 | * @prefix: The device prefix that should be printed before the register name | |
87 | * @debug: Should the write operation debug information be printed? | |
88 | */ | |
89 | ||
90 | void register_write(RegisterInfo *reg, uint64_t val, uint64_t we, | |
91 | const char *prefix, bool debug); | |
92 | ||
93 | /** | |
94 | * read a value from a register, subject to its restrictions | |
95 | * @reg: register to read from | |
96 | * @re: read enable mask | |
97 | * @prefix: The device prefix that should be printed before the register name | |
98 | * @debug: Should the read operation debug information be printed? | |
99 | * returns: value read | |
100 | */ | |
101 | ||
102 | uint64_t register_read(RegisterInfo *reg, uint64_t re, const char* prefix, | |
103 | bool debug); | |
104 | ||
105 | /** | |
106 | * reset a register | |
107 | * @reg: register to reset | |
108 | */ | |
109 | ||
110 | void register_reset(RegisterInfo *reg); | |
111 | ||
112 | #endif |