Skip to content
Permalink
Browse files
cxl/mem: Add CDAT table reading from DOE
This patch simply provides some debug print outs of the entries
at probe time + a sysfs binary attribute to allow dumping of the
whole table.

Binary dumping is modelled on /sys/firmware/ACPI/tables/

The ability to dump this table will be very useful for emulation of
real devices once they become available as QEMU CXL type 3 device
emulation will be able to load this file in.

Open questions:
* No support here for table updates. Worth including these from the
  start, or leave that complexity for later?
* Worth logging the reported info for debug, or is the binary attribute
  sufficient?  Larger open question of whether to expose this info to
  userspace or not left for another day!
* Where to put the CDAT file?  Is it worth a subdirectory?
* What is maximum size of the SSLBIS entry - I haven't quite managed
  to figure that out and this is the record with largest size.
  We could support dynamic allocation of the record size, but it
  would add complexity that seems unnecessary.
  It would not be compliant with the specification for a type 3 memory
  device to report this record anyway so I'm not that worried about this
  for now.  It will become relevant once we have support for reading
  CDAT from CXL switches.
* cdat.h is formatted in a similar style to pci_regs.h on basis that
  it may well be helpful to share this header with userspace tools.
* Move the generic parts of this out to driver/cxl/cdat.c or leave that
  until we have other CXL drivers wishing to use this?

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
jic23 authored and intel-lab-lkp committed Mar 10, 2021
1 parent b4e042f commit 57ebd10b28d20aa89ddd013bdf52956d20011d63
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 1 deletion.
@@ -0,0 +1,79 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Coherent Device Attribute table (CDAT)
*
* Specification available from UEFI.org
*
* Whilst CDAT is defined as a single table, the access via DOE maiboxes is
* done one entry at a time, where the first entry is the header.
*/

#define CXL_DOE_TABLE_ACCESS_REQ_CODE 0x000000ff
#define CXL_DOE_TABLE_ACCESS_REQ_CODE_READ 0
#define CXL_DOE_TABLE_ACCESS_TABLE_TYPE 0x0000ff00
#define CXL_DOE_TABLE_ACCESS_TABLE_TYPE_CDATA 0
#define CXL_DOE_TABLE_ACCESS_ENTRY_HANDLE 0xffff0000


/*
* CDAT entries are little endian and are read from PCI config space which
* is also little endian.
* As such, on a big endian system these will have been reversed.
* This prevents us from making easy use of packed structures.
* Style form pci_regs.h
*/

#define CDAT_HEADER_LENGTH_DW 3
#define CDAT_HEADER_DW0_LENGTH 0xFFFFFFFF
#define CDAT_HEADER_DW1_REVISION 0x000000FF
#define CDAT_HEADER_DW1_CHECKSUM 0x0000FF00
#define CDAT_HEADER_DW2_SEQUENCE 0xFFFFFFFF

/* All structures have a common first DW */
#define CDAT_STRUCTURE_DW0_TYPE 0x000000FF
#define CDAT_STRUCTURE_DW0_TYPE_DSMAS 0
#define CDAT_STRUCTURE_DW0_TYPE_DSLBIS 1
#define CDAT_STRUCTURE_DW0_TYPE_DSMSCIS 2
#define CDAT_STRUCTURE_DW0_TYPE_DSIS 3
#define CDAT_STRUCTURE_DW0_TYPE_DSEMTS 4
#define CDAT_STRUCTURE_DW0_TYPE_SSLBIS 5

#define CDAT_STRUCTURE_DW0_LENGTH 0xFFFF0000

/* Device Scoped Memory Affinity Structure */
#define CDAT_DSMAS_DW1_DSMAD_HANDLE 0x000000ff
#define CDAT_DSMAS_DW1_FLAGS 0x0000ff00
#define CDAT_DSMAS_DPA_OFFSET(entry) ((u64)((entry)[3]) << 32 | (entry)[2])
#define CDAT_DSMAS_DPA_LEN(entry) ((u64)((entry)[5]) << 32 | (entry)[4])

/* Device Scoped Latency and Bandwidth Information Structure */
#define CDAT_DSLBIS_DW1_HANDLE 0x000000ff
#define CDAT_DSLBIS_DW1_FLAGS 0x0000ff00
#define CDAT_DSLBIS_DW1_DATA_TYPE 0x00ff0000
#define CDAT_DSLBIS_BASE_UNIT(entry) ((u64)((entry)[3]) << 32 | (entry)[2])
#define CDAT_DSLBIS_DW4_ENTRY_0 0x0000ffff
#define CDAT_DSLBIS_DW4_ENTRY_1 0xffff0000
#define CDAT_DSLBIS_DW5_ENTRY_2 0x0000ffff

/* Device Scoped Memory Side Cache Information Structure */
#define CDAT_DSMSCIS_DW1_HANDLE 0x000000ff
#define CDAT_DSMSCIS_MEMORY_SIDE_CACHE_SIZE(entry) \
((u64)((entry)[3]) << 32 | (entry)[2])
#define CDAT_DSMSCIS_DW4_MEMORY_SIDE_CACHE_ATTRS 0xffffffff

/* Device Scoped Initiator Structure */
#define CDAT_DSIS_DW1_FLAGS 0x000000ff
#define CDAT_DSIS_DW1_HANDLE 0x0000ff00

/* Device Scoped EFI Memory Type Structure */
#define CDAT_DSEMTS_DW1_HANDLE 0x000000ff
#define CDAT_DSEMTS_DW1_EFI_MEMORY_TYPE_ATTR 0x0000ff00
#define CDAT_DSEMTS_DPA_OFFSET(entry) ((u64)((entry)[3]) << 32 | (entry)[2])
#define CDAT_DSEMTS_DPA_LENGTH(entry) ((u64)((entry)[5]) << 32 | (entry)[4])

/* Switch Scoped Latency and Bandwidth Information Structure */
#define CDAT_SSLBIS_DW1_DATA_TYPE 0x000000ff
#define CDAT_SSLBIS_BASE_UNIT(entry) ((u64)((entry)[3]) << 32 | (entry)[2])
#define CDAT_SSLBIS_ENTRY_PORT_X(entry, i) ((entry)[4 + (i) * 2] & 0x0000ffff)
#define CDAT_SSLBIS_ENTRY_PORT_Y(entry, i) (((entry)[4 + (i) * 2] & 0xffff0000) >> 16)
#define CDAT_SSLBIS_ENTRY_LAT_OR_BW(entry, i) ((entry)[4 + (i) * 2 + 1] & 0x0000ffff)
@@ -7,6 +7,7 @@
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/io.h>
#include <linux/pcie-doe.h>

/* CXL 2.0 8.2.8.1 Device Capabilities Array Register */
#define CXLDEV_CAP_ARRAY_OFFSET 0x0
@@ -57,10 +58,21 @@
(FIELD_GET(CXLMDEV_RESET_NEEDED_MASK, status) != \
CXLMDEV_RESET_NEEDED_NOT)

#define CXL_DOE_PROTOCOL_COMPLIANCE 0
#define CXL_DOE_PROTOCOL_TABLE_ACCESS 2

/* Common to request and response */
#define CXL_DOE_TABLE_ACCESS_3_CODE GENMASK(7, 0)
#define CXL_DOE_TABLE_ACCESS_3_CODE_READ 0
#define CXL_DOE_TABLE_ACCESS_3_TYPE GENMASK(15, 8)
#define CXL_DOE_TABLE_ACCESS_3_TYPE_CDAT 0
#define CXL_DOE_TABLE_ACCESS_3_ENTRY_HANDLE GENMASK(31, 16)

struct cxl_memdev;
/**
* struct cxl_mem - A CXL memory device
* @pdev: The PCI device associated with this CXL device.
* @doe: Data exchange object mailbox used to read tables.
* @regs: IO mappings to the device's MMIO
* @status_regs: CXL 2.0 8.2.8.3 Device Status Registers
* @mbox_regs: CXL 2.0 8.2.8.4 Mailbox Registers
@@ -75,6 +87,7 @@ struct cxl_memdev;
*/
struct cxl_mem {
struct pci_dev *pdev;
struct pcie_doe doe;
void __iomem *regs;
struct cxl_memdev *cxlmd;

0 comments on commit 57ebd10

Please sign in to comment.