From patchwork Mon Dec 16 08:48:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13909402 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 49E81E7717F for ; Mon, 16 Dec 2024 08:49:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=O03Ox/ikMHUfughnRQyibxJAmPcJD8XXaT2vqZCoP8o=; b=sAuHxhFaUOycds PjxC5zLuXDoao38/MRbqh65hzKsvzOxvgYOiUYgIPBrdTVAxPptBi3EqPijZ3pduy3loRFj2qL/z7 rKcIR5Jw9j3wf6NTHZqP+bOA/Ej0o6vO9243idn2Dzjk1C3rz2gGFjTUn3lNrPZxIyJOLTGzotRM9 ES1PGl4ZmX7lYFuxhCVjuu0TLq+c23jJcp1nqAfdr/spSibLy/oCnVWJH51PFkWV5Z8W5petH3GtR EOw0PwHfLDLlQem8AIrcs/IM8nhJfgqkEWO/1QjKwiROVpyT+AMf9sX7Uu/sqAvDdTplRy7+3ika3 qsUbAqeGV7yz//J+oSzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mm-00000009RQK-3ryz; Mon, 16 Dec 2024 08:49:04 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tN6mk-00000009ROr-1W5c for linux-riscv@lists.infradead.org; Mon, 16 Dec 2024 08:49:03 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2161eb94cceso25014575ad.2 for ; Mon, 16 Dec 2024 00:49:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1734338942; x=1734943742; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Vj0v6rXKvRsgy/Lo1T614knekVJOULW+di93SCW+j5g=; b=MsHZ/9o5nOvmpX419/uwcCMVOVtmYFwt2o2Ww2aSmdzl6dQBh2fZZDmNMSuYRgRQrW JEUlJShsS1MScHrokyYzQ7b02hF2U5W2K4rlzUZ3Pf4VKMhFPB0q4gyk5goZwyqUp07K gOlC9TzOtjgorBXq4QEQIztbUtm/28clq9t41ZXArnYbWpd9Y6EAa/l+9ScAdUAd1NE6 HOrKtOx3ShwVRX5hskIxkAwjI51jQ0WjF/Bg7ryebfGrr+XW9i3GNA+tpXw6T3hN54Fv xCozQqaL4ATUjRJ0ZzCl2v72r30/bjMBDBvOOQhqcrKz3LTJOFwiMrAMKC4jkdPSIx0L p4jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734338942; x=1734943742; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vj0v6rXKvRsgy/Lo1T614knekVJOULW+di93SCW+j5g=; b=MYo0bci2nvQRb7SlWoDz63X/9BfmgY0w2MSzJg6Z2o5yyyBezH8X+uHKLwmj1eAkIX APdThsYqv8wYl4jBiltZHhN466REowi7i2zBj+YQsK7OhkOfvC979jCQjDW4TVu+qXYX QyK6xtbNZlIMo+TOt9DOVDrmvwwHsrPpdi0DHGafx1K7FPs11W83DlHe3mP43Zc0XL2G yy16y+Zv1AYMVyzi8kyvwg1GUNLJMw1LlUn/KbnR6rxt9etNaazca/inWXfHFeNPVQNI aP6vxHdYcHz2P6zLbzHhwWYuzirVCIKjHkAiibjHZc3HMB/ue60t3+MCa09/mXhXGQAv s0Tw== X-Forwarded-Encrypted: i=1; AJvYcCVdp9GsJquhg8vFQ1LcoEpwjQdHzVn5logGu6vo7Kjj93s+q8xrfqABcMk5vfB4irbBcLsm17PYfqDfvA==@lists.infradead.org X-Gm-Message-State: AOJu0Yy7arSW/d8M5TFgtFvPN+VNEfp6IOo/nfyvbIChSwjACdyjL6Zt VHr5kfaxnQnK08VnxlrK4IR8XnHei4PJtF5e/dXO0ZAaqWhiJfBDhCkGcQQJQKU= X-Gm-Gg: ASbGncvrGP4b0+EFh7TdO4hJObMVqOMLF5UmETks3ka4IPONeUrARRHCj11fkyzKXF2 6+D9YTLzt8+A5TK+SaxALWUkBY5SvVCqwFu/5M0WvlELwLbuIZuQ5HUtglLpe7f4cc9zLwkFGgW qob3zZMxgElnO8+5SiovY5KYT8fRzL719hD2lVSYAUTxiWFrMVL+b9rRr3TJyCXQR54Vjb0YpEW UeIL9iqciXrpOPwK9oJJdDUv1M+kyE69NITOyniKWQUQPHkVCJFk6UbgrIRxRh/oHfQEXKa9UWz MD2cQrd22M8ELvw= X-Google-Smtp-Source: AGHT+IGlobew52eERJtITGZ1gfIpDVC3U51H+/o8S+NMMG7tU1CeoxEfSB264j/n7py7mlp9j93BGg== X-Received: by 2002:a17:902:f644:b0:212:1ebf:9a03 with SMTP id d9443c01a7336-2189298250bmr173874985ad.2.1734338941574; Mon, 16 Dec 2024 00:49:01 -0800 (PST) Received: from localhost.localdomain ([223.185.130.105]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1e501d0sm37711495ad.116.2024.12.16.00.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 00:49:01 -0800 (PST) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar Subject: [RFC PATCH 5/8] mailbox: Add common header for RPMI messages sent via mailbox Date: Mon, 16 Dec 2024 14:18:14 +0530 Message-ID: <20241216084817.373131-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241216084817.373131-1-apatel@ventanamicro.com> References: <20241216084817.373131-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_004902_404548_DB60B22B X-CRM114-Status: GOOD ( 16.27 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , devicetree@vger.kernel.org, Leyfoon Tan , Anup Patel , Paul Walmsley , linux-kernel@vger.kernel.org, Palmer Dabbelt , Atish Patra , linux-riscv@lists.infradead.org, Andrew Jones , linux-clk@vger.kernel.org, Rahul Pathak Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The RPMI based mailbox controller drivers and mailbox cliens need to share defines related to RPMI messages over mailbox interface so add a common header for this purpose. Co-developed-by: Rahul Pathak Signed-off-by: Rahul Pathak Signed-off-by: Anup Patel --- include/linux/mailbox/riscv-rpmi-message.h | 202 +++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 include/linux/mailbox/riscv-rpmi-message.h diff --git a/include/linux/mailbox/riscv-rpmi-message.h b/include/linux/mailbox/riscv-rpmi-message.h new file mode 100644 index 000000000000..8f4b3a0edbce --- /dev/null +++ b/include/linux/mailbox/riscv-rpmi-message.h @@ -0,0 +1,202 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Ventana Micro Systems Inc. + */ + +#ifndef _LINUX_RISCV_RPMI_MESSAGE_H_ +#define _LINUX_RISCV_RPMI_MESSAGE_H_ + +#include + +/** RPMI version encode/decode macros */ +#define RPMI_VER_MAJOR(__ver) (((__ver) >> 16) & 0xffff) +#define RPMI_VER_MINOR(__ver) ((__ver) & 0xffff) +#define RPMI_MKVER(__maj, __min) (((__maj) << 16) | (__min)) + +/** RPMI message header */ +struct rpmi_message_header { + __le16 servicegroup_id; + u8 service_id; + u8 flags; + __le16 datalen; + __le16 token; +}; + +/** RPMI message */ +struct rpmi_message { + struct rpmi_message_header header; + u8 data[]; +}; + +/** RPMI notification event */ +struct rpmi_notification_event { + __le16 event_datalen; + u8 event_id; + u8 reserved; + u8 event_data[]; +}; + +/** RPMI error codes */ +enum rpmi_error_codes { + RPMI_SUCCESS = 0, + RPMI_ERR_FAILED = -1, + RPMI_ERR_NOTSUPP = -2, + RPMI_ERR_INVALID_PARAM = -3, + RPMI_ERR_DENIED = -4, + RPMI_ERR_INVALID_ADDR = -5, + RPMI_ERR_ALREADY = -6, + RPMI_ERR_EXTENSION = -7, + RPMI_ERR_HW_FAULT = -8, + RPMI_ERR_BUSY = -9, + RPMI_ERR_INVALID_STATE = -10, + RPMI_ERR_BAD_RANGE = -11, + RPMI_ERR_TIMEOUT = -12, + RPMI_ERR_IO = -13, + RPMI_ERR_NO_DATA = -14, + RPMI_ERR_RESERVED_START = -15, + RPMI_ERR_RESERVED_END = -127, + RPMI_ERR_VENDOR_START = -128, +}; + +static inline int rpmi_to_linux_error(int rpmi_error) +{ + switch (rpmi_error) { + case RPMI_SUCCESS: + return 0; + case RPMI_ERR_INVALID_PARAM: + case RPMI_ERR_BAD_RANGE: + case RPMI_ERR_INVALID_STATE: + return -EINVAL; + case RPMI_ERR_DENIED: + return -EPERM; + case RPMI_ERR_INVALID_ADDR: + case RPMI_ERR_HW_FAULT: + return -EFAULT; + case RPMI_ERR_ALREADY: + return -EALREADY; + case RPMI_ERR_BUSY: + return -EBUSY; + case RPMI_ERR_TIMEOUT: + return -ETIMEDOUT; + case RPMI_ERR_IO: + return -ECOMM; + case RPMI_ERR_FAILED: + case RPMI_ERR_NOTSUPP: + case RPMI_ERR_NO_DATA: + case RPMI_ERR_EXTENSION: + default: + return -EOPNOTSUPP; + } +} + +/** RPMI linux mailbox attribute IDs */ +enum rpmi_mbox_attribute_id { + RPMI_MBOX_ATTR_SPEC_VERSION = 0, + RPMI_MBOX_ATTR_MAX_MSG_DATA_SIZE, + RPMI_MBOX_ATTR_SERVICEGROUP_ID, + RPMI_MBOX_ATTR_SERVICEGROUP_VERSION, + RPMI_MBOX_ATTR_MAX_ID, +}; + +/** RPMI linux mailbox message types */ +enum rpmi_mbox_message_type { + RPMI_MBOX_MSG_TYPE_GET_ATTRIBUTE = 0, + RPMI_MBOX_MSG_TYPE_SET_ATTRIBUTE, + RPMI_MBOX_MSG_TYPE_SEND_WITH_RESPONSE, + RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE, + RPMI_MBOX_MSG_TYPE_NOTIFICATION_EVENT, + RPMI_MBOX_MSG_MAX_TYPE, +}; + +/** RPMI linux mailbox message instance */ +struct rpmi_mbox_message { + enum rpmi_mbox_message_type type; + union { + struct { + enum rpmi_mbox_attribute_id id; + u32 value; + } attr; + + struct { + u32 service_id; + void *request; + unsigned long request_len; + void *response; + unsigned long max_response_len; + unsigned long out_response_len; + } data; + + struct rpmi_notification_event *notif_event; + }; + int error; +}; + +/** RPMI linux mailbox message helper routines */ +static inline void rpmi_mbox_init_get_attribute(struct rpmi_mbox_message *msg, + enum rpmi_mbox_attribute_id id) +{ + msg->type = RPMI_MBOX_MSG_TYPE_GET_ATTRIBUTE; + msg->attr.id = id; + msg->attr.value = 0; + msg->error = 0; +} + +static inline void rpmi_mbox_init_set_attribute(struct rpmi_mbox_message *msg, + enum rpmi_mbox_attribute_id id, + u32 value) +{ + msg->type = RPMI_MBOX_MSG_TYPE_SET_ATTRIBUTE; + msg->attr.id = id; + msg->attr.value = value; + msg->error = 0; +} + +static inline void rpmi_mbox_init_send_with_response(struct rpmi_mbox_message *msg, + u32 service_id, + void *request, + unsigned long request_len, + void *response, + unsigned long max_response_len) +{ + msg->type = RPMI_MBOX_MSG_TYPE_SEND_WITH_RESPONSE; + msg->data.service_id = service_id; + msg->data.request = request; + msg->data.request_len = request_len; + msg->data.response = response; + msg->data.max_response_len = max_response_len; + msg->data.out_response_len = 0; + msg->error = 0; +} + +static inline void rpmi_mbox_init_send_without_response(struct rpmi_mbox_message *msg, + u32 service_id, + void *request, + unsigned long request_len) +{ + msg->type = RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE; + msg->data.service_id = service_id; + msg->data.request = request; + msg->data.request_len = request_len; + msg->data.response = NULL; + msg->data.max_response_len = 0; + msg->data.out_response_len = 0; + msg->error = 0; +} + +static inline int rpmi_mbox_send_message(struct mbox_chan *chan, + struct rpmi_mbox_message *msg) +{ + int ret; + + /* Send message for the underlying mailbox channel */ + ret = mbox_send_message(chan, msg); + if (ret < 0) + return ret; + + /* Explicitly signal txdone for mailbox channel */ + ret = msg->error; + mbox_client_txdone(chan, ret); + return ret; +} + +#endif /* _LINUX_RISCV_RPMI_MESSAGE_H_ */