register: Add Register API
[qemu.git] / include / hw / register.h
blob6a2bc756d17d15d2aa018b4114e9cd6d91358b44
1 /*
2 * Register Definition API
4 * Copyright (c) 2016 Xilinx Inc.
5 * Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
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 */
11 #ifndef REGISTER_H
12 #define REGISTER_H
14 #include "exec/memory.h"
16 typedef struct RegisterInfo RegisterInfo;
17 typedef struct RegisterAccessInfo RegisterAccessInfo;
19 /**
20 * Access description for a register that is part of guest accessible device
21 * state.
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
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.
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.
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;
50 uint64_t (*pre_write)(RegisterInfo *reg, uint64_t val);
51 void (*post_write)(RegisterInfo *reg, uint64_t val);
53 uint64_t (*post_read)(RegisterInfo *reg, uint64_t val);
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
63 * @access: Access description of this register
65 * @debug: Whether or not verbose debug is enabled
66 * @prefix: String prefix for log and debug messages
68 * @opaque: Opaque data for the register
71 struct RegisterInfo {
72 /* <public> */
73 void *data;
74 int data_size;
76 const RegisterAccessInfo *access;
78 void *opaque;
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?
90 void register_write(RegisterInfo *reg, uint64_t val, uint64_t we,
91 const char *prefix, bool debug);
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
102 uint64_t register_read(RegisterInfo *reg, uint64_t re, const char* prefix,
103 bool debug);
106 * reset a register
107 * @reg: register to reset
110 void register_reset(RegisterInfo *reg);
112 #endif