CXL的协议内容

在 CXL (Compute Express Link) 的 Linux 驱动开发中,寄存器的探测和映射是关键的一环。这些操作涉及到识别和配置 CXL 设备的不同功能区块。以下是对相关源码的分析:

1. 寄存器探测 ([cxl_probe_component_regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#207%2C6-207%2C6) 和 [cxl_probe_device_regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#209%2C6-209%2C6))

这两个函数位于 [drivers/cxl/core/regs.c](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/regs.c#1%2C1-1%2C1) 文件中,用于探测 CXL 组件和设备寄存器。

[cxl_probe_component_regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#207%2C6-207%2C6)
  • 功能: 探测 CXL 组件寄存器块。
  • 参数:
    • [dev](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#207%2C46-207%2C46): 设备结构体,表示宿主设备。
    • [base](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#154%2C48-154%2C48): 映射的基地址,包含 HDM 解码器能力头。
    • [map](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#208%2C40-208%2C40): 用于描述找到的寄存器块信息的映射对象。
  • 实现细节:
    • 从基地址偏移 [CXL_CM_OFFSET](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#25%2C9-25%2C9) (定义在 cxl.h) 开始读取。
    • 读取并解析能力数组头部,检查是否匹配预期的 ID ([CM_CAP_HDR_CAP_ID](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#28%2C13-28%2C13))。
    • 遍历能力数组,对于每个能力,根据其 ID 处理不同类型的寄存器块(如 HDM 解码器)。
[cxl_probe_device_regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#209%2C6-209%2C6)
  • 功能: 探测 CXL 设备寄存器块。
  • 参数:
    • [dev](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#207%2C46-207%2C46): 设备结构体。
    • [base](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#154%2C48-154%2C48): 映射的基地址,指向 CXL 2.0 8.2.8 设备寄存器接口。
    • [map](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#208%2C40-208%2C40): 映射对象。
  • 实现细节:
    • 从基地址偏移 [CXLDEV_CAP_ARRAY_OFFSET](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#123%2C9-123%2C9) 开始读取。
    • 解析设备能力数组,检查数组 ID。
    • 遍历设备能力,根据能力 ID 处理不同的设备寄存器(如状态、邮箱、内存设备能力)。

2. 寄存器映射 ([cxl_map_component_regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#211%2C5-211%2C5) 和 [cxl_map_device_regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#214%2C5-214%2C5))

这些函数用于将探测到的寄存器块映射到内存中,以便驱动程序可以访问和配置这些寄存器。

[cxl_map_component_regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#211%2C5-211%2C5)
  • 功能: 映射 CXL 组件寄存器。
  • 参数:
    • [pdev](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#211%2C44-211%2C44): PCI 设备结构体。
    • [regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#212%2C34-212%2C34): CXL 组件寄存器结构体。
    • [map](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#208%2C40-208%2C40): 包含映射信息的结构体。
  • 实现细节:
    • 计算物理地址和长度。
    • 使用 [devm_cxl_iomap_block](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#221%2C15-221%2C15) 映射地址区间。
[cxl_map_device_regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#214%2C5-214%2C5)
  • 功能: 映射 CXL 设备寄存器。
  • 参数:
    • [pdev](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#211%2C44-211%2C44): PCI 设备结构体。
    • [regs](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#212%2C34-212%2C34): CXL 设备寄存器结构体。
    • [map](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#208%2C40-208%2C40): 映射信息。
  • 实现细节:
    • 对于每个有效的设备寄存器块(状态、邮箱、内存设备),计算地址和长度,然后映射。

总结

这些函数提供了 CXL 寄存器探测和映射的基础设施,是驱动程序与硬件交互的基础。通过这些操作,驱动程序能够配置和管理 CXL 设备的不同功能,如内存设备、解码器等。

CXL Mailbox (mbox.c)

Overview

The CXL mailbox (mbox.c) handles communication between the host and the CXL device through a mailbox interface. This interface is used for sending commands and receiving responses related to firmware, security, and device management.

Key Functions
  1. Command Filtering and Security ([cxl_mem_raw_command_allowed](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/mbox.c#199%2C13-199%2C13)):

    • Filters commands based on security requirements and configuration settings.
    • Disables certain commands that should not be executed directly by userspace due to security concerns (e.g., firmware activation, setting partition information).
  2. Payload Validation ([cxl_payload_from_user_allowed](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/mbox.c#223%2C4-223%2C4)):

    • Ensures that payloads from userspace do not contain invalid or unsupported values before sending them to the device.
    • Specific checks are implemented based on the command opcode to prevent unsafe operations.
  3. Command Handling ([handle_mailbox_cmd_from_user](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/mbox.c#465%2C4-465%2C4)):

    • Executes mailbox commands on behalf of userspace.
    • Handles copying of output payloads back to userspace, ensuring that the size constraints are respected.

CXL Memory Device (memdev.c)

Overview

The memdev.c file manages CXL memory devices, providing interfaces for device operations, attribute exposure, and IOCTL handling.

Key Components
  1. Device Management:

    • Handles device creation, initialization, and release.
    • Manages device attributes such as firmware version, payload size, and memory sizes (RAM and PMEM).
  2. IOCTL Interface ([cxl_memdev_ioctl](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/memdev.c#282%2C13-282%2C13)):

    • Provides a mechanism for userspace to interact with the CXL device via IOCTL commands.
    • Supports querying device commands and sending specific commands to the device.
  3. Device Attributes:

    • Exposes various attributes through sysfs, allowing userspace to query device properties like memory sizes and firmware version.

CXL Persistent Memory (pmem.c)

Overview

The pmem.c file integrates CXL with the LIBNVDIMM subsystem, facilitating the management of persistent memory.

Key Functions
  1. NVDIMM Bridge Management ([devm_cxl_add_nvdimm_bridge](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#635%2C27-635%2C27)):

    • Creates and manages NVDIMM bridge devices that act as intermediaries between the CXL hardware and the LIBNVDIMM subsystem.
    • Each bridge can host multiple NVDIMM devices, translating LIBNVDIMM operations into CXL operations.
  2. Device Allocation and Registration:

    • Allocates and initializes NVDIMM bridge and NVDIMM devices.
    • Registers these devices with the system, making them available for operations.
  3. Device Release:

    • Handles the cleanup and release of resources when NVDIMM devices are removed.

Summary

  • mbox.c focuses on secure and controlled communication between the host and CXL devices using a mailbox interface.
  • memdev.c manages CXL memory devices, providing user interfaces and system attribute exposure.
  • pmem.c integrates CXL devices with the LIBNVDIMM subsystem for persistent memory management, including the creation and management of bridge devices.

These components are crucial for the operation and management of CXL devices, ensuring secure interactions, system integration, and compliance with the CXL and LIBNVDIMM specifications.

CXL 邮箱(mbox.c

概述

CXL 邮箱(mbox.c)通过邮箱接口处理主机与 CXL 设备之间的通信。此接口用于发送与固件、安全性和设备管理相关的命令并接收响应。

关键功能
  1. 命令过滤与安全([cxl_mem_raw_command_allowed](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/mbox.c#199%2C13-199%2C13)):

    • 根据安全要求和配置设置过滤命令。
    • 禁用某些不应由用户空间直接执行的命令,因为这些命令涉及安全问题(例如,固件激活、设置分区信息)。
  2. 有效载荷验证([cxl_payload_from_user_allowed](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/mbox.c#223%2C4-223%2C4)):

    • 确保用户空间的有效载荷在发送到设备之前不包含无效或不支持的值。
    • 根据命令操作码实施特定检查,以防止不安全的操作。
  3. 命令处理([handle_mailbox_cmd_from_user](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/mbox.c#465%2C4-465%2C4)):

    • 代表用户空间执行邮箱命令。
    • 处理输出有效载荷返回给用户空间,确保遵守大小限制。

CXL 内存设备(memdev.c

概述

memdev.c 文件管理 CXL 内存设备,提供设备操作、属性展示和 IOCTL 处理的接口。

关键组件
  1. 设备管理:

    • 处理设备的创建、初始化和释放。
    • 管理设备属性,如固件版本、有效载荷大小和内存大小(RAM 和 PMEM)。
  2. IOCTL 接口([cxl_memdev_ioctl](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/core/memdev.c#282%2C13-282%2C13)):

    • 为用户空间提供与 CXL 设备交互的机制,通过 IOCTL 命令。
    • 支持查询设备命令并向设备发送特定命令。
  3. 设备属性:

    • 通过 sysfs 暴露各种属性,允许用户空间查询设备属性,如内存大小和固件版本。

CXL 持久内存(pmem.c

概述

pmem.c 文件将 CXL 与 LIBNVDIMM 子系统集成,便于管理持久内存。

关键功能
  1. NVDIMM 桥管理([devm_cxl_add_nvdimm_bridge](file:///d%3A/PythonProj/Xiaomi_Kernel_OpenSource-aurora-u-oss/Xiaomi_Kernel_OpenSource-aurora-u-oss/drivers/cxl/cxl.h#635%2C27-635%2C27)):

    • 创建和管理作为 CXL 硬件与 LIBNVDIMM 子系统之间中介的 NVDIMM 桥设备。
    • 每个桥可以托管多个 NVDIMM 设备,将 LIBNVDIMM 操作转换为 CXL 操作。
  2. 设备分配和注册:

    • 分配和初始化 NVDIMM 桥和 NVDIMM 设备。
    • 将这些设备注册到系统中,使其可用于操作。
  3. 设备释放:

    • 在 NVDIMM 设备被移除时处理资源清理和释放。

总结

  • mbox.c 专注于使用邮箱接口在主机和 CXL 设备之间进行安全和受控的通信。
  • memdev.c 管理 CXL 内存设备,提供用户界面和系统属性展示。
  • pmem.c 将 CXL 设备与 LIBNVDIMM 子系统集成,用于持久内存管理,包括创建和管理桥设备。

这些组件对于操作和管理 CXL 设备至关重要,确保了安全交互、系统集成以及符合 CXL 和 LIBNVDIMM 规范。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值