-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cxl/pci: Find and register CXL PMU devices
CXL PMU devices can be found from entries in the Register Locator DVSEC. Reviewed-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/20230526095824.16336-4-Jonathan.Cameron@huawei.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
- Loading branch information
Jonathan Cameron
authored and
Dan Williams
committed
May 30, 2023
1 parent
d717d7f
commit 1ad3f70
Showing
10 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* Copyright(c) 2023 Huawei. All rights reserved. */ | ||
|
||
#include <linux/device.h> | ||
#include <linux/slab.h> | ||
#include <linux/idr.h> | ||
#include <cxlmem.h> | ||
#include <pmu.h> | ||
#include <cxl.h> | ||
#include "core.h" | ||
|
||
static void cxl_pmu_release(struct device *dev) | ||
{ | ||
struct cxl_pmu *pmu = to_cxl_pmu(dev); | ||
|
||
kfree(pmu); | ||
} | ||
|
||
const struct device_type cxl_pmu_type = { | ||
.name = "cxl_pmu", | ||
.release = cxl_pmu_release, | ||
}; | ||
|
||
static void remove_dev(void *dev) | ||
{ | ||
device_del(dev); | ||
} | ||
|
||
int devm_cxl_pmu_add(struct device *parent, struct cxl_pmu_regs *regs, | ||
int assoc_id, int index, enum cxl_pmu_type type) | ||
{ | ||
struct cxl_pmu *pmu; | ||
struct device *dev; | ||
int rc; | ||
|
||
pmu = kzalloc(sizeof(*pmu), GFP_KERNEL); | ||
if (!pmu) | ||
return -ENOMEM; | ||
|
||
pmu->assoc_id = assoc_id; | ||
pmu->index = index; | ||
pmu->type = type; | ||
pmu->base = regs->pmu; | ||
dev = &pmu->dev; | ||
device_initialize(dev); | ||
device_set_pm_not_required(dev); | ||
dev->parent = parent; | ||
dev->bus = &cxl_bus_type; | ||
dev->type = &cxl_pmu_type; | ||
switch (pmu->type) { | ||
case CXL_PMU_MEMDEV: | ||
rc = dev_set_name(dev, "pmu_mem%d.%d", assoc_id, index); | ||
break; | ||
} | ||
if (rc) | ||
goto err; | ||
|
||
rc = device_add(dev); | ||
if (rc) | ||
goto err; | ||
|
||
return devm_add_action_or_reset(parent, remove_dev, dev); | ||
|
||
err: | ||
put_device(&pmu->dev); | ||
return rc; | ||
} | ||
EXPORT_SYMBOL_NS_GPL(devm_cxl_pmu_add, CXL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Copyright(c) 2023 Huawei | ||
* CXL Specification rev 3.0 Setion 8.2.7 (CPMU Register Interface) | ||
*/ | ||
#ifndef CXL_PMU_H | ||
#define CXL_PMU_H | ||
#include <linux/device.h> | ||
|
||
enum cxl_pmu_type { | ||
CXL_PMU_MEMDEV, | ||
}; | ||
|
||
#define CXL_PMU_REGMAP_SIZE 0xe00 /* Table 8-32 CXL 3.0 specification */ | ||
struct cxl_pmu { | ||
struct device dev; | ||
void __iomem *base; | ||
int assoc_id; | ||
int index; | ||
enum cxl_pmu_type type; | ||
}; | ||
|
||
#define to_cxl_pmu(dev) container_of(dev, struct cxl_pmu, dev) | ||
struct cxl_pmu_regs; | ||
int devm_cxl_pmu_add(struct device *parent, struct cxl_pmu_regs *regs, | ||
int assoc_id, int idx, enum cxl_pmu_type type); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters