Skip to content

Commit 4aa497c

Browse files
committed
Merge branch 'acpi-uid'
Merge ACPI _UID handling unification changes for 6.1-rc1: - Introduce acpi_dev_uid_to_integer() to convert a _UID string into an integer value (Andy Shevchenko). - Use acpi_dev_uid_to_integer() in several places to unify _UID handling (Andy Shevchenko). * acpi-uid: efi/dev-path-parser: Refactor _UID handling to use acpi_dev_uid_to_integer() spi: pxa2xx: Refactor _UID handling to use acpi_dev_uid_to_integer() perf: qcom_l2_pmu: Refactor _UID handling to use acpi_dev_uid_to_integer() i2c: mlxbf: Refactor _UID handling to use acpi_dev_uid_to_integer() i2c: amd-mp2-plat: Refactor _UID handling to use acpi_dev_uid_to_integer() ACPI: x86: Refactor _UID handling to use acpi_dev_uid_to_integer() ACPI: LPSS: Refactor _UID handling to use acpi_dev_uid_to_integer() ACPI: utils: Add acpi_dev_uid_to_integer() helper to get _UID as integer
2 parents a7ece53 + 7fc90e8 commit 4aa497c

File tree

10 files changed

+83
-80
lines changed

10 files changed

+83
-80
lines changed

drivers/acpi/acpi_lpss.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ static struct pwm_lookup byt_pwm_lookup[] = {
167167

168168
static void byt_pwm_setup(struct lpss_private_data *pdata)
169169
{
170-
struct acpi_device *adev = pdata->adev;
170+
u64 uid;
171171

172172
/* Only call pwm_add_table for the first PWM controller */
173-
if (!adev->pnp.unique_id || strcmp(adev->pnp.unique_id, "1"))
173+
if (acpi_dev_uid_to_integer(pdata->adev, &uid) || uid != 1)
174174
return;
175175

176176
pwm_add_table(byt_pwm_lookup, ARRAY_SIZE(byt_pwm_lookup));
@@ -180,14 +180,13 @@ static void byt_pwm_setup(struct lpss_private_data *pdata)
180180

181181
static void byt_i2c_setup(struct lpss_private_data *pdata)
182182
{
183-
const char *uid_str = acpi_device_uid(pdata->adev);
184183
acpi_handle handle = pdata->adev->handle;
185184
unsigned long long shared_host = 0;
186185
acpi_status status;
187-
long uid = 0;
186+
u64 uid;
188187

189-
/* Expected to always be true, but better safe then sorry */
190-
if (uid_str && !kstrtol(uid_str, 10, &uid) && uid) {
188+
/* Expected to always be successfull, but better safe then sorry */
189+
if (!acpi_dev_uid_to_integer(pdata->adev, &uid) && uid) {
191190
/* Detect I2C bus shared with PUNIT and ignore its d3 status */
192191
status = acpi_evaluate_integer(handle, "_SEM", NULL, &shared_host);
193192
if (ACPI_SUCCESS(status) && shared_host)
@@ -211,10 +210,10 @@ static struct pwm_lookup bsw_pwm_lookup[] = {
211210

212211
static void bsw_pwm_setup(struct lpss_private_data *pdata)
213212
{
214-
struct acpi_device *adev = pdata->adev;
213+
u64 uid;
215214

216215
/* Only call pwm_add_table for the first PWM controller */
217-
if (!adev->pnp.unique_id || strcmp(adev->pnp.unique_id, "1"))
216+
if (acpi_dev_uid_to_integer(pdata->adev, &uid) || uid != 1)
218217
return;
219218

220219
pwm_add_table(bsw_pwm_lookup, ARRAY_SIZE(bsw_pwm_lookup));

drivers/acpi/utils.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,30 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev,
793793
}
794794
EXPORT_SYMBOL(acpi_dev_hid_uid_match);
795795

796+
/**
797+
* acpi_dev_uid_to_integer - treat ACPI device _UID as integer
798+
* @adev: ACPI device to get _UID from
799+
* @integer: output buffer for integer
800+
*
801+
* Considers _UID as integer and converts it to @integer.
802+
*
803+
* Returns 0 on success, or negative error code otherwise.
804+
*/
805+
int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer)
806+
{
807+
const char *uid;
808+
809+
if (!adev)
810+
return -ENODEV;
811+
812+
uid = acpi_device_uid(adev);
813+
if (!uid)
814+
return -ENODATA;
815+
816+
return kstrtou64(uid, 0, integer);
817+
}
818+
EXPORT_SYMBOL(acpi_dev_uid_to_integer);
819+
796820
/**
797821
* acpi_dev_found - Detect presence of a given ACPI device in the namespace.
798822
* @hid: Hardware ID of the device.

drivers/acpi/x86/utils.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,22 +368,28 @@ int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *s
368368
struct acpi_device *adev = ACPI_COMPANION(controller_parent);
369369
const struct dmi_system_id *dmi_id;
370370
long quirks = 0;
371+
u64 uid;
372+
int ret;
371373

372374
*skip = false;
373375

374-
/* !dev_is_platform() to not match on PNP enumerated debug UARTs */
375-
if (!adev || !adev->pnp.unique_id || !dev_is_platform(controller_parent))
376+
ret = acpi_dev_uid_to_integer(adev, &uid);
377+
if (ret)
378+
return 0;
379+
380+
/* to not match on PNP enumerated debug UARTs */
381+
if (!dev_is_platform(controller_parent))
376382
return 0;
377383

378384
dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
379385
if (dmi_id)
380386
quirks = (unsigned long)dmi_id->driver_data;
381387

382388
if (quirks & ACPI_QUIRK_UART1_TTY_UART2_SKIP) {
383-
if (!strcmp(adev->pnp.unique_id, "1"))
389+
if (uid == 1)
384390
return -ENODEV; /* Create tty cdev instead of serdev */
385391

386-
if (!strcmp(adev->pnp.unique_id, "2"))
392+
if (uid == 2)
387393
*skip = true;
388394
}
389395

drivers/firmware/efi/dev-path-parser.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
static long __init parse_acpi_path(const struct efi_dev_path *node,
1616
struct device *parent, struct device **child)
1717
{
18-
char hid[ACPI_ID_LEN], uid[11]; /* UINT_MAX + null byte */
1918
struct acpi_device *adev;
2019
struct device *phys_dev;
20+
char hid[ACPI_ID_LEN];
21+
u64 uid;
22+
int ret;
2123

2224
if (node->header.length != 12)
2325
return -EINVAL;
@@ -27,12 +29,12 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
2729
'A' + ((node->acpi.hid >> 5) & 0x1f) - 1,
2830
'A' + ((node->acpi.hid >> 0) & 0x1f) - 1,
2931
node->acpi.hid >> 16);
30-
sprintf(uid, "%u", node->acpi.uid);
3132

3233
for_each_acpi_dev_match(adev, hid, NULL, -1) {
33-
if (adev->pnp.unique_id && !strcmp(adev->pnp.unique_id, uid))
34+
ret = acpi_dev_uid_to_integer(adev, &uid);
35+
if (ret == 0 && node->acpi.uid == uid)
3436
break;
35-
if (!adev->pnp.unique_id && node->acpi.uid == 0)
37+
if (ret == -ENODATA && node->acpi.uid == 0)
3638
break;
3739
}
3840
if (!adev)

drivers/i2c/busses/i2c-amd-mp2-plat.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,18 @@ static const struct i2c_adapter_quirks amd_i2c_dev_quirks = {
244244

245245
static int i2c_amd_probe(struct platform_device *pdev)
246246
{
247+
struct device *dev = &pdev->dev;
247248
int ret;
248249
struct amd_i2c_dev *i2c_dev;
249-
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
250250
struct amd_mp2_dev *mp2_dev;
251-
const char *uid;
251+
u64 uid;
252252

253-
if (!adev)
254-
return -ENODEV;
253+
ret = acpi_dev_uid_to_integer(ACPI_COMPANION(dev), &uid);
254+
if (ret)
255+
return dev_err_probe(dev, ret, "missing UID/bus id!\n");
256+
if (uid >= 2)
257+
return dev_err_probe(dev, -EINVAL, "incorrect UID/bus id \"%llu\"!\n", uid);
258+
dev_dbg(dev, "bus id is %llu\n", uid);
255259

256260
/* The ACPI namespace doesn't contain information about which MP2 PCI
257261
* device an AMDI0011 ACPI device is related to, so assume that there's
@@ -266,6 +270,7 @@ static int i2c_amd_probe(struct platform_device *pdev)
266270
if (!i2c_dev)
267271
return -ENOMEM;
268272

273+
i2c_dev->common.bus_id = uid;
269274
i2c_dev->common.mp2_dev = mp2_dev;
270275
i2c_dev->pdev = pdev;
271276
platform_set_drvdata(pdev, i2c_dev);
@@ -276,20 +281,6 @@ static int i2c_amd_probe(struct platform_device *pdev)
276281
i2c_dev->common.resume = &i2c_amd_resume;
277282
#endif
278283

279-
uid = adev->pnp.unique_id;
280-
if (!uid) {
281-
dev_err(&pdev->dev, "missing UID/bus id!\n");
282-
return -EINVAL;
283-
} else if (strcmp(uid, "0") == 0) {
284-
i2c_dev->common.bus_id = 0;
285-
} else if (strcmp(uid, "1") == 0) {
286-
i2c_dev->common.bus_id = 1;
287-
} else {
288-
dev_err(&pdev->dev, "incorrect UID/bus id \"%s\"!\n", uid);
289-
return -EINVAL;
290-
}
291-
dev_dbg(&pdev->dev, "bus id is %u\n", i2c_dev->common.bus_id);
292-
293284
/* Register the adapter */
294285
amd_mp2_pm_runtime_get(mp2_dev);
295286

drivers/i2c/busses/i2c-mlxbf.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,35 +2229,27 @@ MODULE_DEVICE_TABLE(acpi, mlxbf_i2c_acpi_ids);
22292229
static int mlxbf_i2c_acpi_probe(struct device *dev, struct mlxbf_i2c_priv *priv)
22302230
{
22312231
const struct acpi_device_id *aid;
2232-
struct acpi_device *adev;
2233-
unsigned long bus_id = 0;
2234-
const char *uid;
2232+
u64 bus_id;
22352233
int ret;
22362234

22372235
if (acpi_disabled)
22382236
return -ENOENT;
22392237

2240-
adev = ACPI_COMPANION(dev);
2241-
if (!adev)
2242-
return -ENXIO;
2243-
22442238
aid = acpi_match_device(mlxbf_i2c_acpi_ids, dev);
22452239
if (!aid)
22462240
return -ENODEV;
22472241

22482242
priv->chip = (struct mlxbf_i2c_chip_info *)aid->driver_data;
22492243

2250-
uid = acpi_device_uid(adev);
2251-
if (!uid || !(*uid)) {
2244+
ret = acpi_dev_uid_to_integer(ACPI_COMPANION(dev), &bus_id);
2245+
if (ret) {
22522246
dev_err(dev, "Cannot retrieve UID\n");
2253-
return -ENODEV;
2247+
return ret;
22542248
}
22552249

2256-
ret = kstrtoul(uid, 0, &bus_id);
2257-
if (!ret)
2258-
priv->bus = bus_id;
2250+
priv->bus = bus_id;
22592251

2260-
return ret;
2252+
return 0;
22612253
}
22622254
#else
22632255
static int mlxbf_i2c_acpi_probe(struct device *dev, struct mlxbf_i2c_priv *priv)

drivers/perf/qcom_l2_pmu.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,16 +840,16 @@ static int l2_cache_pmu_probe_cluster(struct device *dev, void *data)
840840
{
841841
struct platform_device *pdev = to_platform_device(dev->parent);
842842
struct platform_device *sdev = to_platform_device(dev);
843-
struct acpi_device *adev = ACPI_COMPANION(dev);
844843
struct l2cache_pmu *l2cache_pmu = data;
845844
struct cluster_pmu *cluster;
846-
unsigned long fw_cluster_id;
845+
u64 fw_cluster_id;
847846
int err;
848847
int irq;
849848

850-
if (!adev || kstrtoul(adev->pnp.unique_id, 10, &fw_cluster_id) < 0) {
849+
err = acpi_dev_uid_to_integer(ACPI_COMPANION(dev), &fw_cluster_id);
850+
if (err) {
851851
dev_err(&pdev->dev, "unable to read ACPI uid\n");
852-
return -ENODEV;
852+
return err;
853853
}
854854

855855
cluster = devm_kzalloc(&pdev->dev, sizeof(*cluster), GFP_KERNEL);
@@ -879,7 +879,7 @@ static int l2_cache_pmu_probe_cluster(struct device *dev, void *data)
879879
}
880880

881881
dev_info(&pdev->dev,
882-
"Registered L2 cache PMU cluster %ld\n", fw_cluster_id);
882+
"Registered L2 cache PMU cluster %lld\n", fw_cluster_id);
883883

884884
spin_lock_init(&cluster->pmu_lock);
885885

drivers/spi/spi-pxa2xx.c

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,31 +1441,6 @@ static const struct of_device_id pxa2xx_spi_of_match[] = {
14411441
};
14421442
MODULE_DEVICE_TABLE(of, pxa2xx_spi_of_match);
14431443

1444-
#ifdef CONFIG_ACPI
1445-
1446-
static int pxa2xx_spi_get_port_id(struct device *dev)
1447-
{
1448-
struct acpi_device *adev;
1449-
unsigned int devid;
1450-
int port_id = -1;
1451-
1452-
adev = ACPI_COMPANION(dev);
1453-
if (adev && adev->pnp.unique_id &&
1454-
!kstrtouint(adev->pnp.unique_id, 0, &devid))
1455-
port_id = devid;
1456-
return port_id;
1457-
}
1458-
1459-
#else /* !CONFIG_ACPI */
1460-
1461-
static int pxa2xx_spi_get_port_id(struct device *dev)
1462-
{
1463-
return -1;
1464-
}
1465-
1466-
#endif /* CONFIG_ACPI */
1467-
1468-
14691444
#ifdef CONFIG_PCI
14701445

14711446
static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
@@ -1479,13 +1454,16 @@ static struct pxa2xx_spi_controller *
14791454
pxa2xx_spi_init_pdata(struct platform_device *pdev)
14801455
{
14811456
struct pxa2xx_spi_controller *pdata;
1457+
struct device *dev = &pdev->dev;
1458+
struct device *parent = dev->parent;
14821459
struct ssp_device *ssp;
14831460
struct resource *res;
1484-
struct device *parent = pdev->dev.parent;
14851461
struct pci_dev *pcidev = dev_is_pci(parent) ? to_pci_dev(parent) : NULL;
14861462
const struct pci_device_id *pcidev_id = NULL;
14871463
enum pxa_ssp_type type;
14881464
const void *match;
1465+
int status;
1466+
u64 uid;
14891467

14901468
if (pcidev)
14911469
pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match, pcidev);
@@ -1529,7 +1507,12 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
15291507

15301508
ssp->type = type;
15311509
ssp->dev = &pdev->dev;
1532-
ssp->port_id = pxa2xx_spi_get_port_id(&pdev->dev);
1510+
1511+
status = acpi_dev_uid_to_integer(ACPI_COMPANION(dev), &uid);
1512+
if (status)
1513+
ssp->port_id = -1;
1514+
else
1515+
ssp->port_id = uid;
15331516

15341517
pdata->is_slave = device_property_read_bool(&pdev->dev, "spi-slave");
15351518
pdata->num_chipselect = 1;

include/acpi/acpi_bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
738738
}
739739

740740
bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
741+
int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer);
741742

742743
void acpi_dev_clear_dependencies(struct acpi_device *supplier);
743744
bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);

include/linux/acpi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,11 @@ acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *u
802802
return false;
803803
}
804804

805+
static inline int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer)
806+
{
807+
return -ENODEV;
808+
}
809+
805810
static inline struct acpi_device *
806811
acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
807812
{

0 commit comments

Comments
 (0)