• Dan Williams's avatar
    cxl/port: Enable HDM Capability after validating DVSEC Ranges · 34e37b4c
    Dan Williams authored
    CXL memory expanders that support the CXL 2.0 memory device class code
    include an "HDM Decoder Capability" mechanism to supplant the "CXL DVSEC
    Range" mechanism originally defined in CXL 1.1. Both mechanisms depend
    on a "mem_enable" bit being set in configuration space before either
    mechanism activates. When the HDM Decoder Capability is enabled the CXL
    DVSEC Range settings are ignored.
    
    Previously, the cxl_mem driver was relying on platform-firmware to set
    "mem_enable". That is an invalid assumption as there is no requirement
    that platform-firmware sets the bit before the driver sees a device,
    especially in hot-plug scenarios. Additionally, ACPI-platforms that
    support CXL 2.0 devices also support the ACPI CEDT (CXL Early Discovery
    Table). That table outlines the platform permissible address ranges for
    CXL operation. So, there is a need for the driver to set "mem_enable",
    and there is information available to determine the validity of the CXL
    DVSEC Ranges.
    
    Arrange for the driver to optionally enable the HDM Decoder Capability
    if "mem_enable" was not set by platform firmware, or the CXL DVSEC Range
    configuration was invalid. Be careful to only disable memory decode if
    the kernel was the one to enable it. In other words, if CXL is backing
    all of kernel memory at boot the device needs to maintain "mem_enable"
    and "HDM Decoder enable" all the way up to handoff back to platform
    firmware (e.g. ACPI S5 state entry may require CXL memory to stay
    active).
    
    Fixes: 560f7855 ("cxl/pci: Retrieve CXL DVSEC memory info")
    Cc: Dan Carpenter <dan.carpenter@oracle.com>
    [dan: fix early terminiation of range-allowed loop]
    Cc: Ariel Sibley <ariel.sibley@microchip.com>
    [ariel: Memory_size must be non-zero]
    Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Reviewed-by: default avatarIra Weiny <ira.weiny@intel.com>
    Link: https://lore.kernel.org/r/165307136375.2499769.861793697156744166.stgit@dwillia2-xfhSigned-off-by: default avatarDan Williams <dan.j.williams@intel.com>
    34e37b4c
pci.c 10.8 KB