forked from torvalds/linux
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
cxl/mem: Find device capabilities
CXL devices contain an array of capabilities that describe the interactions software can interact with the device, or firmware running on the device. A CXL compliant device must implement the device status and the mailbox capability. A CXL compliant memory device must implement the memory device capability. Each of the capabilities can [will] provide an offset within the MMIO region for interacting with the CXL device. Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
- Loading branch information
1 parent
2b4b3b0
commit 03316f5eab47413b046c08f6b977867dfade36f9
Showing
2 changed files
with
143 additions
and
4 deletions.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| // Copyright(c) 2020 Intel Corporation. All rights reserved. | ||
|
|
||
| #ifndef __CXL_H__ | ||
| #define __CXL_H__ | ||
|
|
||
| /* Device */ | ||
| #define CXLDEV_CAP_ARRAY_REG 0x0 | ||
| #define CXLDEV_CAP_ARRAY_CAP_ID 0 | ||
| #define CXLDEV_CAP_ARRAY_ID(x) ((x) & 0xffff) | ||
| #define CXLDEV_CAP_ARRAY_COUNT(x) (((x) >> 32) & 0xffff) | ||
|
|
||
| #define CXL_CAPABILITIES_CAP_ID_DEVICE_STATUS 1 | ||
| #define CXL_CAPABILITIES_CAP_ID_PRIMARY_MAILBOX 2 | ||
| #define CXL_CAPABILITIES_CAP_ID_SECONDARY_MAILBOX 3 | ||
| #define CXL_CAPABILITIES_CAP_ID_MEMDEV 0x4000 | ||
|
|
||
| /* Mailbox */ | ||
| #define CXLDEV_MB_CAPS 0x00 | ||
| #define CXLDEV_MB_CAP_PAYLOAD_SIZE(cap) ((cap) & 0x1F) | ||
| #define CXLDEV_MB_CTRL 0x04 | ||
| #define CXLDEV_MB_CMD 0x08 | ||
| #define CXLDEV_MB_STATUS 0x10 | ||
| #define CXLDEV_MB_BG_CMD_STATUS 0x18 | ||
|
|
||
| struct cxl_mem { | ||
| struct pci_dev *pdev; | ||
| void __iomem *regs; | ||
|
|
||
| /* Cap 0000h */ | ||
| struct { | ||
| void __iomem *regs; | ||
| } status; | ||
|
|
||
| /* Cap 0002h */ | ||
| struct { | ||
| void __iomem *regs; | ||
| size_t payload_size; | ||
| } mbox; | ||
|
|
||
| /* Cap 0040h */ | ||
| struct { | ||
| void __iomem *regs; | ||
| } mem; | ||
| }; | ||
|
|
||
| #define cxl_reg(type) \ | ||
| static inline void cxl_write_##type##_reg32(struct cxl_mem *cxlm, \ | ||
| u32 reg, u32 value) \ | ||
| { \ | ||
| void __iomem *reg_addr = READ_ONCE(cxlm->type.regs); \ | ||
| writel(value, reg_addr + reg); \ | ||
| } \ | ||
| static inline void cxl_write_##type##_reg64(struct cxl_mem *cxlm, \ | ||
| u32 reg, u64 value) \ | ||
| { \ | ||
| void __iomem *reg_addr = READ_ONCE(cxlm->type.regs); \ | ||
| writeq(value, reg_addr + reg); \ | ||
| } \ | ||
| static inline u32 cxl_read_##type##_reg32(struct cxl_mem *cxlm, \ | ||
| u32 reg) \ | ||
| { \ | ||
| void __iomem *reg_addr = READ_ONCE(cxlm->type.regs); \ | ||
| return readl(reg_addr + reg); \ | ||
| } \ | ||
| static inline u64 cxl_read_##type##_reg64(struct cxl_mem *cxlm, \ | ||
| u32 reg) \ | ||
| { \ | ||
| void __iomem *reg_addr = READ_ONCE(cxlm->type.regs); \ | ||
| return readq(reg_addr + reg); \ | ||
| } | ||
|
|
||
| cxl_reg(status) | ||
| cxl_reg(mbox) | ||
|
|
||
| static inline u32 __cxl_raw_read_reg32(struct cxl_mem *cxlm, u32 reg) | ||
| { | ||
| void __iomem *reg_addr = READ_ONCE(cxlm->regs); | ||
|
|
||
| return readl(reg_addr + reg); | ||
| } | ||
|
|
||
| static inline u64 __cxl_raw_read_reg64(struct cxl_mem *cxlm, u32 reg) | ||
| { | ||
| void __iomem *reg_addr = READ_ONCE(cxlm->regs); | ||
|
|
||
| return readq(reg_addr + reg); | ||
| } | ||
| #endif /* __CXL_H__ */ |
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