Skip to content

Commit 0058698

Browse files
aluceropdavejiang
authored andcommitted
cxl: export internal structs for external Type2 drivers
In preparation for type2 support, move structs and functions a type2 driver will need to access to into a new shared header file. Differentiate between public and private data to be preserved by type2 drivers. Signed-off-by: Alejandro Lucero <alucerop@amd.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Tested-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Gregory Price <gourry@gourry.net> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Link: https://patch.msgid.link/20260306164741.3796372-3-alejandro.lucero-palau@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 9a775c0 commit 0058698

3 files changed

Lines changed: 227 additions & 210 deletions

File tree

drivers/cxl/cxl.h

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/node.h>
1313
#include <linux/io.h>
1414
#include <linux/range.h>
15+
#include <cxl/cxl.h>
1516

1617
extern const struct nvdimm_security_ops *cxl_security_ops;
1718

@@ -201,97 +202,6 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)
201202
#define CXLDEV_MBOX_BG_CMD_COMMAND_VENDOR_MASK GENMASK_ULL(63, 48)
202203
#define CXLDEV_MBOX_PAYLOAD_OFFSET 0x20
203204

204-
/*
205-
* Using struct_group() allows for per register-block-type helper routines,
206-
* without requiring block-type agnostic code to include the prefix.
207-
*/
208-
struct cxl_regs {
209-
/*
210-
* Common set of CXL Component register block base pointers
211-
* @hdm_decoder: CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure
212-
* @ras: CXL 2.0 8.2.5.9 CXL RAS Capability Structure
213-
*/
214-
struct_group_tagged(cxl_component_regs, component,
215-
void __iomem *hdm_decoder;
216-
void __iomem *ras;
217-
);
218-
/*
219-
* Common set of CXL Device register block base pointers
220-
* @status: CXL 2.0 8.2.8.3 Device Status Registers
221-
* @mbox: CXL 2.0 8.2.8.4 Mailbox Registers
222-
* @memdev: CXL 2.0 8.2.8.5 Memory Device Registers
223-
*/
224-
struct_group_tagged(cxl_device_regs, device_regs,
225-
void __iomem *status, *mbox, *memdev;
226-
);
227-
228-
struct_group_tagged(cxl_pmu_regs, pmu_regs,
229-
void __iomem *pmu;
230-
);
231-
232-
/*
233-
* RCH downstream port specific RAS register
234-
* @aer: CXL 3.0 8.2.1.1 RCH Downstream Port RCRB
235-
*/
236-
struct_group_tagged(cxl_rch_regs, rch_regs,
237-
void __iomem *dport_aer;
238-
);
239-
240-
/*
241-
* RCD upstream port specific PCIe cap register
242-
* @pcie_cap: CXL 3.0 8.2.1.2 RCD Upstream Port RCRB
243-
*/
244-
struct_group_tagged(cxl_rcd_regs, rcd_regs,
245-
void __iomem *rcd_pcie_cap;
246-
);
247-
};
248-
249-
struct cxl_reg_map {
250-
bool valid;
251-
int id;
252-
unsigned long offset;
253-
unsigned long size;
254-
};
255-
256-
struct cxl_component_reg_map {
257-
struct cxl_reg_map hdm_decoder;
258-
struct cxl_reg_map ras;
259-
};
260-
261-
struct cxl_device_reg_map {
262-
struct cxl_reg_map status;
263-
struct cxl_reg_map mbox;
264-
struct cxl_reg_map memdev;
265-
};
266-
267-
struct cxl_pmu_reg_map {
268-
struct cxl_reg_map pmu;
269-
};
270-
271-
/**
272-
* struct cxl_register_map - DVSEC harvested register block mapping parameters
273-
* @host: device for devm operations and logging
274-
* @base: virtual base of the register-block-BAR + @block_offset
275-
* @resource: physical resource base of the register block
276-
* @max_size: maximum mapping size to perform register search
277-
* @reg_type: see enum cxl_regloc_type
278-
* @component_map: cxl_reg_map for component registers
279-
* @device_map: cxl_reg_maps for device registers
280-
* @pmu_map: cxl_reg_maps for CXL Performance Monitoring Units
281-
*/
282-
struct cxl_register_map {
283-
struct device *host;
284-
void __iomem *base;
285-
resource_size_t resource;
286-
resource_size_t max_size;
287-
u8 reg_type;
288-
union {
289-
struct cxl_component_reg_map component_map;
290-
struct cxl_device_reg_map device_map;
291-
struct cxl_pmu_reg_map pmu_map;
292-
};
293-
};
294-
295205
void cxl_probe_component_regs(struct device *dev, void __iomem *base,
296206
struct cxl_component_reg_map *map);
297207
void cxl_probe_device_regs(struct device *dev, void __iomem *base,
@@ -497,11 +407,6 @@ struct cxl_region_params {
497407
resource_size_t cache_size;
498408
};
499409

500-
enum cxl_partition_mode {
501-
CXL_PARTMODE_RAM,
502-
CXL_PARTMODE_PMEM,
503-
};
504-
505410
/*
506411
* Indicate whether this region has been assembled by autodetection or
507412
* userspace assembly. Prevent endpoint decoders outside of automatic

drivers/cxl/cxlmem.h

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
113113
resource_size_t base, resource_size_t len,
114114
resource_size_t skipped);
115115

116-
#define CXL_NR_PARTITIONS_MAX 2
117-
118116
struct cxl_dpa_info {
119117
u64 size;
120118
struct cxl_dpa_part_info {
@@ -373,87 +371,6 @@ struct cxl_security_state {
373371
struct kernfs_node *sanitize_node;
374372
};
375373

376-
/*
377-
* enum cxl_devtype - delineate type-2 from a generic type-3 device
378-
* @CXL_DEVTYPE_DEVMEM - Vendor specific CXL Type-2 device implementing HDM-D or
379-
* HDM-DB, no requirement that this device implements a
380-
* mailbox, or other memory-device-standard manageability
381-
* flows.
382-
* @CXL_DEVTYPE_CLASSMEM - Common class definition of a CXL Type-3 device with
383-
* HDM-H and class-mandatory memory device registers
384-
*/
385-
enum cxl_devtype {
386-
CXL_DEVTYPE_DEVMEM,
387-
CXL_DEVTYPE_CLASSMEM,
388-
};
389-
390-
/**
391-
* struct cxl_dpa_perf - DPA performance property entry
392-
* @dpa_range: range for DPA address
393-
* @coord: QoS performance data (i.e. latency, bandwidth)
394-
* @cdat_coord: raw QoS performance data from CDAT
395-
* @qos_class: QoS Class cookies
396-
*/
397-
struct cxl_dpa_perf {
398-
struct range dpa_range;
399-
struct access_coordinate coord[ACCESS_COORDINATE_MAX];
400-
struct access_coordinate cdat_coord[ACCESS_COORDINATE_MAX];
401-
int qos_class;
402-
};
403-
404-
/**
405-
* struct cxl_dpa_partition - DPA partition descriptor
406-
* @res: shortcut to the partition in the DPA resource tree (cxlds->dpa_res)
407-
* @perf: performance attributes of the partition from CDAT
408-
* @mode: operation mode for the DPA capacity, e.g. ram, pmem, dynamic...
409-
*/
410-
struct cxl_dpa_partition {
411-
struct resource res;
412-
struct cxl_dpa_perf perf;
413-
enum cxl_partition_mode mode;
414-
};
415-
416-
/**
417-
* struct cxl_dev_state - The driver device state
418-
*
419-
* cxl_dev_state represents the CXL driver/device state. It provides an
420-
* interface to mailbox commands as well as some cached data about the device.
421-
* Currently only memory devices are represented.
422-
*
423-
* @dev: The device associated with this CXL state
424-
* @cxlmd: The device representing the CXL.mem capabilities of @dev
425-
* @reg_map: component and ras register mapping parameters
426-
* @regs: Class device "Device" registers
427-
* @cxl_dvsec: Offset to the PCIe device DVSEC
428-
* @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH)
429-
* @media_ready: Indicate whether the device media is usable
430-
* @dpa_res: Overall DPA resource tree for the device
431-
* @part: DPA partition array
432-
* @nr_partitions: Number of DPA partitions
433-
* @serial: PCIe Device Serial Number
434-
* @type: Generic Memory Class device or Vendor Specific Memory device
435-
* @cxl_mbox: CXL mailbox context
436-
* @cxlfs: CXL features context
437-
*/
438-
struct cxl_dev_state {
439-
struct device *dev;
440-
struct cxl_memdev *cxlmd;
441-
struct cxl_register_map reg_map;
442-
struct cxl_device_regs regs;
443-
int cxl_dvsec;
444-
bool rcd;
445-
bool media_ready;
446-
struct resource dpa_res;
447-
struct cxl_dpa_partition part[CXL_NR_PARTITIONS_MAX];
448-
unsigned int nr_partitions;
449-
u64 serial;
450-
enum cxl_devtype type;
451-
struct cxl_mailbox cxl_mbox;
452-
#ifdef CONFIG_CXL_FEATURES
453-
struct cxl_features_state *cxlfs;
454-
#endif
455-
};
456-
457374
static inline resource_size_t cxl_pmem_size(struct cxl_dev_state *cxlds)
458375
{
459376
/*
@@ -523,37 +440,6 @@ to_cxl_memdev_state(struct cxl_dev_state *cxlds)
523440
return container_of(cxlds, struct cxl_memdev_state, cxlds);
524441
}
525442

526-
struct cxl_dev_state *_devm_cxl_dev_state_create(struct device *dev,
527-
enum cxl_devtype type,
528-
u64 serial, u16 dvsec,
529-
size_t size, bool has_mbox);
530-
531-
/**
532-
* cxl_dev_state_create - safely create and cast a cxl dev state embedded in a
533-
* driver specific struct.
534-
*
535-
* @parent: device behind the request
536-
* @type: CXL device type
537-
* @serial: device identification
538-
* @dvsec: dvsec capability offset
539-
* @drv_struct: driver struct embedding a cxl_dev_state struct
540-
* @member: name of the struct cxl_dev_state member in drv_struct
541-
* @mbox: true if mailbox supported
542-
*
543-
* Returns a pointer to the drv_struct allocated and embedding a cxl_dev_state
544-
* struct initialized.
545-
*
546-
* Introduced for Type2 driver support.
547-
*/
548-
#define devm_cxl_dev_state_create(parent, type, serial, dvsec, drv_struct, member, mbox) \
549-
({ \
550-
static_assert(__same_type(struct cxl_dev_state, \
551-
((drv_struct *)NULL)->member)); \
552-
static_assert(offsetof(drv_struct, member) == 0); \
553-
(drv_struct *)_devm_cxl_dev_state_create(parent, type, serial, dvsec, \
554-
sizeof(drv_struct), mbox); \
555-
})
556-
557443
enum cxl_opcode {
558444
CXL_MBOX_OP_INVALID = 0x0000,
559445
CXL_MBOX_OP_RAW = CXL_MBOX_OP_INVALID,

0 commit comments

Comments
 (0)