Skip to content

Commit 0b9159d

Browse files
weiny2djbw
authored andcommitted
cxl/pci: Store memory capacity values
The Identify Memory Device command returns information about the volatile only and persistent only memory capacities. Store those values in the cxl_mem structure for later use. While at it, reuse those calculations to calculate the ram and pmem ranges. Signed-off-by: Ira Weiny <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 5b68705 commit 0b9159d

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

drivers/cxl/cxlmem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,9 @@ struct cxl_mem {
9595

9696
struct range pmem_range;
9797
struct range ram_range;
98+
u64 total_bytes;
99+
u64 volatile_only_bytes;
100+
u64 persistent_only_bytes;
101+
u64 partition_align_bytes;
98102
};
99103
#endif /* __CXL_MEM_H__ */

drivers/cxl/pci.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ enum opcode {
6464
CXL_MBOX_OP_MAX = 0x10000
6565
};
6666

67+
/*
68+
* CXL 2.0 - Memory capacity multiplier
69+
* See Section 8.2.9.5
70+
*
71+
* Volatile, Persistent, and Partition capacities are specified to be in
72+
* multiples of 256MB - define a multiplier to convert to/from bytes.
73+
*/
74+
#define CXL_CAPACITY_MULTIPLIER SZ_256M
75+
6776
/**
6877
* struct mbox_cmd - A command to be submitted to hardware.
6978
* @opcode: (input) The command set and command submitted to hardware.
@@ -1350,16 +1359,37 @@ static int cxl_mem_identify(struct cxl_mem *cxlm)
13501359
if (rc < 0)
13511360
return rc;
13521361

1362+
cxlm->total_bytes = le64_to_cpu(id.total_capacity);
1363+
cxlm->total_bytes *= CXL_CAPACITY_MULTIPLIER;
1364+
1365+
cxlm->volatile_only_bytes = le64_to_cpu(id.volatile_capacity);
1366+
cxlm->volatile_only_bytes *= CXL_CAPACITY_MULTIPLIER;
1367+
1368+
cxlm->persistent_only_bytes = le64_to_cpu(id.persistent_capacity);
1369+
cxlm->persistent_only_bytes *= CXL_CAPACITY_MULTIPLIER;
1370+
1371+
cxlm->partition_align_bytes = le64_to_cpu(id.partition_align);
1372+
cxlm->partition_align_bytes *= CXL_CAPACITY_MULTIPLIER;
1373+
1374+
dev_dbg(&cxlm->pdev->dev, "Identify Memory Device\n"
1375+
" total_bytes = %#llx\n"
1376+
" volatile_only_bytes = %#llx\n"
1377+
" persistent_only_bytes = %#llx\n"
1378+
" partition_align_bytes = %#llx\n",
1379+
cxlm->total_bytes,
1380+
cxlm->volatile_only_bytes,
1381+
cxlm->persistent_only_bytes,
1382+
cxlm->partition_align_bytes);
1383+
13531384
/*
13541385
* TODO: enumerate DPA map, as 'ram' and 'pmem' do not alias.
13551386
* For now, only the capacity is exported in sysfs
13561387
*/
13571388
cxlm->ram_range.start = 0;
1358-
cxlm->ram_range.end = le64_to_cpu(id.volatile_capacity) * SZ_256M - 1;
1389+
cxlm->ram_range.end = cxlm->volatile_only_bytes - 1;
13591390

13601391
cxlm->pmem_range.start = 0;
1361-
cxlm->pmem_range.end =
1362-
le64_to_cpu(id.persistent_capacity) * SZ_256M - 1;
1392+
cxlm->pmem_range.end = cxlm->persistent_only_bytes - 1;
13631393

13641394
cxlm->lsa_size = le32_to_cpu(id.lsa_size);
13651395
memcpy(cxlm->firmware_version, id.fw_revision, sizeof(id.fw_revision));

0 commit comments

Comments
 (0)