|
30 | 30 |
|
31 | 31 | static struct cxl_region *to_cxl_region(struct device *dev);
|
32 | 32 |
|
| 33 | +#define __ACCESS_ATTR_RO(_level, _name) { \ |
| 34 | + .attr = { .name = __stringify(_name), .mode = 0444 }, \ |
| 35 | + .show = _name##_access##_level##_show, \ |
| 36 | +} |
| 37 | + |
| 38 | +#define ACCESS_DEVICE_ATTR_RO(level, name) \ |
| 39 | + struct device_attribute dev_attr_access##level##_##name = __ACCESS_ATTR_RO(level, name) |
| 40 | + |
| 41 | +#define ACCESS_ATTR_RO(level, attrib) \ |
| 42 | +static ssize_t attrib##_access##level##_show(struct device *dev, \ |
| 43 | + struct device_attribute *attr, \ |
| 44 | + char *buf) \ |
| 45 | +{ \ |
| 46 | + struct cxl_region *cxlr = to_cxl_region(dev); \ |
| 47 | + \ |
| 48 | + if (cxlr->coord[level].attrib == 0) \ |
| 49 | + return -ENOENT; \ |
| 50 | + \ |
| 51 | + return sysfs_emit(buf, "%u\n", cxlr->coord[level].attrib); \ |
| 52 | +} \ |
| 53 | +static ACCESS_DEVICE_ATTR_RO(level, attrib) |
| 54 | + |
| 55 | +ACCESS_ATTR_RO(0, read_bandwidth); |
| 56 | +ACCESS_ATTR_RO(0, read_latency); |
| 57 | +ACCESS_ATTR_RO(0, write_bandwidth); |
| 58 | +ACCESS_ATTR_RO(0, write_latency); |
| 59 | + |
| 60 | +#define ACCESS_ATTR_DECLARE(level, attrib) \ |
| 61 | + (&dev_attr_access##level##_##attrib.attr) |
| 62 | + |
| 63 | +static struct attribute *access0_coordinate_attrs[] = { |
| 64 | + ACCESS_ATTR_DECLARE(0, read_bandwidth), |
| 65 | + ACCESS_ATTR_DECLARE(0, write_bandwidth), |
| 66 | + ACCESS_ATTR_DECLARE(0, read_latency), |
| 67 | + ACCESS_ATTR_DECLARE(0, write_latency), |
| 68 | + NULL |
| 69 | +}; |
| 70 | + |
| 71 | +ACCESS_ATTR_RO(1, read_bandwidth); |
| 72 | +ACCESS_ATTR_RO(1, read_latency); |
| 73 | +ACCESS_ATTR_RO(1, write_bandwidth); |
| 74 | +ACCESS_ATTR_RO(1, write_latency); |
| 75 | + |
| 76 | +static struct attribute *access1_coordinate_attrs[] = { |
| 77 | + ACCESS_ATTR_DECLARE(1, read_bandwidth), |
| 78 | + ACCESS_ATTR_DECLARE(1, write_bandwidth), |
| 79 | + ACCESS_ATTR_DECLARE(1, read_latency), |
| 80 | + ACCESS_ATTR_DECLARE(1, write_latency), |
| 81 | + NULL |
| 82 | +}; |
| 83 | + |
| 84 | +#define ACCESS_VISIBLE(level) \ |
| 85 | +static umode_t cxl_region_access##level##_coordinate_visible( \ |
| 86 | + struct kobject *kobj, struct attribute *a, int n) \ |
| 87 | +{ \ |
| 88 | + struct device *dev = kobj_to_dev(kobj); \ |
| 89 | + struct cxl_region *cxlr = to_cxl_region(dev); \ |
| 90 | + \ |
| 91 | + if (a == &dev_attr_access##level##_read_latency.attr && \ |
| 92 | + cxlr->coord[level].read_latency == 0) \ |
| 93 | + return 0; \ |
| 94 | + \ |
| 95 | + if (a == &dev_attr_access##level##_write_latency.attr && \ |
| 96 | + cxlr->coord[level].write_latency == 0) \ |
| 97 | + return 0; \ |
| 98 | + \ |
| 99 | + if (a == &dev_attr_access##level##_read_bandwidth.attr && \ |
| 100 | + cxlr->coord[level].read_bandwidth == 0) \ |
| 101 | + return 0; \ |
| 102 | + \ |
| 103 | + if (a == &dev_attr_access##level##_write_bandwidth.attr && \ |
| 104 | + cxlr->coord[level].write_bandwidth == 0) \ |
| 105 | + return 0; \ |
| 106 | + \ |
| 107 | + return a->mode; \ |
| 108 | +} |
| 109 | + |
| 110 | +ACCESS_VISIBLE(0); |
| 111 | +ACCESS_VISIBLE(1); |
| 112 | + |
| 113 | +static const struct attribute_group cxl_region_access0_coordinate_group = { |
| 114 | + .name = "access0", |
| 115 | + .attrs = access0_coordinate_attrs, |
| 116 | + .is_visible = cxl_region_access0_coordinate_visible, |
| 117 | +}; |
| 118 | + |
| 119 | +static const struct attribute_group cxl_region_access1_coordinate_group = { |
| 120 | + .name = "access1", |
| 121 | + .attrs = access1_coordinate_attrs, |
| 122 | + .is_visible = cxl_region_access1_coordinate_visible, |
| 123 | +}; |
| 124 | + |
33 | 125 | static ssize_t uuid_show(struct device *dev, struct device_attribute *attr,
|
34 | 126 | char *buf)
|
35 | 127 | {
|
@@ -2069,6 +2161,8 @@ static const struct attribute_group *region_groups[] = {
|
2069 | 2161 | &cxl_base_attribute_group,
|
2070 | 2162 | &cxl_region_group,
|
2071 | 2163 | &cxl_region_target_group,
|
| 2164 | + &cxl_region_access0_coordinate_group, |
| 2165 | + &cxl_region_access1_coordinate_group, |
2072 | 2166 | NULL,
|
2073 | 2167 | };
|
2074 | 2168 |
|
|
0 commit comments