2016-07-04 14:06:36 +02:00
|
|
|
/*
|
|
|
|
* Register Definition API
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Xilinx Inc.
|
|
|
|
* Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef REGISTER_H
|
|
|
|
#define REGISTER_H
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
#include "hw/qdev-core.h"
|
2016-07-04 14:06:36 +02:00
|
|
|
#include "exec/memory.h"
|
2017-01-27 16:20:21 +01:00
|
|
|
#include "hw/registerfields.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2016-07-04 14:06:36 +02:00
|
|
|
|
|
|
|
typedef struct RegisterInfo RegisterInfo;
|
|
|
|
typedef struct RegisterAccessInfo RegisterAccessInfo;
|
2016-07-04 14:06:36 +02:00
|
|
|
typedef struct RegisterInfoArray RegisterInfoArray;
|
2016-07-04 14:06:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Access description for a register that is part of guest accessible device
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* @name: String name of the register
|
|
|
|
* @ro: whether or not the bit is read-only
|
|
|
|
* @w1c: bits with the common write 1 to clear semantic.
|
|
|
|
* @reset: reset value.
|
|
|
|
* @cor: Bits that are clear on read
|
|
|
|
* @rsvd: Bits that are reserved and should not be changed
|
|
|
|
*
|
|
|
|
* @pre_write: Pre write callback. Passed the value that's to be written,
|
|
|
|
* immediately before the actual write. The returned value is what is written,
|
|
|
|
* giving the handler a chance to modify the written value.
|
|
|
|
* @post_write: Post write callback. Passed the written value. Most write side
|
2018-03-01 12:05:43 +01:00
|
|
|
* effects should be implemented here. This is called during device reset.
|
2016-07-04 14:06:36 +02:00
|
|
|
*
|
|
|
|
* @post_read: Post read callback. Passes the value that is about to be returned
|
|
|
|
* for a read. The return value from this function is what is ultimately read,
|
|
|
|
* allowing this function to modify the value before return to the client.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct RegisterAccessInfo {
|
|
|
|
const char *name;
|
|
|
|
uint64_t ro;
|
|
|
|
uint64_t w1c;
|
|
|
|
uint64_t reset;
|
|
|
|
uint64_t cor;
|
|
|
|
uint64_t rsvd;
|
|
|
|
uint64_t unimp;
|
|
|
|
|
|
|
|
uint64_t (*pre_write)(RegisterInfo *reg, uint64_t val);
|
|
|
|
void (*post_write)(RegisterInfo *reg, uint64_t val);
|
|
|
|
|
|
|
|
uint64_t (*post_read)(RegisterInfo *reg, uint64_t val);
|
2016-07-04 14:06:36 +02:00
|
|
|
|
|
|
|
hwaddr addr;
|
2016-07-04 14:06:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A register that is part of guest accessible state
|
|
|
|
* @data: pointer to the register data. Will be cast
|
|
|
|
* to the relevant uint type depending on data_size.
|
|
|
|
* @data_size: Size of the register in bytes. Must be
|
|
|
|
* 1, 2, 4 or 8
|
|
|
|
*
|
|
|
|
* @access: Access description of this register
|
|
|
|
*
|
|
|
|
* @debug: Whether or not verbose debug is enabled
|
|
|
|
* @prefix: String prefix for log and debug messages
|
|
|
|
*
|
|
|
|
* @opaque: Opaque data for the register
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct RegisterInfo {
|
2016-07-04 14:06:36 +02:00
|
|
|
/* <private> */
|
|
|
|
DeviceState parent_obj;
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
/* <public> */
|
|
|
|
void *data;
|
|
|
|
int data_size;
|
|
|
|
|
|
|
|
const RegisterAccessInfo *access;
|
|
|
|
|
|
|
|
void *opaque;
|
|
|
|
};
|
|
|
|
|
hw: Replace anti-social QOM type names
Several QOM type names contain ',':
ARM,bitband-memory
etraxfs,pic
etraxfs,serial
etraxfs,timer
fsl,imx25
fsl,imx31
fsl,imx6
fsl,imx6ul
fsl,imx7
grlib,ahbpnp
grlib,apbpnp
grlib,apbuart
grlib,gptimer
grlib,irqmp
qemu,register
SUNW,bpp
SUNW,CS4231
SUNW,DBRI
SUNW,DBRI.prom
SUNW,fdtwo
SUNW,sx
SUNW,tcx
xilinx,zynq_slcr
xlnx,zynqmp
xlnx,zynqmp-pmu-soc
xlnx,zynq-xadc
These are all device types. They can't be plugged with -device /
device_add, except for xlnx,zynqmp-pmu-soc, and I doubt that one
actually works.
They *can* be used with -device / device_add to request help.
Usability is poor, though: you have to double the comma, like this:
$ qemu-system-x86_64 -device SUNW,,fdtwo,help
Trap for the unwary. The fact that this was broken in
device-introspect-test for more than six years until commit e27bd49876
fixed it demonstrates that "the unwary" includes seasoned developers.
One QOM type name contains ' ': "ICH9 SMB". Because having to
remember just one way to quote would be too easy.
Rename the "SUNW,FOO types to "sun-FOO". Summarily replace ',' and '
' by '-' in the other type names.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210304140229.575481-2-armbru@redhat.com>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
2021-03-04 15:02:28 +01:00
|
|
|
#define TYPE_REGISTER "qemu-register"
|
2020-08-31 23:07:33 +02:00
|
|
|
DECLARE_INSTANCE_CHECKER(RegisterInfo, REGISTER,
|
|
|
|
TYPE_REGISTER)
|
2016-07-04 14:06:36 +02:00
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
/**
|
|
|
|
* This structure is used to group all of the individual registers which are
|
|
|
|
* modeled using the RegisterInfo structure.
|
|
|
|
*
|
2016-11-19 20:47:15 +01:00
|
|
|
* @r is an array containing of all the relevant RegisterInfo structures.
|
2016-07-04 14:06:36 +02:00
|
|
|
*
|
|
|
|
* @num_elements is the number of elements in the array r
|
|
|
|
*
|
|
|
|
* @mem: optional Memory region for the register
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct RegisterInfoArray {
|
2016-07-04 14:06:36 +02:00
|
|
|
MemoryRegion mem;
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
int num_elements;
|
|
|
|
RegisterInfo **r;
|
|
|
|
|
|
|
|
bool debug;
|
|
|
|
const char *prefix;
|
|
|
|
};
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
/**
|
|
|
|
* write a value to a register, subject to its restrictions
|
|
|
|
* @reg: register to write to
|
|
|
|
* @val: value to write
|
|
|
|
* @we: write enable mask
|
|
|
|
* @prefix: The device prefix that should be printed before the register name
|
|
|
|
* @debug: Should the write operation debug information be printed?
|
|
|
|
*/
|
|
|
|
|
|
|
|
void register_write(RegisterInfo *reg, uint64_t val, uint64_t we,
|
|
|
|
const char *prefix, bool debug);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* read a value from a register, subject to its restrictions
|
|
|
|
* @reg: register to read from
|
|
|
|
* @re: read enable mask
|
|
|
|
* @prefix: The device prefix that should be printed before the register name
|
|
|
|
* @debug: Should the read operation debug information be printed?
|
|
|
|
* returns: value read
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint64_t register_read(RegisterInfo *reg, uint64_t re, const char* prefix,
|
|
|
|
bool debug);
|
|
|
|
|
|
|
|
/**
|
2018-03-01 12:05:43 +01:00
|
|
|
* Resets a register. This will also call the post_write hook if it exists.
|
|
|
|
* @reg: The register to reset.
|
2016-07-04 14:06:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void register_reset(RegisterInfo *reg);
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
/**
|
|
|
|
* Initialize a register.
|
|
|
|
* @reg: Register to initialize
|
|
|
|
*/
|
|
|
|
|
|
|
|
void register_init(RegisterInfo *reg);
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
/**
|
|
|
|
* Memory API MMIO write handler that will write to a Register API register.
|
|
|
|
* @opaque: RegisterInfo to write to
|
|
|
|
* @addr: Address to write
|
|
|
|
* @value: Value to write
|
|
|
|
* @size: Number of bytes to write
|
|
|
|
*/
|
|
|
|
|
|
|
|
void register_write_memory(void *opaque, hwaddr addr, uint64_t value,
|
|
|
|
unsigned size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Memory API MMIO read handler that will read from a Register API register.
|
|
|
|
* @opaque: RegisterInfo to read from
|
|
|
|
* @addr: Address to read
|
|
|
|
* @size: Number of bytes to read
|
|
|
|
* returns: Value read from register
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint64_t register_read_memory(void *opaque, hwaddr addr, unsigned size);
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
/**
|
|
|
|
* Init a block of registers into a container MemoryRegion. A
|
|
|
|
* number of constant register definitions are parsed to create a corresponding
|
|
|
|
* array of RegisterInfo's.
|
|
|
|
*
|
|
|
|
* @owner: device owning the registers
|
|
|
|
* @rae: Register definitions to init
|
|
|
|
* @num: number of registers to init (length of @rae)
|
|
|
|
* @ri: Register array to init, must already be allocated
|
|
|
|
* @data: Array to use for register data, must already be allocated
|
|
|
|
* @ops: Memory region ops to access registers.
|
|
|
|
* @debug enabled: turn on/off verbose debug information
|
2020-07-07 08:23:08 +02:00
|
|
|
* @memory_size: Size of the memory region
|
2016-07-04 14:06:36 +02:00
|
|
|
* returns: A structure containing all of the registers and an initialized
|
|
|
|
* memory region (r_array->mem) the caller should add to a container.
|
|
|
|
*/
|
|
|
|
|
2020-04-02 18:28:39 +02:00
|
|
|
RegisterInfoArray *register_init_block8(DeviceState *owner,
|
|
|
|
const RegisterAccessInfo *rae,
|
|
|
|
int num, RegisterInfo *ri,
|
|
|
|
uint8_t *data,
|
|
|
|
const MemoryRegionOps *ops,
|
|
|
|
bool debug_enabled,
|
|
|
|
uint64_t memory_size);
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
RegisterInfoArray *register_init_block32(DeviceState *owner,
|
|
|
|
const RegisterAccessInfo *rae,
|
|
|
|
int num, RegisterInfo *ri,
|
|
|
|
uint32_t *data,
|
|
|
|
const MemoryRegionOps *ops,
|
|
|
|
bool debug_enabled,
|
|
|
|
uint64_t memory_size);
|
|
|
|
|
2021-07-20 20:31:42 +02:00
|
|
|
RegisterInfoArray *register_init_block64(DeviceState *owner,
|
|
|
|
const RegisterAccessInfo *rae,
|
|
|
|
int num, RegisterInfo *ri,
|
|
|
|
uint64_t *data,
|
|
|
|
const MemoryRegionOps *ops,
|
|
|
|
bool debug_enabled,
|
|
|
|
uint64_t memory_size);
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
/**
|
|
|
|
* This function should be called to cleanup the registers that were initialized
|
|
|
|
* when calling register_init_block32(). This function should only be called
|
|
|
|
* from the device's instance_finalize function.
|
|
|
|
*
|
|
|
|
* Any memory operations that the device performed that require cleanup (such
|
|
|
|
* as creating subregions) need to be called before calling this function.
|
|
|
|
*
|
|
|
|
* @r_array: A structure containing all of the registers, as returned by
|
|
|
|
* register_init_block32()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void register_finalize_block(RegisterInfoArray *r_array);
|
|
|
|
|
2016-07-04 14:06:36 +02:00
|
|
|
#endif
|