From: Aravind Iddamsetty <[email protected]>

Add a retired-pages node type to drm-ras so drivers can report the
memory pages they have taken out of service, with two operations:

 - get-retired-pages: dump one entry per page with its address, size
   and status (retired, pending or failed). The dump is flagged with
   NLM_F_DUMP_INTR if the list changes while it is read.
 - get-retired-pages-info: return the maximum number of pages that can
   be retired.

v3 (Rodrigo+LLM):
 - Split the drm-ras core from the xe user.
 - Flatten the page attributes and name the node type retired-pages
   instead of retired-resources, avoiding the over-wrapping
   anti-pattern pointed out by Jakub: the type-specific nest and the
   resource-type enum are gone.
 - Use uint for address, size and max-pages, no pad (Jakub).
 - Start the status enum at 1.
 - Move max-pages to its own do operation instead of a leading dump
   entry.
 - Set NLM_F_DUMP_INTR from a driver generation counter.
 - Report unknown node IDs with NL_SET_BAD_ATTR.
 - Removed deprecated Assisted-by tag.

v4 (Rodrigo+LLM):
 - Check the dump consistency once a page message is filled (Sashiko),
   and on the final NLMSG_DONE (local Sashiko), so NLM_F_DUMP_INTR is
   not lost.
 - Make the error-counter operations reject other node types (Sashiko).
 - Hold a node reference in the new handlers (local Sashiko).
 - Rebase on the telemetry node type, moving the type check of its
   handlers into drm_ras_node_get().

v5 (Rodrigo+LLM):
 - Split the node and callback checks in the clear-error-counter doit,
   and write the new handlers like the error-counter ones, with
   put_node labels and an inline dump loop, for consistency (Riana).
 - Drop node-id from the dump entries (Riana).

Cc: Jakub Kicinski <[email protected]>
Cc: Riana Tauro <[email protected]>
Cc: Raag Jadav <[email protected]>
Cc: Zack McKevitt <[email protected]>
Cc: Jeff Hugo <[email protected]>
Signed-off-by: Aravind Iddamsetty <[email protected]>
Signed-off-by: Rodrigo Vivi <[email protected]>
---
 Documentation/netlink/specs/drm_ras.yaml |  73 +++++++-
 drivers/gpu/drm/drm_ras.c                | 228 +++++++++++++++++++++--
 drivers/gpu/drm/drm_ras_nl.c             |  24 +++
 drivers/gpu/drm/drm_ras_nl.h             |   4 +
 include/drm/drm_ras.h                    |  49 +++++
 include/uapi/drm/drm_ras.h               |  31 ++-
 6 files changed, 385 insertions(+), 24 deletions(-)

diff --git a/Documentation/netlink/specs/drm_ras.yaml 
b/Documentation/netlink/specs/drm_ras.yaml
index 0f1ceb705d3d..c217e52197e6 100644
--- a/Documentation/netlink/specs/drm_ras.yaml
+++ b/Documentation/netlink/specs/drm_ras.yaml
@@ -16,16 +16,28 @@ definitions:
     type: enum
     name: node-type
     value-start: 1
-    entries: [error-counter, telemetry]
+    entries: [error-counter, telemetry, retired-pages]
     doc: >-
          Type of the node. The error-counter nodes expose reliability counters
-         for a hardware/software component, and telemetry nodes expose an
-         interface for reading and writing telemetry values to a device.
+         for a hardware/software component, telemetry nodes expose an
+         interface for reading and writing telemetry values to a device, and
+         retired-pages nodes list the memory pages that have been taken out
+         of service.
   -
     type: flags
     name: telemetry-field-mode
     entries: [read, write]
     doc: Bitmask of access modes supported by a telemetry field.
+  -
+    type: enum
+    name: retired-page-status
+    value-start: 1
+    entries: [retired, pending, failed]
+    doc: >-
+         Status of a retired page. retired means the page is reserved and out
+         of service; pending means the retirement is queued but the
+         reservation is not complete yet; failed means the reservation failed
+         and the page may still be in use.
 
 attribute-sets:
   -
@@ -140,6 +152,30 @@ attribute-sets:
         doc: >-
              Bitmask of access modes (read/write) supported by the
              telemetry field.
+  -
+    name: retired-page-attrs
+    attributes:
+      -
+        name: node-id
+        type: u32
+        doc: Node ID targeted by this retired pages operation.
+      -
+        name: address
+        type: uint
+        doc: Device address of the retired page.
+      -
+        name: size
+        type: uint
+        doc: Size of the retired page in bytes.
+      -
+        name: status
+        type: u32
+        doc: Retirement status of the page.
+        enum: retired-page-status
+      -
+        name: max-pages
+        type: uint
+        doc: Maximum number of pages that can be retired on this node.
 
 operations:
   list:
@@ -287,6 +323,37 @@ operations:
             - field
             - field-name
             - mode
+    -
+      name: get-retired-pages
+      doc: >-
+           Retrieve the pages retired on a retired-pages node, one entry per
+           page. The dump is flagged as interrupted if the list changes while
+           it is being read.
+      attribute-set: retired-page-attrs
+      flags: [admin-perm]
+      dump:
+        request:
+          attributes:
+            - node-id
+        reply:
+          attributes:
+            - address
+            - size
+            - status
+    -
+      name: get-retired-pages-info
+      doc: >-
+           Retrieve the retired page limits of a retired-pages node.
+      attribute-set: retired-page-attrs
+      flags: [admin-perm]
+      do:
+        request:
+          attributes:
+            - node-id
+        reply:
+          attributes:
+            - node-id
+            - max-pages
 
 mcast-groups:
   list:
diff --git a/drivers/gpu/drm/drm_ras.c b/drivers/gpu/drm/drm_ras.c
index 82fcc766b84b..26505a7e4f0f 100644
--- a/drivers/gpu/drm/drm_ras.c
+++ b/drivers/gpu/drm/drm_ras.c
@@ -69,6 +69,14 @@
  *     Each field contains the uAPI defined enum string, its numerical value,
  *     and its mode bitmask, which encodes read/write capabilities.
  *
+ * 11. GET_RETIRED_PAGES: Dump the retired pages of a given node.
+ *     Userspace must provide Node ID.
+ *     Returns one entry per page with its address, size and status.
+ *
+ * 12. GET_RETIRED_PAGES_INFO: Get the retired page limits of a given node.
+ *     Userspace must provide Node ID.
+ *     Returns the maximum number of pages that can be retired.
+ *
  * Node registration:
  *
  * - drm_ras_node_register(): Registers a new node and assigns
@@ -121,6 +129,13 @@
  *     + The driver can optionally provide a pre_doit callback, 
telemetry_pre(),
  *       to enforce permissions checks on telemetry operations.
  *
+ * - RETIRED_PAGES:
+ *     + The driver must implement the query_retired_page() callback, returning
+ *       the retired page with the lowest address at or above a cursor, and
+ *       -ENOENT when there is none.
+ *     + The driver can implement query_retired_pages_info() to report the
+ *       maximum number of pages that can be retired.
+ *
  * Netlink handlers:
  *
  * - drm_ras_nl_list_nodes_dumpit(): Implements the LIST_NODES
@@ -147,6 +162,10 @@
  * - drm_ras_nl_telemetry_list_fields_dumpit(): Implements the 
TELEMETRY_LIST_FIELDS
  *   dumpit operation, enumerating all telemetry fields and their supported
  *   access modes for a telemetry node.
+ * - drm_ras_nl_get_retired_pages_dumpit(): Implements the GET_RETIRED_PAGES 
dumpit
+ *   operation, listing the retired pages of a specific node.
+ * - drm_ras_nl_get_retired_pages_info_doit(): Implements the 
GET_RETIRED_PAGES_INFO
+ *   doit operation, fetching the retired page limits of a specific node.
  */
 
 static DEFINE_XARRAY_ALLOC(drm_ras_xa);
@@ -162,6 +181,8 @@ struct drm_ras_ctx {
        unsigned long restart;
        /* Node targeted by a telemetry get/set doit */
        struct drm_ras_node *node;
+       /* Which retired page address to restart the dump from */
+       u64 cursor;
 };
 
 static_assert(sizeof(struct drm_ras_ctx) <= NETLINK_CTX_SIZE);
@@ -169,6 +190,7 @@ static_assert(sizeof(struct drm_ras_ctx) <= 
NETLINK_CTX_SIZE);
 /**
  * drm_ras_node_get() - Look up a RAS node by ID and take a reference
  * @node_id: ID of the node to look up
+ * @type: Expected type of the node
  *
  * Looks the node up in the global xarray and, if found, takes a reference to
  * it so that it cannot be freed while the caller is using it. The lookup and
@@ -179,16 +201,19 @@ static_assert(sizeof(struct drm_ras_ctx) <= 
NETLINK_CTX_SIZE);
  *
  * The caller must drop the returned reference with drm_ras_node_put().
  *
- * Return: the referenced node, or NULL if no node with @node_id is registered.
+ * Return: the referenced node, or NULL if no node of @type with @node_id is
+ * registered.
  */
-static struct drm_ras_node *drm_ras_node_get(u32 node_id)
+static struct drm_ras_node *drm_ras_node_get(u32 node_id, enum 
drm_ras_node_type type)
 {
        struct drm_ras_node *node;
 
        xa_lock(&drm_ras_xa);
        node = xa_load(&drm_ras_xa, node_id);
-       if (node)
+       if (node && node->type == type)
                refcount_inc(&node->ref);
+       else
+               node = NULL;
        xa_unlock(&drm_ras_xa);
 
        return node;
@@ -412,7 +437,7 @@ static int doit_reply_value(struct genl_info *info, u32 
node_id,
        u32 value;
        int ret;
 
-       node = drm_ras_node_get(node_id);
+       node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER);
        if (!node)
                return -ENOENT;
 
@@ -461,7 +486,7 @@ static int doit_reply_threshold(struct genl_info *info, u32 
node_id, u32 error_i
        u32 threshold;
        int ret;
 
-       node = drm_ras_node_get(node_id);
+       node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER);
        if (!node)
                return -ENOENT;
 
@@ -603,7 +628,7 @@ int drm_ras_nl_get_error_counter_dumpit(struct sk_buff *skb,
 
        node_id = 
nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID]);
 
-       node = drm_ras_node_get(node_id);
+       node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER);
        if (!node)
                return -ENOENT;
 
@@ -699,20 +724,24 @@ int drm_ras_nl_clear_error_counter_doit(struct sk_buff 
*skb,
        node_id = 
nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID]);
        error_id = 
nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_ID]);
 
-       node = drm_ras_node_get(node_id);
-       if (!node || !node->clear_error_counter) {
-               drm_ras_node_put(node);
+       node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER);
+       if (!node)
                return -ENOENT;
+
+       if (!node->clear_error_counter) {
+               ret = -ENOENT;
+               goto put_node;
        }
 
        if (error_id < node->error_counter_range.first ||
            error_id > node->error_counter_range.last) {
-               drm_ras_node_put(node);
-               return -EINVAL;
+               ret = -EINVAL;
+               goto put_node;
        }
 
        ret = node->clear_error_counter(node, error_id);
 
+put_node:
        drm_ras_node_put(node);
 
        return ret;
@@ -770,7 +799,7 @@ int drm_ras_nl_set_error_threshold_doit(struct sk_buff 
*skb, struct genl_info *i
        error_id = 
nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_ID]);
        threshold = 
nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_THRESHOLD]);
 
-       node = drm_ras_node_get(node_id);
+       node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_ERROR_COUNTER);
        if (!node)
                return -ENOENT;
 
@@ -781,6 +810,166 @@ int drm_ras_nl_set_error_threshold_doit(struct sk_buff 
*skb, struct genl_info *i
        return ret;
 }
 
