From: <bchalios@amazon.es>
To: <linux-kernel@vger.kernel.org>
Cc: <bchalios@amazon.es>, <tytso@mit.edu>, <Jason@zx2c4.com>,
<dwmw@amazon.co.uk>, <graf@amazon.de>, <xmarcalx@amazon.co.uk>,
<gregkh@linuxfoundation.org>
Subject: [PATCH 1/2] virt: vmgenid: add helper function to parse ADDR
Date: Wed, 3 Aug 2022 17:21:26 +0200 [thread overview]
Message-ID: <20220803152127.48281-2-bchalios@amazon.es> (raw)
In-Reply-To: <20220803152127.48281-1-bchalios@amazon.es>
From: Babis Chalios <bchalios@amazon.es>
Add a helper function to parse the objects of the vmgenid device and use
it to parse the "ADDR" object and return the physical address of vmgenid
data. This prepares the code for adding support for an extra object
including the address of a vmgenid generation counter.
Signed-off-by: Babis Chalios <bchalios@amazon.es>
---
drivers/virt/vmgenid.c | 50 ++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c
index a1c467a0e..0cc2fe0f4 100644
--- a/drivers/virt/vmgenid.c
+++ b/drivers/virt/vmgenid.c
@@ -21,24 +21,20 @@ struct vmgenid_state {
u8 this_id[VMGENID_SIZE];
};
-static int vmgenid_add(struct acpi_device *device)
+static int parse_vmgenid_address(struct acpi_device *device, acpi_string object_name,
+ phys_addr_t *phys_addr)
{
struct acpi_buffer parsed = { ACPI_ALLOCATE_BUFFER };
- struct vmgenid_state *state;
- union acpi_object *obj;
- phys_addr_t phys_addr;
acpi_status status;
+ union acpi_object *obj;
int ret = 0;
- state = devm_kmalloc(&device->dev, sizeof(*state), GFP_KERNEL);
- if (!state)
- return -ENOMEM;
-
- status = acpi_evaluate_object(device->handle, "ADDR", NULL, &parsed);
+ status = acpi_evaluate_object(device->handle, object_name, NULL, &parsed);
if (ACPI_FAILURE(status)) {
- ACPI_EXCEPTION((AE_INFO, status, "Evaluating ADDR"));
+ ACPI_EXCEPTION((AE_INFO, status, "Evaluating vmgenid object"));
return -ENODEV;
}
+
obj = parsed.pointer;
if (!obj || obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 2 ||
obj->package.elements[0].type != ACPI_TYPE_INTEGER ||
@@ -47,22 +43,38 @@ static int vmgenid_add(struct acpi_device *device)
goto out;
}
- phys_addr = (obj->package.elements[0].integer.value << 0) |
- (obj->package.elements[1].integer.value << 32);
+ *phys_addr = (obj->package.elements[0].integer.value << 0) |
+ (obj->package.elements[1].integer.value << 32);
+
+out:
+ ACPI_FREE(parsed.pointer);
+ return ret;
+}
+
+static int vmgenid_add(struct acpi_device *device)
+{
+ struct vmgenid_state *state;
+ phys_addr_t phys_addr;
+ int ret;
+
+ state = devm_kmalloc(&device->dev, sizeof(*state), GFP_KERNEL);
+ if (!state)
+ return -ENOMEM;
+
+ ret = parse_vmgenid_address(device, "ADDR", &phys_addr);
+ if (ret)
+ return ret;
+
state->next_id = devm_memremap(&device->dev, phys_addr, VMGENID_SIZE, MEMREMAP_WB);
- if (IS_ERR(state->next_id)) {
- ret = PTR_ERR(state->next_id);
- goto out;
- }
+ if (IS_ERR(state->next_id))
+ return PTR_ERR(state->next_id);
memcpy(state->this_id, state->next_id, sizeof(state->this_id));
add_device_randomness(state->this_id, sizeof(state->this_id));
device->driver_data = state;
-out:
- ACPI_FREE(parsed.pointer);
- return ret;
+ return 0;
}
static void vmgenid_notify(struct acpi_device *device, u32 event)
--
2.32.1 (Apple Git-133)
Amazon Spain Services sociedad limitada unipersonal, Calle Ramirez de Prado 5, 28045 Madrid. Registro Mercantil de Madrid . Tomo 22458 . Folio 102 . Hoja M-401234 . CIF B84570936
next prev parent reply other threads:[~2022-08-03 15:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-03 15:21 [PATCH 0/2] virt: vmgenid: add generation counter bchalios
2022-08-03 15:21 ` bchalios [this message]
2022-08-03 15:21 ` [PATCH 2/2] virt: vmgenid: add support for " bchalios
2022-08-03 15:28 ` Greg KH
2022-08-03 15:30 ` Greg KH
2022-08-03 17:53 ` Chalios, Babis
2022-08-03 15:31 ` Greg KH
2022-08-03 17:58 ` Chalios, Babis
2022-08-14 3:26 ` kernel test robot
2022-08-03 15:50 ` [PATCH 0/2] virt: vmgenid: add " Chalios, Babis
2022-08-03 15:57 ` Chalios, Babis
2022-08-04 13:33 ` Chalios, Babis
2022-08-04 14:59 ` Jason A. Donenfeld
2022-08-04 15:46 ` bchalios
2022-08-10 9:19 ` bchalios
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220803152127.48281-2-bchalios@amazon.es \
--to=bchalios@amazon.es \
--cc=Jason@zx2c4.com \
--cc=dwmw@amazon.co.uk \
--cc=graf@amazon.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=xmarcalx@amazon.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox