cxl/mem: Introduce 'struct cxl_regs' for "composable" CXL devices
[linux-2.6-microblaze.git] / drivers / cxl / cxl.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright(c) 2020 Intel Corporation. */
3
4 #ifndef __CXL_H__
5 #define __CXL_H__
6
7 #include <linux/bitfield.h>
8 #include <linux/bitops.h>
9 #include <linux/io.h>
10
11 /* CXL 2.0 8.2.8.1 Device Capabilities Array Register */
12 #define CXLDEV_CAP_ARRAY_OFFSET 0x0
13 #define   CXLDEV_CAP_ARRAY_CAP_ID 0
14 #define   CXLDEV_CAP_ARRAY_ID_MASK GENMASK_ULL(15, 0)
15 #define   CXLDEV_CAP_ARRAY_COUNT_MASK GENMASK_ULL(47, 32)
16 /* CXL 2.0 8.2.8.2 CXL Device Capability Header Register */
17 #define CXLDEV_CAP_HDR_CAP_ID_MASK GENMASK(15, 0)
18 /* CXL 2.0 8.2.8.2.1 CXL Device Capabilities */
19 #define CXLDEV_CAP_CAP_ID_DEVICE_STATUS 0x1
20 #define CXLDEV_CAP_CAP_ID_PRIMARY_MAILBOX 0x2
21 #define CXLDEV_CAP_CAP_ID_SECONDARY_MAILBOX 0x3
22 #define CXLDEV_CAP_CAP_ID_MEMDEV 0x4000
23
24 /* CXL 2.0 8.2.8.4 Mailbox Registers */
25 #define CXLDEV_MBOX_CAPS_OFFSET 0x00
26 #define   CXLDEV_MBOX_CAP_PAYLOAD_SIZE_MASK GENMASK(4, 0)
27 #define CXLDEV_MBOX_CTRL_OFFSET 0x04
28 #define   CXLDEV_MBOX_CTRL_DOORBELL BIT(0)
29 #define CXLDEV_MBOX_CMD_OFFSET 0x08
30 #define   CXLDEV_MBOX_CMD_COMMAND_OPCODE_MASK GENMASK_ULL(15, 0)
31 #define   CXLDEV_MBOX_CMD_PAYLOAD_LENGTH_MASK GENMASK_ULL(36, 16)
32 #define CXLDEV_MBOX_STATUS_OFFSET 0x10
33 #define   CXLDEV_MBOX_STATUS_RET_CODE_MASK GENMASK_ULL(47, 32)
34 #define CXLDEV_MBOX_BG_CMD_STATUS_OFFSET 0x18
35 #define CXLDEV_MBOX_PAYLOAD_OFFSET 0x20
36
37 /*
38  * CXL_DEVICE_REGS - Common set of CXL Device register block base pointers
39  * @status: CXL 2.0 8.2.8.3 Device Status Registers
40  * @mbox: CXL 2.0 8.2.8.4 Mailbox Registers
41  * @memdev: CXL 2.0 8.2.8.5 Memory Device Registers
42  */
43 #define CXL_DEVICE_REGS() \
44         void __iomem *status; \
45         void __iomem *mbox; \
46         void __iomem *memdev
47
48 /* See note for 'struct cxl_regs' for the rationale of this organization */
49 struct cxl_device_regs {
50         CXL_DEVICE_REGS();
51 };
52
53 /*
54  * Note, the anonymous union organization allows for per
55  * register-block-type helper routines, without requiring block-type
56  * agnostic code to include the prefix. I.e.
57  * cxl_setup_device_regs(&cxlm->regs.dev) vs readl(cxlm->regs.mbox).
58  * The specificity reads naturally from left-to-right.
59  */
60 struct cxl_regs {
61         union {
62                 struct {
63                         CXL_DEVICE_REGS();
64                 };
65                 struct cxl_device_regs device_regs;
66         };
67 };
68
69 extern struct bus_type cxl_bus_type;
70 #endif /* __CXL_H__ */