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.
14 #include "exec/memory.h"
16 typedef struct RegisterInfo RegisterInfo
;
17 typedef struct RegisterAccessInfo RegisterAccessInfo
;
20 * Access description for a register that is part of guest accessible device
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
{
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
);
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
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
76 const RegisterAccessInfo
*access
;
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
);
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?
102 uint64_t register_read(RegisterInfo
*reg
, uint64_t re
, const char* prefix
,
107 * @reg: register to reset
110 void register_reset(RegisterInfo
*reg
);