1

cxl: Use of_property_ accessor functions

The CXL driver has its own custom implementations of typed DT property
accessors. Replace the custom property accessor functions with the
common DT property functions.

This clean-up is part of a larger effort to remove of_get_property() and
other DT functions which leak pointers to DT node and property data.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Link: https://lore.kernel.org/r/20240729-dt-cxl-cleanup-v1-2-a75eea80d231@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Rob Herring (Arm) 2024-07-29 16:36:44 -06:00 committed by Greg Kroah-Hartman
parent 35fc26541f
commit 5c4efc6055
2 changed files with 33 additions and 105 deletions

View File

@ -7,59 +7,12 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/of.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include "cxl.h" #include "cxl.h"
static const __be32 *read_prop_string(const struct device_node *np,
const char *prop_name)
{
const __be32 *prop;
prop = of_get_property(np, prop_name, NULL);
return prop;
}
static const __be32 *read_prop_dword(const struct device_node *np,
const char *prop_name, u32 *val)
{
const __be32 *prop;
prop = of_get_property(np, prop_name, NULL);
if (prop)
*val = be32_to_cpu(prop[0]);
return prop;
}
static const __be64 *read_prop64_dword(const struct device_node *np,
const char *prop_name, u64 *val)
{
const __be64 *prop;
prop = of_get_property(np, prop_name, NULL);
if (prop)
*val = be64_to_cpu(prop[0]);
return prop;
}
static int read_handle(struct device_node *np, u64 *handle)
{
const __be32 *prop;
u64 size;
/* Get address and size of the node */
prop = of_get_address(np, 0, &size, NULL);
if (size)
return -EINVAL;
/* Helper to read a big number; size is in cells (not bytes) */
*handle = of_read_number(prop, of_n_addr_cells(np));
return 0;
}
static int read_phys_addr(struct device_node *np, char *prop_name, static int read_phys_addr(struct device_node *np, char *prop_name,
struct cxl_afu *afu) struct cxl_afu *afu)
{ {
@ -121,17 +74,12 @@ static int read_vpd(struct cxl *adapter, struct cxl_afu *afu)
int cxl_of_read_afu_handle(struct cxl_afu *afu, struct device_node *afu_np) int cxl_of_read_afu_handle(struct cxl_afu *afu, struct device_node *afu_np)
{ {
if (read_handle(afu_np, &afu->guest->handle)) return of_property_read_reg(afu_np, 0, &afu->guest->handle, NULL);
return -EINVAL;
pr_devel("AFU handle: 0x%.16llx\n", afu->guest->handle);
return 0;
} }
int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np) int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
{ {
int i, rc; int i, rc;
const __be32 *prop;
u16 device_id, vendor_id; u16 device_id, vendor_id;
u32 val = 0, class_code; u32 val = 0, class_code;
@ -150,16 +98,15 @@ int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
else else
afu->psa = true; afu->psa = true;
read_prop_dword(np, "ibm,#processes", &afu->max_procs_virtualised); of_property_read_u32(np, "ibm,#processes", &afu->max_procs_virtualised);
if (cxl_verbose) if (cxl_verbose)
read_vpd(NULL, afu); read_vpd(NULL, afu);
read_prop_dword(np, "ibm,max-ints-per-process", &afu->guest->max_ints); of_property_read_u32(np, "ibm,max-ints-per-process", &afu->guest->max_ints);
afu->irqs_max = afu->guest->max_ints; afu->irqs_max = afu->guest->max_ints;
prop = read_prop_dword(np, "ibm,min-ints-per-process", &afu->pp_irqs); if (!of_property_read_u32(np, "ibm,min-ints-per-process", &afu->pp_irqs)) {
if (prop) {
/* One extra interrupt for the PSL interrupt is already /* One extra interrupt for the PSL interrupt is already
* included. Remove it now to keep only AFU interrupts and * included. Remove it now to keep only AFU interrupts and
* match the native case. * match the native case.
@ -167,13 +114,13 @@ int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
afu->pp_irqs--; afu->pp_irqs--;
} }
read_prop64_dword(np, "ibm,error-buffer-size", &afu->eb_len); of_property_read_u64(np, "ibm,error-buffer-size", &afu->eb_len);
afu->eb_offset = 0; afu->eb_offset = 0;
read_prop64_dword(np, "ibm,config-record-size", &afu->crs_len); of_property_read_u64(np, "ibm,config-record-size", &afu->crs_len);
afu->crs_offset = 0; afu->crs_offset = 0;
read_prop_dword(np, "ibm,#config-records", &afu->crs_num); of_property_read_u32(np, "ibm,#config-records", &afu->crs_num);
if (cxl_verbose) { if (cxl_verbose) {
for (i = 0; i < afu->crs_num; i++) { for (i = 0; i < afu->crs_num; i++) {
@ -201,14 +148,12 @@ int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
* not supported * not supported
*/ */
val = 0; val = 0;
prop = read_prop_dword(np, "ibm,process-mmio", &val); if (!of_property_read_u32(np, "ibm,process-mmio", &val) && val == 1)
if (prop && val == 1)
afu->pp_psa = true; afu->pp_psa = true;
else else
afu->pp_psa = false; afu->pp_psa = false;
prop = read_prop_dword(np, "ibm,function-error-interrupt", &val); if (!of_property_read_u32(np, "ibm,function-error-interrupt", &val))
if (prop)
afu->serr_hwirq = val; afu->serr_hwirq = val;
pr_devel("AFU handle: %#llx\n", afu->guest->handle); pr_devel("AFU handle: %#llx\n", afu->guest->handle);
@ -279,17 +224,13 @@ err:
int cxl_of_read_adapter_handle(struct cxl *adapter, struct device_node *np) int cxl_of_read_adapter_handle(struct cxl *adapter, struct device_node *np)
{ {
if (read_handle(np, &adapter->guest->handle)) return of_property_read_reg(np, 0, &adapter->guest->handle, NULL);
return -EINVAL;
pr_devel("Adapter handle: 0x%.16llx\n", adapter->guest->handle);
return 0;
} }
int cxl_of_read_adapter_properties(struct cxl *adapter, struct device_node *np) int cxl_of_read_adapter_properties(struct cxl *adapter, struct device_node *np)
{ {
int rc; int rc;
const __be32 *prop; const char *p;
u32 val = 0; u32 val = 0;
/* Properties are read in the same order as listed in PAPR */ /* Properties are read in the same order as listed in PAPR */
@ -297,37 +238,30 @@ int cxl_of_read_adapter_properties(struct cxl *adapter, struct device_node *np)
if ((rc = read_adapter_irq_config(adapter, np))) if ((rc = read_adapter_irq_config(adapter, np)))
return rc; return rc;
prop = read_prop_dword(np, "ibm,caia-version", &val); if (!of_property_read_u32(np, "ibm,caia-version", &val)) {
if (prop) {
adapter->caia_major = (val & 0xFF00) >> 8; adapter->caia_major = (val & 0xFF00) >> 8;
adapter->caia_minor = val & 0xFF; adapter->caia_minor = val & 0xFF;
} }
prop = read_prop_dword(np, "ibm,psl-revision", &val); if (!of_property_read_u32(np, "ibm,psl-revision", &val))
if (prop)
adapter->psl_rev = val; adapter->psl_rev = val;
prop = read_prop_string(np, "status"); if (!of_property_read_string(np, "status", &p)) {
if (prop) { adapter->guest->status = kasprintf(GFP_KERNEL, "%s", p);
adapter->guest->status = kasprintf(GFP_KERNEL, "%s", (char *) prop);
if (adapter->guest->status == NULL) if (adapter->guest->status == NULL)
return -ENOMEM; return -ENOMEM;
} }
prop = read_prop_dword(np, "vendor-id", &val); if (!of_property_read_u32(np, "vendor-id", &val))
if (prop)
adapter->guest->vendor = val; adapter->guest->vendor = val;
prop = read_prop_dword(np, "device-id", &val); if (!of_property_read_u32(np, "device-id", &val))
if (prop)
adapter->guest->device = val; adapter->guest->device = val;
prop = read_prop_dword(np, "subsystem-vendor-id", &val); if (!of_property_read_u32(np, "subsystem-vendor-id", &val))
if (prop)
adapter->guest->subsystem_vendor = val; adapter->guest->subsystem_vendor = val;
prop = read_prop_dword(np, "subsystem-id", &val); if (!of_property_read_u32(np, "subsystem-id", &val))
if (prop)
adapter->guest->subsystem = val; adapter->guest->subsystem = val;
if (cxl_verbose) if (cxl_verbose)

View File

@ -363,17 +363,17 @@ int cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid,
{ {
int rc; int rc;
struct device_node *np; struct device_node *np;
const __be32 *prop; u32 id;
if (!(np = pnv_pci_get_phb_node(dev))) if (!(np = pnv_pci_get_phb_node(dev)))
return -ENODEV; return -ENODEV;
while (np && !(prop = of_get_property(np, "ibm,chip-id", NULL))) while (np && of_property_read_u32(np, "ibm,chip-id", &id))
np = of_get_next_parent(np); np = of_get_next_parent(np);
if (!np) if (!np)
return -ENODEV; return -ENODEV;
*chipid = be32_to_cpup(prop); *chipid = id;
rc = get_phb_index(np, phb_index); rc = get_phb_index(np, phb_index);
if (rc) { if (rc) {
@ -398,32 +398,26 @@ static DEFINE_MUTEX(indications_mutex);
static int get_phb_indications(struct pci_dev *dev, u64 *capiind, u64 *asnind, static int get_phb_indications(struct pci_dev *dev, u64 *capiind, u64 *asnind,
u64 *nbwind) u64 *nbwind)
{ {
static u64 nbw, asn, capi = 0; static u32 val[3];
struct device_node *np; struct device_node *np;
const __be32 *prop;
mutex_lock(&indications_mutex); mutex_lock(&indications_mutex);
if (!capi) { if (!val[0]) {
if (!(np = pnv_pci_get_phb_node(dev))) { if (!(np = pnv_pci_get_phb_node(dev))) {
mutex_unlock(&indications_mutex); mutex_unlock(&indications_mutex);
return -ENODEV; return -ENODEV;
} }
prop = of_get_property(np, "ibm,phb-indications", NULL); if (of_property_read_u32_array(np, "ibm,phb-indications", val, 3)) {
if (!prop) { val[2] = 0x0300UL; /* legacy values */
nbw = 0x0300UL; /* legacy values */ val[1] = 0x0400UL;
asn = 0x0400UL; val[0] = 0x0200UL;
capi = 0x0200UL;
} else {
nbw = (u64)be32_to_cpu(prop[2]);
asn = (u64)be32_to_cpu(prop[1]);
capi = (u64)be32_to_cpu(prop[0]);
} }
of_node_put(np); of_node_put(np);
} }
*capiind = capi; *capiind = val[0];
*asnind = asn; *asnind = val[1];
*nbwind = nbw; *nbwind = val[2];
mutex_unlock(&indications_mutex); mutex_unlock(&indications_mutex);
return 0; return 0;
} }
@ -605,7 +599,7 @@ static void cxl_setup_psl_timebase(struct cxl *adapter, struct pci_dev *dev)
/* Do not fail when CAPP timebase sync is not supported by OPAL */ /* Do not fail when CAPP timebase sync is not supported by OPAL */
of_node_get(np); of_node_get(np);
if (! of_get_property(np, "ibm,capp-timebase-sync", NULL)) { if (!of_property_present(np, "ibm,capp-timebase-sync")) {
of_node_put(np); of_node_put(np);
dev_info(&dev->dev, "PSL timebase inactive: OPAL support missing\n"); dev_info(&dev->dev, "PSL timebase inactive: OPAL support missing\n");
return; return;