qemu-patch-raspberry4/include/hw/ppc/vof.h
Alexey Kardashevskiy 14c7e06e72 ppc/vof: Fix Coverity issues
Coverity reported issues which are caused by mixing of signed return codes
from DTC and unsigned return codes of the client interface.

This introduces PROM_ERROR and makes distinction between the error types.

This fixes NEGATIVE_RETURNS, OVERRUN issues reported by Coverity.

This adds a comment about the return parameters number in the VOF hcall.
The reason for such counting is to keep the numbers look the same in
vof_client_handle() and the Linux (an OF client).

vmc->client_architecture_support() returns target_ulong and we want to
propagate this to the client (for example H_MULTI_THREADS_ACTIVE).
The VOF path to do_client_architecture_support() needs chopping off
the top 32bit but SLOF's H_CAS does not; and either way the return values
are either 0 or 32bit negative error code. For now this chops
the top 32bits.

This makes "claim" fail if the allocated address is above 4GB as
the client interface is 32bit. This still allows claiming memory above
4GB as potentially initrd can be put there and the client can read
the address from the FDT's "available" property.

Fixes: CID 1458139, 1458138, 1458137, 1458133, 1458132
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Message-Id: <20210720050726.2737405-1-aik@ozlabs.ru>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-07-29 10:59:49 +10:00

61 lines
2 KiB
C

/*
* Virtual Open Firmware
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef HW_VOF_H
#define HW_VOF_H
typedef struct Vof {
uint64_t top_addr; /* copied from rma_size */
GArray *claimed; /* array of SpaprOfClaimed */
uint64_t claimed_base;
GHashTable *of_instances; /* ihandle -> SpaprOfInstance */
uint32_t of_instance_last;
char *bootargs;
long fw_size;
} Vof;
int vof_client_call(MachineState *ms, Vof *vof, void *fdt,
target_ulong args_real);
uint64_t vof_claim(Vof *vof, uint64_t virt, uint64_t size, uint64_t align);
void vof_init(Vof *vof, uint64_t top_addr, Error **errp);
void vof_cleanup(Vof *vof);
void vof_build_dt(void *fdt, Vof *vof);
uint32_t vof_client_open_store(void *fdt, Vof *vof, const char *nodename,
const char *prop, const char *path);
#define TYPE_VOF_MACHINE_IF "vof-machine-if"
typedef struct VofMachineIfClass VofMachineIfClass;
DECLARE_CLASS_CHECKERS(VofMachineIfClass, VOF_MACHINE, TYPE_VOF_MACHINE_IF)
struct VofMachineIfClass {
InterfaceClass parent;
target_ulong (*client_architecture_support)(MachineState *ms, CPUState *cs,
target_ulong vec);
void (*quiesce)(MachineState *ms);
bool (*setprop)(MachineState *ms, const char *path, const char *propname,
void *val, int vallen);
};
/*
* Initial stack size is from
* https://www.devicetree.org/open-firmware/bindings/ppc/release/ppc-2_1.html#REF27292
*
* "Client programs shall be invoked with a valid stack pointer (r1) with
* at least 32K bytes of memory available for stack growth".
*/
#define VOF_STACK_SIZE 0x8000
#define VOF_MEM_READ(pa, buf, size) \
address_space_read(&address_space_memory, \
(pa), MEMTXATTRS_UNSPECIFIED, (buf), (size))
#define VOF_MEM_WRITE(pa, buf, size) \
address_space_write(&address_space_memory, \
(pa), MEMTXATTRS_UNSPECIFIED, (buf), (size))
#define PROM_ERROR (~0U)
#endif /* HW_VOF_H */