hw/cxl: Add CXL_CAPACITY_MULTIPLIER definition

Remove usage of magic numbers when accessing capacity fields and replace
with CXL_CAPACITY_MULTIPLIER, matching the kernel definition.

Signed-off-by: Gregory Price <gregory.price@memverge.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Message-Id: <20230206172816.8201-5-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Gregory Price 2023-02-06 17:28:10 +00:00 committed by Michael S. Tsirkin
parent 2ef5063610
commit 1c580bed9a

View File

@ -12,8 +12,11 @@
#include "hw/pci/pci.h" #include "hw/pci/pci.h"
#include "qemu/cutils.h" #include "qemu/cutils.h"
#include "qemu/log.h" #include "qemu/log.h"
#include "qemu/units.h"
#include "qemu/uuid.h" #include "qemu/uuid.h"
#define CXL_CAPACITY_MULTIPLIER (256 * MiB)
/* /*
* How to add a new command, example. The command set FOO, with cmd BAR. * How to add a new command, example. The command set FOO, with cmd BAR.
* 1. Add the command set and cmd to the enum. * 1. Add the command set and cmd to the enum.
@ -138,7 +141,7 @@ static ret_code cmd_firmware_update_get_info(struct cxl_cmd *cmd,
} QEMU_PACKED *fw_info; } QEMU_PACKED *fw_info;
QEMU_BUILD_BUG_ON(sizeof(*fw_info) != 0x50); QEMU_BUILD_BUG_ON(sizeof(*fw_info) != 0x50);
if (cxl_dstate->pmem_size < (256 << 20)) { if (cxl_dstate->pmem_size < CXL_CAPACITY_MULTIPLIER) {
return CXL_MBOX_INTERNAL_ERROR; return CXL_MBOX_INTERNAL_ERROR;
} }
@ -283,7 +286,7 @@ static ret_code cmd_identify_memory_device(struct cxl_cmd *cmd,
CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d); CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d);
uint64_t size = cxl_dstate->pmem_size; uint64_t size = cxl_dstate->pmem_size;
if (!QEMU_IS_ALIGNED(size, 256 << 20)) { if (!QEMU_IS_ALIGNED(size, CXL_CAPACITY_MULTIPLIER)) {
return CXL_MBOX_INTERNAL_ERROR; return CXL_MBOX_INTERNAL_ERROR;
} }
@ -293,8 +296,8 @@ static ret_code cmd_identify_memory_device(struct cxl_cmd *cmd,
/* PMEM only */ /* PMEM only */
snprintf(id->fw_revision, 0x10, "BWFW VERSION %02d", 0); snprintf(id->fw_revision, 0x10, "BWFW VERSION %02d", 0);
id->total_capacity = size / (256 << 20); id->total_capacity = size / CXL_CAPACITY_MULTIPLIER;
id->persistent_capacity = size / (256 << 20); id->persistent_capacity = size / CXL_CAPACITY_MULTIPLIER;
id->lsa_size = cvc->get_lsa_size(ct3d); id->lsa_size = cvc->get_lsa_size(ct3d);
*len = sizeof(*id); *len = sizeof(*id);
@ -314,14 +317,14 @@ static ret_code cmd_ccls_get_partition_info(struct cxl_cmd *cmd,
QEMU_BUILD_BUG_ON(sizeof(*part_info) != 0x20); QEMU_BUILD_BUG_ON(sizeof(*part_info) != 0x20);
uint64_t size = cxl_dstate->pmem_size; uint64_t size = cxl_dstate->pmem_size;
if (!QEMU_IS_ALIGNED(size, 256 << 20)) { if (!QEMU_IS_ALIGNED(size, CXL_CAPACITY_MULTIPLIER)) {
return CXL_MBOX_INTERNAL_ERROR; return CXL_MBOX_INTERNAL_ERROR;
} }
/* PMEM only */ /* PMEM only */
part_info->active_vmem = 0; part_info->active_vmem = 0;
part_info->next_vmem = 0; part_info->next_vmem = 0;
part_info->active_pmem = size / (256 << 20); part_info->active_pmem = size / CXL_CAPACITY_MULTIPLIER;
part_info->next_pmem = 0; part_info->next_pmem = 0;
*len = sizeof(*part_info); *len = sizeof(*part_info);