+static struct drm_ras_node *get_retired_pages_node(const struct genl_info 
*info)
+{
+       struct nlattr *attr = info->attrs[DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID];
+       struct drm_ras_node *node;
+
+       node = drm_ras_node_get(nla_get_u32(attr), 
DRM_RAS_NODE_TYPE_RETIRED_PAGES);
+       if (!node)
+               NL_SET_BAD_ATTR(info->extack, attr);
+
+       return node;
+}
+
+static int msg_put_retired_page(struct sk_buff *msg,
+                               const struct drm_ras_retired_page *page)
+{
+       int ret;
+
+       ret = nla_put_uint(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_ADDRESS, 
page->address);
+       if (ret)
+               return ret;
+
+       ret = nla_put_uint(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_SIZE, page->size);
+       if (ret)
+               return ret;
+
+       return nla_put_u32(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_STATUS, 
page->status);
+}
+
+/**
+ * drm_ras_nl_get_retired_pages_dumpit() - Dump the retired pages of a node
+ * @skb: Netlink message buffer
+ * @cb: Callback context for multi-part dumps
+ *
+ * Appends one message per retired page, in increasing address order. The
+ * dump resumes from the next address after a buffer overflow, and is flagged
+ * with %NLM_F_DUMP_INTR if the list changed between messages.
+ *
+ * Return: 0 if all pages fit in @skb, -EMSGSIZE if the buffer filled up
+ *         (requires multi-part continuation), or a negative error code on
+ *         failure.
+ */
+int drm_ras_nl_get_retired_pages_dumpit(struct sk_buff *skb,
+                                       struct netlink_callback *cb)
+{
+       const struct genl_info *info = genl_info_dump(cb);
+       struct drm_ras_ctx *ctx = (void *)cb->ctx;
+       struct drm_ras_retired_page page;
+       struct drm_ras_node *node;
+       void *hdr;
+       int ret;
+
+       if (!info->attrs || GENL_REQ_ATTR_CHECK(info, 
DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID))
+               return -EINVAL;
+
+       node = get_retired_pages_node(info);
+       if (!node)
+               return -ENOENT;
+
+       for (;;) {
+               ret = node->query_retired_page(node, ctx->cursor, &page);
+               if (ret && ret != -ENOENT)
+                       break;
+
+               /* Never zero, so the first message is checked as well */
+               cb->seq = page.generation + 1;
+               if (ret == -ENOENT) {
+                       ret = 0;
+                       break;
+               }
+
+               hdr = genlmsg_iput(skb, info);
+               if (!hdr) {
+                       ret = -EMSGSIZE;
+                       break;
+               }
+
+               ret = msg_put_retired_page(skb, &page);
+               if (ret) {
+                       genlmsg_cancel(skb, hdr);
+                       break;
+               }
+
+               genl_dump_check_consistent(cb, hdr);
+
+               genlmsg_end(skb, hdr);
+               ctx->cursor = page.address + 1;
+       }
+
+       drm_ras_node_put(node);
+
+       return ret;
+}
+
+/**
+ * drm_ras_nl_get_retired_pages_info_doit() - Query the retired page limits of 
a node
+ * @skb: Netlink message buffer
+ * @info: Generic Netlink info containing attributes of the request
+ *
+ * Return: 0 on success, or negative errno on failure.
+ */
+int drm_ras_nl_get_retired_pages_info_doit(struct sk_buff *skb,
+                                          struct genl_info *info)
+{
+       struct drm_ras_node *node;
+       struct sk_buff *msg;
+       u64 max_pages;
+       void *hdr;
+       int ret;
+
+       if (!info->attrs || GENL_REQ_ATTR_CHECK(info, 
DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID))
+               return -EINVAL;
+
+       node = get_retired_pages_node(info);
+       if (!node)
+               return -ENOENT;
+
+       if (!node->query_retired_pages_info) {
+               ret = -EOPNOTSUPP;
+               goto put_node;
+       }
+
+       ret = node->query_retired_pages_info(node, &max_pages);
+       if (ret)
+               goto put_node;
+
+       msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+       if (!msg) {
+               ret = -ENOMEM;
+               goto put_node;
+       }
+
+       hdr = genlmsg_iput(msg, info);
+       if (!hdr) {
+               ret = -EMSGSIZE;
+               goto free_msg;
+       }
+
+       ret = nla_put_u32(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID, node->id);
+       if (ret)
+               goto cancel_msg;
+
+       ret = nla_put_uint(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX_PAGES, 
max_pages);
+       if (ret)
+               goto cancel_msg;
+
+       genlmsg_end(msg, hdr);
+
+       drm_ras_node_put(node);
+
+       return genlmsg_reply(msg, info);
+
+cancel_msg:
+       genlmsg_cancel(msg, hdr);
+free_msg:
+       nlmsg_free(msg);
+put_node:
+       drm_ras_node_put(node);
+       return ret;
+}
+
 /**
  * drm_ras_nl_pre_telemetry - Look up the telemetry node and enforce 
permissions
  * @ops: Generic netlink operations
@@ -808,10 +997,9 @@ int drm_ras_nl_pre_telemetry(const struct genl_split_ops 
*ops, struct sk_buff *s
                return -EINVAL;
 
        node_id = nla_get_u32(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
-       node = drm_ras_node_get(node_id);
-       if (!node || node->type != DRM_RAS_NODE_TYPE_TELEMETRY) {
+       node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_TELEMETRY);
+       if (!node) {
                NL_SET_BAD_ATTR(info->extack, 
info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
-               drm_ras_node_put(node);
                return -ENOENT;
        }
 
@@ -892,10 +1080,9 @@ int drm_ras_nl_telemetry_list_fields_dumpit(struct 
sk_buff *skb, struct netlink_
 
        node_id = nla_get_u32(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
 
-       node = drm_ras_node_get(node_id);
-       if (!node || node->type != DRM_RAS_NODE_TYPE_TELEMETRY) {
+       node = drm_ras_node_get(node_id, DRM_RAS_NODE_TYPE_TELEMETRY);
+       if (!node) {
                NL_SET_BAD_ATTR(info->extack, 
info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
-               drm_ras_node_put(node);
                return -ENOENT;
        }
 
@@ -1100,7 +1287,6 @@ int drm_ras_node_register(struct drm_ras_node *node)
        if (!node->device_name || !node->node_name)
                return -EINVAL;
 
-       /* Currently, only Error Counter and Telemetry endpoints are supported 
*/
        switch (node->type) {
        case DRM_RAS_NODE_TYPE_ERROR_COUNTER:
                /* Mandatory entries for Error Counter Node */
@@ -1112,6 +1298,10 @@ int drm_ras_node_register(struct drm_ras_node *node)
                if (!node->telemetry_get || !node->telemetry_fields)
                        return -EINVAL;
                break;
+       case DRM_RAS_NODE_TYPE_RETIRED_PAGES:
+               if (!node->query_retired_page)
+                       return -EINVAL;
+               break;
        default:
                return -EINVAL;
        }
diff --git a/drivers/gpu/drm/drm_ras_nl.c b/drivers/gpu/drm/drm_ras_nl.c
index 589c6445eff7..c56220205876 100644
--- a/drivers/gpu/drm/drm_ras_nl.c
+++ b/drivers/gpu/drm/drm_ras_nl.c
@@ -59,6 +59,16 @@ static const struct nla_policy 
drm_ras_telemetry_list_fields_nl_policy[DRM_RAS_A
        [DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID] = { .type = NLA_U32, },
 };
 
+/* DRM_RAS_CMD_GET_RETIRED_PAGES - dump */
+static const struct nla_policy 
drm_ras_get_retired_pages_nl_policy[DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID + 1] = 
{
+       [DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID] = { .type = NLA_U32, },
+};
+
+/* DRM_RAS_CMD_GET_RETIRED_PAGES_INFO - do */
+static const struct nla_policy 
drm_ras_get_retired_pages_info_nl_policy[DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID + 
1] = {
+       [DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID] = { .type = NLA_U32, },
+};
+
 /* Ops table for drm_ras */
 static const struct genl_split_ops drm_ras_nl_ops[] = {
        {
@@ -126,6 +136,20 @@ static const struct genl_split_ops drm_ras_nl_ops[] = {
                .maxattr        = DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID,
                .flags          = GENL_CMD_CAP_DUMP,
        },
+       {
+               .cmd            = DRM_RAS_CMD_GET_RETIRED_PAGES,
+               .dumpit         = drm_ras_nl_get_retired_pages_dumpit,
+               .policy         = drm_ras_get_retired_pages_nl_policy,
+               .maxattr        = DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID,
+               .flags          = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP,
+       },
+       {
+               .cmd            = DRM_RAS_CMD_GET_RETIRED_PAGES_INFO,
+               .doit           = drm_ras_nl_get_retired_pages_info_doit,
+               .policy         = drm_ras_get_retired_pages_info_nl_policy,
+               .maxattr        = DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID,
+               .flags          = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
+       },
 };
 
 static const struct genl_multicast_group drm_ras_nl_mcgrps[] = {
diff --git a/drivers/gpu/drm/drm_ras_nl.h b/drivers/gpu/drm/drm_ras_nl.h
index 7a1cba70fd50..880b0c2befe3 100644
--- a/drivers/gpu/drm/drm_ras_nl.h
+++ b/drivers/gpu/drm/drm_ras_nl.h
@@ -34,6 +34,10 @@ int drm_ras_nl_telemetry_get_doit(struct sk_buff *skb, 
struct genl_info *info);
 int drm_ras_nl_telemetry_set_doit(struct sk_buff *skb, struct genl_info *info);
 int drm_ras_nl_telemetry_list_fields_dumpit(struct sk_buff *skb,
                                            struct netlink_callback *cb);
+int drm_ras_nl_get_retired_pages_dumpit(struct sk_buff *skb,
+                                       struct netlink_callback *cb);
+int drm_ras_nl_get_retired_pages_info_doit(struct sk_buff *skb,
+                                          struct genl_info *info);
 
 enum {
        DRM_RAS_NLGRP_ERROR_REPORT,
diff --git a/include/drm/drm_ras.h b/include/drm/drm_ras.h
index 76bdcc6f96a5..5c3900a53278 100644
--- a/include/drm/drm_ras.h
+++ b/include/drm/drm_ras.h
@@ -28,6 +28,23 @@ struct drm_ras_telemetry_field {
        u32 mode;
 };
 
+/**
+ * struct drm_ras_retired_page - A retired page reported by a driver
+ */
+struct drm_ras_retired_page {
+       /** @address: Device address of the page. */
+       u64 address;
+       /** @size: Size of the page in bytes. */
+       u64 size;
+       /** @status: Retirement status (enum drm_ras_retired_page_status). */
+       enum drm_ras_retired_page_status status;
+       /**
+        * @generation: Generation of the retired page list, changed by the
+        * driver whenever a page is added, removed or changes status.
+        */
+       u32 generation;
+};
+
 /**
  * struct drm_ras_node - A DRM RAS Node
  */
@@ -184,6 +201,38 @@ struct drm_ras_node {
        int (*telemetry_set)(struct drm_ras_node *ep, u64 *field, s64 *value,
                             s64 *status);
 
+       /* Retired-Pages Related Callbacks */
+
+       /**
+        * @query_retired_page:
+        *
+        * This callback is used by drm-ras to list the retired pages of a node.
+        * It must fill @page with the retired page that has the lowest address
+        * greater than or equal to @cursor. @page->generation must be set even
+        * when no page is found.
+        *
+        * The @query_retired_page is a mandatory callback for
+        * retired_pages_node.
+        *
+        * Returns: 0 on success,
+        *          -ENOENT when no page is at or above @cursor, which ends the
+        *                  list.
+        *          Other negative values on errors that should terminate the
+        *          netlink query.
+        */
+       int (*query_retired_page)(struct drm_ras_node *node, u64 cursor,
+                                 struct drm_ras_retired_page *page);
+
+       /**
+        * @query_retired_pages_info:
+        *
+        * This callback is used by drm-ras to query the maximum number of pages
+        * that can be retired on a node.
+        *
+        * Returns: 0 on success, negative error code on failure.
+        */
+       int (*query_retired_pages_info)(struct drm_ras_node *node, u64 
*max_pages);
+
        /** @priv: Driver private data */
        void *priv;
 
diff --git a/include/uapi/drm/drm_ras.h b/include/uapi/drm/drm_ras.h
index 56e0588af5d5..e7f2da18cc4c 100644
--- a/include/uapi/drm/drm_ras.h
+++ b/include/uapi/drm/drm_ras.h
@@ -12,12 +12,14 @@
 
 /*
  * Type of the node. The error-counter nodes expose reliability counters for a
- * hardware/software component, and telemetry nodes expose an interface for
- * reading and writing telemetry values to a device.
+ * hardware/software component, telemetry nodes expose an interface for reading
+ * and writing telemetry values to a device, and retired-pages nodes list the
+ * memory pages that have been taken out of service.
  */
 enum drm_ras_node_type {
        DRM_RAS_NODE_TYPE_ERROR_COUNTER = 1,
        DRM_RAS_NODE_TYPE_TELEMETRY,
+       DRM_RAS_NODE_TYPE_RETIRED_PAGES,
 };
 
 /*
@@ -28,6 +30,18 @@ enum drm_ras_telemetry_field_mode {
        DRM_RAS_TELEMETRY_FIELD_MODE_WRITE = 2,
 };
 
+/*
+ * Status of a retired page. retired means the page is reserved and out of
+ * service; pending means the retirement is queued but the reservation is not
+ * complete yet; failed means the reservation failed and the page may still be
+ * in use.
+ */
+enum drm_ras_retired_page_status {
+       DRM_RAS_RETIRED_PAGE_STATUS_RETIRED = 1,
+       DRM_RAS_RETIRED_PAGE_STATUS_PENDING,
+       DRM_RAS_RETIRED_PAGE_STATUS_FAILED,
+};
+
 enum {
        DRM_RAS_A_NODE_ATTRS_NODE_ID = 1,
        DRM_RAS_A_NODE_ATTRS_DEVICE_NAME,
@@ -73,6 +87,17 @@ enum {
        DRM_RAS_A_TELEMETRY_ATTRS_MAX = (__DRM_RAS_A_TELEMETRY_ATTRS_MAX - 1)
 };
 
+enum {
+       DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID = 1,
+       DRM_RAS_A_RETIRED_PAGE_ATTRS_ADDRESS,
+       DRM_RAS_A_RETIRED_PAGE_ATTRS_SIZE,
+       DRM_RAS_A_RETIRED_PAGE_ATTRS_STATUS,
+       DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX_PAGES,
+
+       __DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX,
+       DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX = (__DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX 
- 1)
+};
+
 enum {
        DRM_RAS_CMD_LIST_NODES = 1,
        DRM_RAS_CMD_GET_ERROR_COUNTER,
@@ -83,6 +108,8 @@ enum {
        DRM_RAS_CMD_TELEMETRY_GET,
        DRM_RAS_CMD_TELEMETRY_SET,
        DRM_RAS_CMD_TELEMETRY_LIST_FIELDS,
+       DRM_RAS_CMD_GET_RETIRED_PAGES,
+       DRM_RAS_CMD_GET_RETIRED_PAGES_INFO,
 
        __DRM_RAS_CMD_MAX,
        DRM_RAS_CMD_MAX = (__DRM_RAS_CMD_MAX - 1)
-- 
2.56.0

Reply via email to