* RE: [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object
@ 2004-09-16 14:07 Tolentino, Matthew E
[not found] ` <D36CE1FCEFD3524B81CA12C6FE5BCAB007B6FA60-oCDej+MBycNZtRGVdHMbwrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Tolentino, Matthew E @ 2004-09-16 14:07 UTC (permalink / raw)
To: Keiichiro Tokunaga, S, Naveen B, Dave Hansen
Cc: acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
lhms-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
>I have changed the patch to create directories and files in
>/sys/firmware/acpi/memory/ from Dave's comments. The files are
>to export the following stuffs of each ACPI memory object for the
>first version.
Hmm. I thought Dave's suggestion was to create an arch-agnostic
viewpoint of physical memory and dump it into
/sys/devices/system/memory in order to gain consistency between
arches...
># ls /sys/firmware/acpi/memory/MEM1/
>address_length
>address_translation_offset
>granularity
>max_address_fixed
>max_address_range
>min_address_fixed
>min_address_range
>producer_consumer
>resource_type
For my understanding, what exactly are all of these attributes for?
matt
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
^ permalink raw reply [flat|nested] 7+ messages in thread[parent not found: <D36CE1FCEFD3524B81CA12C6FE5BCAB007B6FA60-oCDej+MBycNZtRGVdHMbwrfspsVTdybXVpNB7YpNyf8@public.gmane.org>]
* Re: [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object [not found] ` <D36CE1FCEFD3524B81CA12C6FE5BCAB007B6FA60-oCDej+MBycNZtRGVdHMbwrfspsVTdybXVpNB7YpNyf8@public.gmane.org> @ 2004-09-16 16:00 ` Keiichiro Tokunaga 2004-09-16 16:46 ` Keiichiro Tokunaga 1 sibling, 0 replies; 7+ messages in thread From: Keiichiro Tokunaga @ 2004-09-16 16:00 UTC (permalink / raw) To: Tolentino, Matthew E Cc: naveen.b.s-ral2JQCrhuEAvxtiuMwx3w, haveblue-r/Jw6+rmf7HQT0dZR+AlfA, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, lhms-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, tokunaga.keiich-+CUm20s59erQFUHtdCDX3A On Thu, 16 Sep 2004 07:07:07 -0700, Tolentino, Matthew E wrote: > >I have changed the patch to create directories and files in > >/sys/firmware/acpi/memory/ from Dave's comments. The files are > >to export the following stuffs of each ACPI memory object for the > >first version. > > Hmm. I thought Dave's suggestion was to create an arch-agnostic > viewpoint of physical memory and dump it into > /sys/devices/system/memory in order to gain consistency between > arches... Yes, that is also his suggestion. I understand that we have agreedthere are arch-specific and agnostic Actually, the patch is to create just arch-specific directory, since he has agreed with it. > ># ls /sys/firmware/acpi/memory/MEM1/ > >address_length > >address_translation_offset > >granularity > >max_address_fixed > >max_address_range > >min_address_fixed > >min_address_range > >producer_consumer > >resource_type > > For my understanding, what exactly are all of these attributes for? > > matt ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object [not found] ` <D36CE1FCEFD3524B81CA12C6FE5BCAB007B6FA60-oCDej+MBycNZtRGVdHMbwrfspsVTdybXVpNB7YpNyf8@public.gmane.org> 2004-09-16 16:00 ` Keiichiro Tokunaga @ 2004-09-16 16:46 ` Keiichiro Tokunaga [not found] ` <20040917014611.000055db.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org> 1 sibling, 1 reply; 7+ messages in thread From: Keiichiro Tokunaga @ 2004-09-16 16:46 UTC (permalink / raw) To: Tolentino, Matthew E Cc: naveen.b.s-ral2JQCrhuEAvxtiuMwx3w, haveblue-r/Jw6+rmf7HQT0dZR+AlfA, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, lhms-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, tokunaga.keiich-+CUm20s59erQFUHtdCDX3A Sorry, I sent the email in the middle of writing... On Thu, 16 Sep 2004 07:07:07 -0700, Tolentino, Matthew E wrote: > >I have changed the patch to create directories and files in > >/sys/firmware/acpi/memory/ from Dave's comments. The files are > >to export the following stuffs of each ACPI memory object for the > >first version. > > Hmm. I thought Dave's suggestion was to create an arch-agnostic > viewpoint of physical memory and dump it into > /sys/devices/system/memory in order to gain consistency between > arches... Yes, that is also his suggestion. I think we have agreed that there are arch-specific and agnostic directories. The agnostic one would consist of some files that the specific one provides. Actually, the patch is to create just the arch-specific directory. Then I would turn into the agnostic stuffs. > ># ls /sys/firmware/acpi/memory/MEM1/ > >address_length > >address_translation_offset > >granularity > >max_address_fixed > >max_address_range > >min_address_fixed > >min_address_range > >producer_consumer > >resource_type > > For my understanding, what exactly are all of these attributes for? The directory name 'MEM1', min_address_range and max_address_range are used to know the physical address range of the ACPI memory object. Then, we can determine what memsection belongs to the ACPI memory object by using the address range. ACPI container hotplug is assuming to use the method to know corresponding memsections (To be exact, a user mode script 'container.agent' uses it). When ACPI container hotplug is invoked, it knows ACPI object names of devices contained in a container. So when the container hotplug invokes the 'container.agent', it just can tell ACPI object names. The 'container.agent' is responsible for onlining/offlining, so it needs to translate the ACPI object names to memsections. But, I am not sure about the other files... Thanks, Keiichiro Tokunaga ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <20040917014611.000055db.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org>]
* Re: [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object [not found] ` <20040917014611.000055db.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org> @ 2004-09-16 17:55 ` Dave Hansen 2004-09-17 1:43 ` Keiichiro Tokunaga 0 siblings, 1 reply; 7+ messages in thread From: Dave Hansen @ 2004-09-16 17:55 UTC (permalink / raw) To: Keiichiro Tokunaga Cc: Matthew E Tolentino, naveen.b.s-ral2JQCrhuEAvxtiuMwx3w, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, lhms On Thu, 2004-09-16 at 09:46, Keiichiro Tokunaga wrote: > Sorry, I sent the email in the middle of writing... > > On Thu, 16 Sep 2004 07:07:07 -0700, Tolentino, Matthew E wrote: > > >I have changed the patch to create directories and files in > > >/sys/firmware/acpi/memory/ from Dave's comments. The files are > > >to export the following stuffs of each ACPI memory object for the > > >first version. > > > > Hmm. I thought Dave's suggestion was to create an arch-agnostic > > viewpoint of physical memory and dump it into > > /sys/devices/system/memory in order to gain consistency between > > arches... > > Yes, that is also his suggestion. I think we have agreed that there > are arch-specific and agnostic directories. The agnostic one would > consist of some files that the specific one provides. Actually, the > patch is to create just the arch-specific directory. Then I would > turn into the agnostic stuffs. Could you explain what each of those fields means? -- Dave ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object 2004-09-16 17:55 ` Dave Hansen @ 2004-09-17 1:43 ` Keiichiro Tokunaga 0 siblings, 0 replies; 7+ messages in thread From: Keiichiro Tokunaga @ 2004-09-17 1:43 UTC (permalink / raw) To: Dave Hansen Cc: tokunaga.keiich-+CUm20s59erQFUHtdCDX3A, matthew.e.tolentino-ral2JQCrhuEAvxtiuMwx3w, naveen.b.s-ral2JQCrhuEAvxtiuMwx3w, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, lhms-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f On Thu, 16 Sep 2004 10:55:11 -0700 Dave Hansen wrote: > On Thu, 2004-09-16 at 09:46, Keiichiro Tokunaga wrote: > > Sorry, I sent the email in the middle of writing... > > > > On Thu, 16 Sep 2004 07:07:07 -0700, Tolentino, Matthew E wrote: > > > >I have changed the patch to create directories and files in > > > >/sys/firmware/acpi/memory/ from Dave's comments. The files are > > > >to export the following stuffs of each ACPI memory object for the > > > >first version. > > > > > > Hmm. I thought Dave's suggestion was to create an arch-agnostic > > > viewpoint of physical memory and dump it into > > > /sys/devices/system/memory in order to gain consistency between > > > arches... > > > > Yes, that is also his suggestion. I think we have agreed that there > > are arch-specific and agnostic directories. The agnostic one would > > consist of some files that the specific one provides. Actually, the > > patch is to create just the arch-specific directory. Then I would > > turn into the agnostic stuffs. > > Could you explain what each of those fields means? Those fields are all defined in ACPI spec 3.0. I steal the definitions from the spec Table 6-39 below ;) resource_type: This indicates which type of resource this descriptor describes. producer_consumer: 1 - This device consumes this resource 0 - This device produces and consumers this resource decode: (This is for bridge devices) min_address_fixed: 1 - The specified minimum address is fixed 0 - The specified minimum address is not fixed max_address_fixed: 1 - The specified maximum address is fixed 0 - The specified maximum address is not fixed granularity: A set bit in this mask means that this bit is decoded. All bits less significant than the most significant set bit must be set. That is, the value of the full Address Space Granularity field (all 32 bits) must be a number (2^n - 1) min_address_range: (This definition is from the former page, Table 6-36) A minimum base memory address of a device max_address_range: (This definition is from the former page, Table 6-36) A maximum base memory address of a device address_translation_offset: (This is for bridge devices) address_length: (This definition is from the former page, Table 6-36) A length of the memory range I just tried to export the fields for the first version. As I said to Matt, at least min_address_range and max_address_range are in real need so far. So, fields that should be exported might need to be reconsidered. Thanks, Keiichiro Tokunaga ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] ACPI based Memory Hotplug Driver Patch
@ 2004-09-09 10:54 S, Naveen B
2004-09-10 14:02 ` Keiichiro Tokunaga
0 siblings, 1 reply; 7+ messages in thread
From: S, Naveen B @ 2004-09-09 10:54 UTC (permalink / raw)
To: acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
lhms-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Cc: Tolentino, Matthew E, S, Naveen B
Hi,
Attached is an ACPI based hot plug driver patch to support physical memory hotplug. This driver supports physical hotplug operation on memory, fields notifications from firmware and notifies the VM of the affected memory ranges. The following patch is against kernel 2.6.8.1-mm3, and works with the current memory hotplug VM patches posted at: http://sprucegoose.sr71.net/patches. This patch has been tested on real prototype hardware in the hot-add memory case. Hot remove feature is tested in an emulated environment (by overriding ACPI DSDT).
Please review and consider for inclusion.
Thanks & Regards
Signed-off-by: Naveen B S <naveen.b.s-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Matt Tolentino <matthew.e.tolentino-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
drivers/acpi/Kconfig | 7
drivers/acpi/Makefile | 1
drivers/acpi/acpi_ksyms.c | 1
drivers/acpi/memory.c | 576 ++++++++++++++++++++++++++++++++++++++++++++++
drivers/acpi/scan.c | 2
include/acpi/acpi_bus.h | 2
6 files changed, 588 insertions(+), 1 deletion(-)
diff -Nura linux-2.6.8.1-mm3-orig/drivers/acpi/acpi_ksyms.c linux-2.6.8.1-mm3-hpmem/drivers/acpi/acpi_ksyms.c
--- linux-2.6.8.1-mm3-orig/drivers/acpi/acpi_ksyms.c 2004-09-09 13:55:36.000000000 +0530
+++ linux-2.6.8.1-mm3-hpmem/drivers/acpi/acpi_ksyms.c 2004-09-09 14:01:11.000000000 +0530
@@ -135,6 +135,7 @@
EXPORT_SYMBOL(acpi_bus_receive_event);
EXPORT_SYMBOL(acpi_bus_register_driver);
EXPORT_SYMBOL(acpi_bus_unregister_driver);
+EXPORT_SYMBOL(acpi_bus_add);
#endif /*CONFIG_ACPI_BUS*/
diff -Nura linux-2.6.8.1-mm3-orig/drivers/acpi/Kconfig linux-2.6.8.1-mm3-hpmem/drivers/acpi/Kconfig
--- linux-2.6.8.1-mm3-orig/drivers/acpi/Kconfig 2004-09-09 13:55:36.000000000 +0530
+++ linux-2.6.8.1-mm3-hpmem/drivers/acpi/Kconfig 2004-09-09 14:01:11.000000000 +0530
@@ -270,5 +270,12 @@
kernel logs, and/or you are using this on a notebook which
does not yet have an HPET, you should say "Y" here.
+config ACPI_HOTPLUG_MEMORY
+ tristate "Memory Hotplug"
+ depends on ACPI
+ depends on MEMORY_HOTPLUG
+ default m
+ help
+ This driver adds supports for ACPI Memory Hotplug.
endmenu
diff -Nura linux-2.6.8.1-mm3-orig/drivers/acpi/Makefile linux-2.6.8.1-mm3-hpmem/drivers/acpi/Makefile
--- linux-2.6.8.1-mm3-orig/drivers/acpi/Makefile 2004-09-09 13:55:36.000000000 +0530
+++ linux-2.6.8.1-mm3-hpmem/drivers/acpi/Makefile 2004-09-09 14:01:11.000000000 +0530
@@ -48,3 +48,4 @@
obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o
obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o
obj-$(CONFIG_ACPI_BUS) += scan.o motherboard.o
+obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += memory.o
diff -Nura linux-2.6.8.1-mm3-orig/drivers/acpi/memory.c linux-2.6.8.1-mm3-hpmem/drivers/acpi/memory.c
--- linux-2.6.8.1-mm3-orig/drivers/acpi/memory.c 1970-01-01 05:30:00.000000000 +0530
+++ linux-2.6.8.1-mm3-hpmem/drivers/acpi/memory.c 2004-09-09 14:01:47.000000000 +0530
@@ -0,0 +1,576 @@
+/*
+ * Copyright (C) 2004 Intel Corporation <naveen.b.s-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * ACPI based HotPlug driver that supports Memory Hotplug
+ * This driver fields notifications from firmare for memory add
+ * and remove operations and alerts the VM of the affected memory
+ * ranges.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/memory_hotplug.h>
+#include <acpi/acpi_drivers.h>
+
+
+#define ACPI_MEMORY_DEVICE_COMPONENT 0x08000000UL
+#define ACPI_MEMORY_DEVICE_CLASS "memory"
+#define ACPI_MEMORY_DEVICE_HID "PNP0C80"
+#define ACPI_MEMORY_DEVICE_DRIVER_NAME "Hotplug Mem Driver"
+#define ACPI_MEMORY_DEVICE_NAME "Hotplug Mem Device"
+
+#define _COMPONENT ACPI_MEMORY_DEVICE_COMPONENT
+
+ACPI_MODULE_NAME ("acpi_memory")
+MODULE_AUTHOR("Naveen B S <naveen.b.s-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>");
+MODULE_DESCRIPTION(ACPI_MEMORY_DEVICE_DRIVER_NAME);
+MODULE_LICENSE("GPL");
+
+/* ACPI _STA method values */
+#define ACPI_MEMORY_STA_PRESENT (0x00000001UL)
+#define ACPI_MEMORY_STA_ENABLED (0x00000002UL)
+#define ACPI_MEMORY_STA_FUNCTIONAL (0x00000008UL)
+
+/* Memory Device States */
+#define MEMORY_INVALID_STATE 0
+#define MEMORY_POWER_ON_STATE 1
+#define MEMORY_POWER_OFF_STATE 2
+
+static int acpi_memory_device_add (struct acpi_device *device);
+static int acpi_memory_device_remove (struct acpi_device *device, int type);
+
+static struct acpi_driver acpi_memory_device_driver = {
+ .name = ACPI_MEMORY_DEVICE_DRIVER_NAME,
+ .class = ACPI_MEMORY_DEVICE_CLASS,
+ .ids = ACPI_MEMORY_DEVICE_HID,
+ .ops = {
+ .add = acpi_memory_device_add,
+ .remove = acpi_memory_device_remove,
+ },
+};
+
+struct acpi_memory_device {
+ acpi_handle handle;
+ unsigned int state; /* State of the memory device */
+ unsigned short cache_attribute; /* memory cache attribute */
+ unsigned short read_write_attribute;/* memory read/write attribute */
+ u64 start_addr; /* Memory Range start physical addr */
+ u64 end_addr; /* Memory Range end physical addr */
+};
+
+
+static int
+acpi_memory_get_device_resources(struct acpi_memory_device *mem_device)
+{
+ acpi_status status;
+ struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+ struct acpi_resource *resource = NULL;
+ struct acpi_resource_address16 *address16 = NULL;
+ struct acpi_resource_address32 *address32 = NULL;
+ struct acpi_resource_address64 *address64 = NULL;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_get_device_resources");
+
+ /* Get the range from the _CRS */
+ status = acpi_get_current_resources(mem_device->handle, &buffer);
+ if (ACPI_FAILURE(status))
+ return_VALUE(-EINVAL);
+
+ resource = (struct acpi_resource *) buffer.pointer;
+
+ switch (resource->id) {
+ case ACPI_RSTYPE_ADDRESS16:
+ address16 = (struct acpi_resource_address16 *) &resource->data;
+ if (address16->resource_type != ACPI_MEMORY_RANGE)
+ break;
+
+ /* Populate the structure */
+ mem_device->cache_attribute =
+ address16->attribute.memory.cache_attribute;
+ mem_device->read_write_attribute =
+ address16->attribute.memory.read_write_attribute;
+ mem_device->start_addr = address16->min_address_range;
+ mem_device->end_addr = address16->max_address_range;
+ break;
+
+ case ACPI_RSTYPE_ADDRESS32:
+ address32 = (struct acpi_resource_address32 *) &resource->data;
+ if (address32->resource_type != ACPI_MEMORY_RANGE)
+ break;
+
+ /* Populate the structure */
+ mem_device->cache_attribute =
+ address32->attribute.memory.cache_attribute;
+ mem_device->read_write_attribute =
+ address32->attribute.memory.read_write_attribute;
+ mem_device->start_addr = address32->min_address_range;
+ mem_device->end_addr = address32->max_address_range;
+ break;
+
+ case ACPI_RSTYPE_ADDRESS64:
+ address64 = (struct acpi_resource_address64 *) &resource->data;
+ if (address64->resource_type != ACPI_MEMORY_RANGE)
+ break;
+
+ /* Populate the structure */
+ mem_device->cache_attribute =
+ address64->attribute.memory.cache_attribute;
+ mem_device->read_write_attribute =
+ address64->attribute.memory.read_write_attribute;
+ mem_device->start_addr = address64->min_address_range;
+ mem_device->end_addr = address64->max_address_range;
+ break;
+
+ default:
+ break;
+ }
+
+ acpi_os_free(buffer.pointer);
+ return_VALUE(0);
+}
+
+static int
+acpi_memory_get_device(acpi_handle handle,
+ struct acpi_memory_device **mem_device)
+{
+ acpi_status status;
+ acpi_handle phandle;
+ struct acpi_device *device = NULL;
+ struct acpi_device *pdevice = NULL;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_get_device");
+
+ if (!acpi_bus_get_device(handle, &device) && device)
+ goto end;
+
+ status = acpi_get_parent(handle, &phandle);
+ if (ACPI_FAILURE(status)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Error in acpi_get_parent\n"));
+ return_VALUE(-EINVAL);
+ }
+
+ /* Get the parent device */
+ status = acpi_bus_get_device(phandle, &pdevice);
+ if (ACPI_FAILURE(status)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Error in acpi_bus_get_device\n"));
+ return_VALUE(-EINVAL);
+ }
+
+ /*
+ * Now add the notified device. This creates the acpi_device
+ * and invokes .add function
+ */
+ status = acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE);
+ if (ACPI_FAILURE(status)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Error in acpi_bus_add\n"));
+ return_VALUE(-EINVAL);
+ }
+
+end:
+ *mem_device = acpi_driver_data(device);
+ if (!(*mem_device)) {
+ printk(KERN_ERR "\n driver data not found" );
+ return_VALUE(-ENODEV);
+ }
+
+ return_VALUE(0);
+}
+
+static int
+acpi_memory_check_device(struct acpi_memory_device *mem_device)
+{
+ unsigned long current_status;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_check_device");
+
+ /* Get device present/absent information from the _STA */
+ if (ACPI_FAILURE(acpi_evaluate_integer(mem_device->handle, "_STA",
+ NULL, ¤t_status)))
+ return_VALUE(-ENODEV);
+ /*
+ * Check for device status. Device should be
+ * present/enabled/functioning.
+ */
+ if (!((current_status & ACPI_MEMORY_STA_PRESENT)
+ && (current_status & ACPI_MEMORY_STA_ENABLED)
+ && (current_status & ACPI_MEMORY_STA_FUNCTIONAL)))
+ return_VALUE(-ENODEV);
+
+ return_VALUE(0);
+}
+
+static int
+acpi_memory_enable_device(struct acpi_memory_device *mem_device)
+{
+ int result;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_enable_device");
+
+ /* Get the range from the _CRS */
+ result = acpi_memory_get_device_resources(mem_device);
+ if (result) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "\nget_device_resources failed\n"));
+ mem_device->state = MEMORY_INVALID_STATE;
+ return result;
+ }
+
+ /*
+ * Tell the VM there is more memory here...
+ * Note: Assume that this function returns zero on success
+ */
+ result = add_memory(mem_device->start_addr,
+ (mem_device->end_addr - mem_device->start_addr) + 1,
+ mem_device->read_write_attribute);
+ if (result) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "\nadd_memory failed\n"));
+ mem_device->state = MEMORY_INVALID_STATE;
+ return result;
+ }
+
+ return result;
+}
+
+static int
+acpi_memory_powerdown_device(struct acpi_memory_device *mem_device)
+{
+ acpi_status status;
+ struct acpi_object_list arg_list;
+ union acpi_object arg;
+ unsigned long current_status;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_powerdown_device");
+
+ /* Issue the _EJ0 command */
+ arg_list.count = 1;
+ arg_list.pointer = &arg;
+ arg.type = ACPI_TYPE_INTEGER;
+ arg.integer.value = 1;
+ status = acpi_evaluate_object(mem_device->handle,
+ "_EJ0", &arg_list, NULL);
+ /* Return on _EJ0 failure */
+ if (ACPI_FAILURE(status)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"_EJ0 failed.\n"));
+ return_VALUE(-ENODEV);
+ }
+
+ /* Evalute _STA to check if the device is disabled */
+ status = acpi_evaluate_integer(mem_device->handle, "_STA",
+ NULL, ¤t_status);
+ if (ACPI_FAILURE(status))
+ return_VALUE(-ENODEV);
+
+ /* Check for device status. Device should be disabled */
+ if (current_status & ACPI_MEMORY_STA_ENABLED)
+ return_VALUE(-EINVAL);
+
+ return_VALUE(0);
+}
+
+static int
+acpi_memory_disable_device(struct acpi_memory_device *mem_device)
+{
+ int result;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_disable_device");
+
+ /*
+ * Ask the VM to offline this memory range.
+ * Note: Assume that this function returns zero on success
+ */
+ if (remove_memory(mem_device->start_addr,
+ (mem_device->end_addr - mem_device->start_addr) + 1,
+ mem_device->read_write_attribute)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Hot-Remove failed.\n"));
+ return_VALUE(-EINVAL);
+ }
+
+ /* Power-off and eject the device */
+ result = acpi_memory_powerdown_device(mem_device);
+ if (result) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Device Power Down failed.\n"));
+ /* Set the status of the device to invalid */
+ mem_device->state = MEMORY_INVALID_STATE;
+ return result;
+ }
+
+ mem_device->state = MEMORY_POWER_OFF_STATE;
+ return result;
+}
+
+static void
+acpi_memory_device_notify(acpi_handle handle, u32 event, void *data)
+{
+ struct acpi_memory_device *mem_device;
+ struct acpi_device *device;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_device_notify");
+
+ switch (event) {
+ case ACPI_NOTIFY_BUS_CHECK:
+ ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+ "\nReceived BUS CHECK notification for device\n"));
+ /* Fall Through */
+ case ACPI_NOTIFY_DEVICE_CHECK:
+ if (event == ACPI_NOTIFY_DEVICE_CHECK)
+ ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+ "\nReceived DEVICE CHECK notification for device\n"));
+ if (acpi_memory_get_device(handle, &mem_device)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Error in finding driver data\n"));
+ return_VOID;
+ }
+
+ if (!acpi_memory_check_device(mem_device)) {
+ if (acpi_memory_enable_device(mem_device))
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Error in acpi_memory_enable_device\n"));
+ }
+ break;
+ case ACPI_NOTIFY_EJECT_REQUEST:
+ ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+ "\nReceived EJECT REQUEST notification for device\n"));
+
+ if (acpi_bus_get_device(handle, &device)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Device doesn't exist\n"));
+ break;
+ }
+ mem_device = acpi_driver_data(device);
+ if (!mem_device) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Driver Data is NULL\n"));
+ break;
+ }
+
+ /*
+ * Currently disabling memory device from kernel mode
+ * TBD: Can also be disabled from user mode scripts
+ * TBD: Can also be disabled by Callback registration
+ * with generic sysfs driver
+ */
+ if (acpi_memory_disable_device(mem_device))
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Error in acpi_memory_disable_device\n"));
+ /*
+ * TBD: Invoke acpi_bus_remove to cleanup data structures
+ */
+ break;
+ default:
+ ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+ "Unsupported event [0x%x]\n", event));
+ break;
+ }
+
+ return_VOID;
+}
+
+static int
+acpi_memory_device_add(struct acpi_device *device)
+{
+ int result;
+ struct acpi_memory_device *mem_device = NULL;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_device_add");
+
+ if (!device)
+ return_VALUE(-EINVAL);
+
+ mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL);
+ if (!mem_device)
+ return_VALUE(-ENOMEM);
+ memset(mem_device, 0, sizeof(struct acpi_memory_device));
+
+ mem_device->handle = device->handle;
+ sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME);
+ sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS);
+ acpi_driver_data(device) = mem_device;
+
+ /* Get the range from the _CRS */
+ result = acpi_memory_get_device_resources(mem_device);
+ if (result) {
+ kfree(mem_device);
+ return_VALUE(result);
+ }
+
+ /* Set the device state */
+ mem_device->state = MEMORY_POWER_ON_STATE;
+
+ printk(KERN_INFO "%s \n", acpi_device_name(device));
+
+ return_VALUE(result);
+}
+
+static int
+acpi_memory_device_remove (struct acpi_device *device, int type)
+{
+ struct acpi_memory_device *mem_device = NULL;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_device_remove");
+
+ if (!device || !acpi_driver_data(device))
+ return_VALUE(-EINVAL);
+
+ mem_device = (struct acpi_memory_device *) acpi_driver_data(device);
+ kfree(mem_device);
+
+ return_VALUE(0);
+}
+
+/*
+ * Helper function to check for memory device
+ */
+static acpi_status is_memory_device(acpi_handle handle)
+{
+ char *hardware_id;
+ acpi_status status;
+ struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+ struct acpi_device_info *info;
+
+ ACPI_FUNCTION_TRACE("is_memory_device");
+
+ status = acpi_get_object_info(handle, &buffer);
+ if (ACPI_FAILURE(status))
+ return_ACPI_STATUS(AE_ERROR);
+
+ info = buffer.pointer;
+ if (!(info->valid & ACPI_VALID_HID)) {
+ acpi_os_free(buffer.pointer);
+ return_ACPI_STATUS(AE_ERROR);
+ }
+
+ hardware_id = info->hardware_id.value;
+ if ((hardware_id == NULL) ||
+ (strcmp(hardware_id, ACPI_MEMORY_DEVICE_HID)))
+ status = AE_ERROR;
+
+ acpi_os_free(buffer.pointer);
+ return_ACPI_STATUS(status);
+}
+
+static acpi_status
+acpi_memory_register_notify_handler (acpi_handle handle,
+ u32 level, void *ctxt, void **retv)
+{
+ acpi_status status;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_register_notify_handler");
+
+ status = is_memory_device(handle);
+ if (ACPI_FAILURE(status))
+ return_ACPI_STATUS(AE_OK); /* continue */
+
+ status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
+ acpi_memory_device_notify, NULL);
+ if (ACPI_FAILURE(status)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Error installing notify handler\n"));
+ return_ACPI_STATUS(AE_OK); /* continue */
+ }
+
+ return_ACPI_STATUS(status);
+}
+
+static acpi_status
+acpi_memory_deregister_notify_handler (acpi_handle handle,
+ u32 level, void *ctxt, void **retv)
+{
+ acpi_status status;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_deregister_notify_handler");
+
+ status = is_memory_device(handle);
+ if (ACPI_FAILURE(status))
+ return_ACPI_STATUS(AE_OK); /* continue */
+
+ status = acpi_remove_notify_handler(handle,
+ ACPI_SYSTEM_NOTIFY, acpi_memory_device_notify);
+ if (ACPI_FAILURE(status)) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
+ "Error removing notify handler\n"));
+ return_ACPI_STATUS(AE_OK); /* continue */
+ }
+
+ return_ACPI_STATUS(status);
+}
+
+static int __init
+acpi_memory_device_init (void)
+{
+ int result;
+ acpi_status status;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_device_init");
+
+ result = acpi_bus_register_driver(&acpi_memory_device_driver);
+
+ if (result < 0)
+ return_VALUE(-ENODEV);
+
+ status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+ ACPI_UINT32_MAX,
+ acpi_memory_register_notify_handler,
+ NULL, NULL);
+
+ if (ACPI_FAILURE (status)) {
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed\n"));
+ acpi_bus_unregister_driver(&acpi_memory_device_driver);
+ return_VALUE(-ENODEV);
+ }
+
+ return_VALUE(0);
+}
+
+static void __exit
+acpi_memory_device_exit (void)
+{
+ acpi_status status;
+
+ ACPI_FUNCTION_TRACE("acpi_memory_device_exit");
+
+ /*
+ * Adding this to un-install notification handlers for all the device
+ * handles.
+ */
+ status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+ ACPI_UINT32_MAX,
+ acpi_memory_deregister_notify_handler,
+ NULL, NULL);
+
+ if (ACPI_FAILURE (status))
+ ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed\n"));
+
+ acpi_bus_unregister_driver(&acpi_memory_device_driver);
+
+ return_VOID;
+}
+
+module_init(acpi_memory_device_init);
+module_exit(acpi_memory_device_exit);
+
+
diff -Nura linux-2.6.8.1-mm3-orig/drivers/acpi/scan.c linux-2.6.8.1-mm3-hpmem/drivers/acpi/scan.c
--- linux-2.6.8.1-mm3-orig/drivers/acpi/scan.c 2004-09-09 13:55:36.000000000 +0530
+++ linux-2.6.8.1-mm3-hpmem/drivers/acpi/scan.c 2004-09-09 14:01:11.000000000 +0530
@@ -760,7 +760,7 @@
#endif /*CONFIG_ACPI_DEBUG_OUTPUT*/
}
-static int
+int
acpi_bus_add (
struct acpi_device **child,
struct acpi_device *parent,
diff -Nura linux-2.6.8.1-mm3-orig/include/acpi/acpi_bus.h linux-2.6.8.1-mm3-hpmem/include/acpi/acpi_bus.h
--- linux-2.6.8.1-mm3-orig/include/acpi/acpi_bus.h 2004-09-09 13:55:01.000000000 +0530
+++ linux-2.6.8.1-mm3-hpmem/include/acpi/acpi_bus.h 2004-09-09 14:01:11.000000000 +0530
@@ -321,6 +321,8 @@
int acpi_bus_receive_event (struct acpi_bus_event *event);
int acpi_bus_register_driver (struct acpi_driver *driver);
int acpi_bus_unregister_driver (struct acpi_driver *driver);
+int acpi_bus_add (struct acpi_device **child, struct acpi_device *parent,
+ acpi_handle handle, int type);
int acpi_create_dir(struct acpi_device *);
void acpi_remove_dir(struct acpi_device *);
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idP47&alloc_id\x10808&op=click
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] ACPI based Memory Hotplug Driver Patch @ 2004-09-10 14:02 ` Keiichiro Tokunaga [not found] ` <20040910230200.73eb0374.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Keiichiro Tokunaga @ 2004-09-10 14:02 UTC (permalink / raw) To: S, Naveen B, matthew.e.tolentino-ral2JQCrhuEAvxtiuMwx3w Cc: tokunaga.keiich-+CUm20s59erQFUHtdCDX3A, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, lhms-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f On Thu, 09 Sep 2004 16:24:46 +0530 S, Naveen B wrote: > Attached is an ACPI based hot plug driver patch to support physical > memory hotplug. This driver supports physical hotplug operation on > memory, fields notifications from firmware and notifies the VM of the > affected memory ranges. The following patch is against kernel > 2.6.8.1-mm3, and works with the current memory hotplug VM patches > posted at: http://sprucegoose.sr71.net/patches. This patch has been > tested on real prototype hardware in the hot-add memory case. Hot > remove feature is tested in an emulated environment (by overriding > ACPI DSDT). > > Please review and consider for inclusion. I would like to add a feature into drivers/acpi/memory.c. Please see the patch below. This patch is for the kernel applying your patch. This patch generates procfs entry 'info' for each memory ACPI object to expose memory device information. This information is needed to determine which logical memory ID(s) (memsection ID) belongs which memory ACPI object (e.g. memsection5 --> MEM0). Memsection IDs could be fingured out from min_address_range and max_address_range that 'info' file shows. Actually, container hotplug is assuming to use the information, because 'container.agent', which lives in the userland, needs to search memsection entires related with a certain ACPI memory object name (e.g. MEM0) to invoke generic memory hotplug function. The 'info' file shows the following information. kei%cat /proc/acpi/memory/MEM0/info resource_type: 0x0 producer_consumer: 0x0 decode: 0x0 min_address: 0x0 max_address: 0x0 granularity: 0x0 min_address_range: 0x0 max_address_range: 0x80000000 address_translation_offset: 0x0 address_length: 0x80000000 Thanks, Keiichiro Tokunaga Signed-off-by: Keiichiro Tokunaga (tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org) --- linux-2.6.8.1-mm3-mem-kei/drivers/acpi/memory.c | 155 ++++++++++++++++++++++-- 1 files changed, 148 insertions(+), 7 deletions(-) diff -puN drivers/acpi/memory.c~proc_memory drivers/acpi/memory.c --- linux-2.6.8.1-mm3-mem/drivers/acpi/memory.c~proc_memory 2004-09-10 14:01:21.000000000 +0900 +++ linux-2.6.8.1-mm3-mem-kei/drivers/acpi/memory.c 2004-09-10 17:37:54.000000000 +0900 @@ -29,6 +29,8 @@ #include <linux/module.h> #include <linux/init.h> #include <linux/types.h> +#include <linux/proc_fs.h> +#include <linux/seq_file.h> #include <linux/memory_hotplug.h> #include <acpi/acpi_drivers.h> @@ -38,6 +40,8 @@ #define ACPI_MEMORY_DEVICE_HID "PNP0C80" #define ACPI_MEMORY_DEVICE_DRIVER_NAME "Hotplug Mem Driver" #define ACPI_MEMORY_DEVICE_NAME "Hotplug Mem Device" +#define ACPI_MEMORY_DEVICE_FILE_INFO "info" + #define _COMPONENT ACPI_MEMORY_DEVICE_COMPONENT @@ -61,6 +65,7 @@ MODULE_LICENSE("GPL"); static int acpi_memory_device_add (struct acpi_device *device); static int acpi_memory_device_remove (struct acpi_device *device, int type); void acpi_memory_device_notify(acpi_handle handle, u32 event, void *data); +static int acpi_memory_info_open_fs(struct inode *inode, struct file *file); static struct acpi_driver acpi_memory_device_driver = { .name = ACPI_MEMORY_DEVICE_DRIVER_NAME, @@ -79,11 +84,124 @@ struct acpi_memory_device { unsigned short read_write_attribute;/* memory read/write attribute */ u64 start_addr; /* Memory Range start physical addr */ u64 end_addr; /* Memory Range end physical addr */ + struct acpi_resource resource; }; #define to_memory_device(sys_device) container_of(sys_device, \ struct acpi_memory_device, sysdev) +static struct file_operations acpi_memory_device_info_fops = { + .open = acpi_memory_info_open_fs, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +struct proc_dir_entry *acpi_memory_device_dir = NULL; + +static int acpi_memory_info_seq_show(struct seq_file *seq, void *offset) +{ + struct acpi_memory_device *mem_device = (struct acpi_memory_device *)seq->private; + struct acpi_resource *resource; + struct acpi_resource_address64 address64; + + ACPI_FUNCTION_TRACE("acpi_memory_info_seq_show"); + + if (!mem_device) + goto end; + + resource = &mem_device->resource; + + /* + * Even if the resource is an address16 or address32, or address64, + * copy it to the adddress64 return buffer. + */ + acpi_resource_to_address64(resource, &address64); + + if (address64.resource_type != ACPI_MEMORY_RANGE) { + goto end; + } + + seq_printf(seq, + "resource_type: 0x%x\n" + "producer_consumer: 0x%x\n" + "decode: 0x%x\n" + "min_address: 0x%x\n" + "max_address: 0x%x\n" + "granularity: 0x%lx\n" + "min_address_range: 0x%lx\n" + "max_address_range: 0x%lx\n" + "address_translation_offset: 0x%lx\n" + "address_length: 0x%lx\n", + address64.resource_type, + address64.producer_consumer, + address64.decode, + address64.min_address_fixed, + address64.max_address_fixed, + address64.granularity, + address64.min_address_range, + address64.max_address_range, + address64.address_translation_offset, + address64.address_length); +end: + return 0; +} + +static int acpi_memory_info_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_memory_info_seq_show, + PDE(inode)->data); +} + +static int +acpi_memory_add_fs ( + struct acpi_device *device) +{ + struct proc_dir_entry *entry = NULL; + + ACPI_FUNCTION_TRACE("acpi_memory_add_fs"); + + if (!acpi_device_dir(device)) { + acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), + acpi_memory_device_dir); + if (!acpi_device_dir(device)) + return_VALUE(-ENODEV); + } + acpi_device_dir(device)->owner = THIS_MODULE; + + /* 'info' [R] */ + entry = create_proc_entry(ACPI_MEMORY_DEVICE_FILE_INFO, + S_IRUGO, acpi_device_dir(device)); + if (!entry) + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, + "Unable to create '%s' fs entry\n", + ACPI_MEMORY_DEVICE_FILE_INFO)); + else { + entry->proc_fops = &acpi_memory_device_info_fops; + entry->data = acpi_driver_data(device); + entry->owner = THIS_MODULE; + } + + return_VALUE(0); +} + +static int +acpi_memory_remove_fs ( + struct acpi_device *device) +{ + ACPI_FUNCTION_TRACE("acpi_memory_remove_fs"); + + if (acpi_device_dir(device)) { + remove_proc_entry(ACPI_MEMORY_DEVICE_FILE_INFO, + acpi_device_dir(device)); + remove_proc_entry(acpi_device_bid(device), + acpi_memory_device_dir); + acpi_device_dir(device) = NULL; + } + + return_VALUE(0); +} + static int acpi_memory_get_device_resources(struct acpi_memory_device *mem_device) { @@ -102,6 +220,7 @@ acpi_memory_get_device_resources(struct return_VALUE(-EINVAL); resource = (struct acpi_resource *) buffer.pointer; + mem_device->resource = *resource; switch (resource->id) { case ACPI_RSTYPE_ADDRESS16: @@ -409,16 +528,19 @@ acpi_memory_device_add(struct acpi_devic /* Get the range from the _CRS */ result = acpi_memory_get_device_resources(mem_device); - if (result) { - kfree(mem_device); - return_VALUE(result); - } + if (result) + goto end; /* Set the device state */ mem_device->state = MEMORY_POWER_ON_STATE; printk(KERN_INFO "%s \n", acpi_device_name(device)); + /* procfs */ + result = acpi_memory_add_fs(device); + if (result) + goto end; + status = acpi_install_notify_handler(mem_device->handle, ACPI_SYSTEM_NOTIFY, acpi_memory_device_notify, mem_device); if (ACPI_FAILURE(status)) { @@ -428,6 +550,12 @@ acpi_memory_device_add(struct acpi_devic kfree(mem_device); } +end: + if (result) { + acpi_memory_remove_fs(device); + kfree(mem_device); + } + return_VALUE(result); } @@ -442,6 +570,9 @@ acpi_memory_device_remove (struct acpi_d return_VALUE(-EINVAL); mem_device = (struct acpi_memory_device *) acpi_driver_data(device); + + acpi_memory_remove_fs(device); + kfree(mem_device); return_VALUE(0); @@ -531,11 +662,18 @@ acpi_memory_device_init (void) ACPI_FUNCTION_TRACE("acpi_memory_device_init"); - result = acpi_bus_register_driver(&acpi_memory_device_driver); + acpi_memory_device_dir = proc_mkdir(ACPI_MEMORY_DEVICE_CLASS, + acpi_root_dir); + if (!acpi_memory_device_dir) + return_VALUE(-ENODEV); + acpi_memory_device_dir->owner = THIS_MODULE; - if (result < 0) + result = acpi_bus_register_driver(&acpi_memory_device_driver); + if (result < 0) { + remove_proc_entry(ACPI_MEMORY_DEVICE_CLASS, acpi_root_dir); return_VALUE(-ENODEV); - + } + status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, acpi_memory_register_notify_handler, @@ -543,6 +681,7 @@ acpi_memory_device_init (void) if (ACPI_FAILURE (status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed\n")); + remove_proc_entry(ACPI_MEMORY_DEVICE_CLASS, acpi_root_dir); acpi_bus_unregister_driver(&acpi_memory_device_driver); return_VALUE(-ENODEV); } @@ -571,6 +710,8 @@ acpi_memory_device_exit (void) acpi_bus_unregister_driver(&acpi_memory_device_driver); + remove_proc_entry(ACPI_MEMORY_DEVICE_CLASS, acpi_root_dir); + return_VOID; } _ ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <20040910230200.73eb0374.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org>]
* [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object [not found] ` <20040910230200.73eb0374.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org> @ 2004-09-16 10:47 ` Keiichiro Tokunaga [not found] ` <20040916194725.562b50f0.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Keiichiro Tokunaga @ 2004-09-16 10:47 UTC (permalink / raw) To: naveen.b.s-ral2JQCrhuEAvxtiuMwx3w, Dave Hansen Cc: tokunaga.keiich-+CUm20s59erQFUHtdCDX3A, matthew.e.tolentino-ral2JQCrhuEAvxtiuMwx3w, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, lhms-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f On Fri, 10 Sep 2004 23:02:00 +0900 Keiichiro Tokunaga wrote: > On Thu, 09 Sep 2004 16:24:46 +0530 S, Naveen B wrote: > > Attached is an ACPI based hot plug driver patch to support physical > > memory hotplug. This driver supports physical hotplug operation on > > memory, fields notifications from firmware and notifies the VM of the > > affected memory ranges. The following patch is against kernel > > 2.6.8.1-mm3, and works with the current memory hotplug VM patches > > posted at: http://sprucegoose.sr71.net/patches. This patch has been > > tested on real prototype hardware in the hot-add memory case. Hot > > remove feature is tested in an emulated environment (by overriding > > ACPI DSDT). > > > > Please review and consider for inclusion. > > I would like to add a feature into drivers/acpi/memory.c. > > Please see the patch below. This patch is for the kernel applying > your patch. I have changed the patch to create directories and files in /sys/firmware/acpi/memory/ from Dave's comments. The files are to export the following stuffs of each ACPI memory object for the first version. # ls /sys/firmware/acpi/memory/MEM1/ address_length address_translation_offset granularity max_address_fixed max_address_range min_address_fixed min_address_range producer_consumer resource_type # cat /sys/firmware/acpi/memory/MEM1/min_address_range 0xc0000000 Naveen, if it looks okay, please include it to your patch. If you are still working on 2.6.8.1-mm3, it applies. If you are not, please let me know. Thanks, Keiichiro Tokunaga Signed-off-by: Keiichiro Tokunaga <tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org> --- drivers/acpi/memory.c | 363 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 358 insertions(+), 5 deletions(-) diff -puN drivers/acpi/memory.c~sysfs_memory drivers/acpi/memory.c --- linux-2.6.8.1-mm3/drivers/acpi/memory.c~sysfs_memory 2004-09-16 10:19:00.000000000 +0900 +++ linux-2.6.8.1-mm3-kei/drivers/acpi/memory.c 2004-09-16 19:06:38.000000000 +0900 @@ -69,6 +69,15 @@ static struct acpi_driver acpi_memory_de }, }; +struct acpi_mem { + struct acpi_mem_device_ops *ops; + void (*release)(struct acpi_mem *mdev); + struct kobject kobj; +}; + +#define to_acpi_mem(n) container_of(n, struct acpi_mem, kobj) +#define acpi_mem_to_dev(n) container_of(n, struct acpi_memory_device, amem) + struct acpi_memory_device { acpi_handle handle; unsigned int state; /* State of the memory device */ @@ -76,8 +85,335 @@ struct acpi_memory_device { unsigned short read_write_attribute;/* memory read/write attribute */ u64 start_addr; /* Memory Range start physical addr */ u64 end_addr; /* Memory Range end physical addr */ + struct acpi_resource resource; + struct acpi_mem amem; +}; + +/* + * /sys/firmware/acpi/memory/ + */ +struct acpi_mem_attribute { + struct attribute attr; + ssize_t (*show)(struct acpi_mem *, char *); + ssize_t (*store)(struct acpi_mem *, const char *, size_t); }; +#define to_acpi_mem_attr(n) container_of(n, struct acpi_mem_attribute, attr) + +static ssize_t acpi_mem_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + struct acpi_mem *amem = to_acpi_mem(kobj); + struct acpi_mem_attribute *attribute = to_acpi_mem_attr(attr); + return attribute->show ? attribute->show(amem, buf) : 0; +} + +static ssize_t acpi_mem_attr_store(struct kobject *kobj, + struct attribute *attr, const char *buf, + size_t len) +{ + struct acpi_mem *amem = to_acpi_mem(kobj); + struct acpi_mem_attribute *attribute = to_acpi_mem_attr(attr); + return attribute->store ? attribute->store(amem, buf, len) : 0; +} + +static struct sysfs_ops acpi_mem_sysfs_ops = { + .show = acpi_mem_attr_show, + .store = acpi_mem_attr_store, +}; + +static void acpi_mem_release(struct kobject *kobj) +{ + sysfs_remove_dir(kobj); + if (kobj->kset) { + down_write(&kobj->kset->subsys->rwsem); + list_del_init(&kobj->entry); + up_write(&kobj->kset->subsys->rwsem); + } +} + +static struct kobj_type acpi_mem_ktype = { + .sysfs_ops = &acpi_mem_sysfs_ops, + .release = &acpi_mem_release, +}; + +static decl_subsys_name(acpi_mem, memory, &acpi_mem_ktype, NULL); + +static int acpi_mem_register(struct acpi_mem *amem) +{ + return kobject_register(&amem->kobj); +} + +int create_acpi_mem(struct acpi_memory_device *mem_device, + struct acpi_device *device) +{ + int result; + struct acpi_mem *amem = &mem_device->amem; + + ACPI_FUNCTION_TRACE("create_acpi_mem"); + + memset(amem, 0, sizeof(struct acpi_mem)); + kobject_set_name(&amem->kobj, device->pnp.bus_id); + kobj_set_kset_s(amem, acpi_mem_subsys); + amem->kobj.parent = &acpi_mem_subsys.kset.kobj; + + result = acpi_mem_register(amem); + if (result) + goto end; +end: + return_VALUE(result); +} + +int acpi_mem_fs_init(void) +{ + int result; + extern struct subsystem acpi_subsys; + + ACPI_FUNCTION_TRACE("acpi_mem_fs_init"); + + acpi_mem_subsys.kset.kobj.parent = &acpi_subsys.kset.kobj; + result = subsystem_register(&acpi_mem_subsys); + + return_VALUE(result); +} + +void acpi_mem_fs_exit(void) +{ + ACPI_FUNCTION_TRACE("acpi_mem_fs_exit"); + + subsystem_unregister(&acpi_mem_subsys); + + return_VOID; +} + +static int get_address64(struct acpi_mem *amem, + struct acpi_resource_address64 *address64) +{ + struct acpi_memory_device *mem_device = acpi_mem_to_dev(amem); + struct acpi_resource *resource; + + if (!mem_device) + return -ENODEV; + + resource = &mem_device->resource; + + acpi_resource_to_address64(resource, address64); + + if (address64->resource_type != ACPI_MEMORY_RANGE) + return -EINVAL; + + return 0; +} + +static ssize_t resource_type_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%x\n", address64.resource_type); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_resource_type = { + .attr = {.name = "resource_type", .mode = S_IFREG | S_IRUGO}, + .show = resource_type_read_file, +}; + +static ssize_t producer_consumer_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%x\n", address64.producer_consumer); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_producer_consumer = { + .attr = {.name = "producer_consumer", .mode = S_IFREG | S_IRUGO}, + .show = producer_consumer_read_file, +}; + +static ssize_t decode_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%x\n", address64.decode); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_decode = { + .attr = {.name = "decode", .mode = S_IFREG | S_IRUGO}, + .show = decode_read_file, +}; + +static ssize_t min_address_fixed_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%x\n", address64.min_address_fixed); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_min_address_fixed = { + .attr = {.name = "min_address_fixed", .mode = S_IFREG | S_IRUGO}, + .show = min_address_fixed_read_file, +}; + +static ssize_t max_address_fixed_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%x\n", address64.max_address_fixed); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_max_address_fixed = { + .attr = {.name = "max_address_fixed", .mode = S_IFREG | S_IRUGO}, + .show = max_address_fixed_read_file, +}; + +static ssize_t granularity_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%llx\n", address64.granularity); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_granularity = { + .attr = {.name = "granularity", .mode = S_IFREG | S_IRUGO}, + .show = granularity_read_file, +}; + +static ssize_t min_address_range_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%llx\n", address64.min_address_range); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_min_address_range = { + .attr = {.name = "min_address_range", .mode = S_IFREG | S_IRUGO}, + .show = min_address_range_read_file, +}; + +static ssize_t max_address_range_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%llx\n", address64.max_address_range); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_max_address_range = { + .attr = {.name = "max_address_range", .mode = S_IFREG | S_IRUGO}, + .show = max_address_range_read_file, +}; + +static ssize_t address_translation_offset_read_file(struct acpi_mem *amem, + char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%llx\n", + address64.address_translation_offset); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_address_translation_offset = { + .attr = {.name = "address_translation_offset", + .mode = S_IFREG | S_IRUGO}, + .show = address_translation_offset_read_file, +}; + +static ssize_t address_length_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%llx\n", address64.address_length); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_address_length = { + .attr = {.name = "address_length", .mode = S_IFREG | S_IRUGO}, + .show = address_length_read_file, +}; + +static int fs_add_memory(struct acpi_mem *amem) +{ + sysfs_create_file(&amem->kobj, &acpi_mem_attr_resource_type.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_producer_consumer.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_decode.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_min_address_fixed.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_max_address_fixed.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_granularity.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_min_address_range.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_max_address_range.attr); + sysfs_create_file(&amem->kobj, + &acpi_mem_attr_address_translation_offset.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_address_length.attr); + + return 0; +} static int acpi_memory_get_device_resources(struct acpi_memory_device *mem_device) @@ -97,6 +433,7 @@ acpi_memory_get_device_resources(struct return_VALUE(-EINVAL); resource = (struct acpi_resource *) buffer.pointer; + mem_device->resource = *resource; switch (resource->id) { case ACPI_RSTYPE_ADDRESS16: @@ -413,17 +750,26 @@ acpi_memory_device_add(struct acpi_devic /* Get the range from the _CRS */ result = acpi_memory_get_device_resources(mem_device); - if (result) { - kfree(mem_device); - return_VALUE(result); - } - + if (result) + goto errout; + + result = create_acpi_mem(mem_device, device); + if (result) + goto errout; + + result = fs_add_memory(&mem_device->amem); + if (result) + goto errout; + /* Set the device state */ mem_device->state = MEMORY_POWER_ON_STATE; printk(KERN_INFO "%s \n", acpi_device_name(device)); return_VALUE(result); +errout: + kfree(mem_device); + return_VALUE(result); } static int @@ -527,6 +873,10 @@ acpi_memory_device_init (void) ACPI_FUNCTION_TRACE("acpi_memory_device_init"); + result = acpi_mem_fs_init(); + if (result) + return_VALUE(-ENODEV); + result = acpi_bus_register_driver(&acpi_memory_device_driver); if (result < 0) @@ -540,6 +890,7 @@ acpi_memory_device_init (void) if (ACPI_FAILURE (status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed\n")); acpi_bus_unregister_driver(&acpi_memory_device_driver); + acpi_mem_fs_exit(); return_VALUE(-ENODEV); } @@ -567,6 +918,8 @@ acpi_memory_device_exit (void) acpi_bus_unregister_driver(&acpi_memory_device_driver); + acpi_mem_fs_exit(); + return_VOID; } _ ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <20040916194725.562b50f0.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org>]
* Re: [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object [not found] ` <20040916194725.562b50f0.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org> @ 2004-09-24 8:46 ` Keiichiro Tokunaga 0 siblings, 0 replies; 7+ messages in thread From: Keiichiro Tokunaga @ 2004-09-24 8:46 UTC (permalink / raw) To: naveen.b.s-ral2JQCrhuEAvxtiuMwx3w Cc: tokunaga.keiich-+CUm20s59erQFUHtdCDX3A, haveblue-r/Jw6+rmf7HQT0dZR+AlfA, matthew.e.tolentino-ral2JQCrhuEAvxtiuMwx3w, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, lhms-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f On Thu, 16 Sep 2004 19:47:25 +0900 Keiichiro Tokunaga wrote: > On Fri, 10 Sep 2004 23:02:00 +0900 Keiichiro Tokunaga wrote: > > On Thu, 09 Sep 2004 16:24:46 +0530 S, Naveen B wrote: > > > Attached is an ACPI based hot plug driver patch to support physical > > > memory hotplug. This driver supports physical hotplug operation on > > > memory, fields notifications from firmware and notifies the VM of the > > > affected memory ranges. The following patch is against kernel > > > 2.6.8.1-mm3, and works with the current memory hotplug VM patches > > > posted at: http://sprucegoose.sr71.net/patches. This patch has been > > > tested on real prototype hardware in the hot-add memory case. Hot > > > remove feature is tested in an emulated environment (by overriding > > > ACPI DSDT). > > > > > > Please review and consider for inclusion. > > > > I would like to add a feature into drivers/acpi/memory.c. > > > > Please see the patch below. This patch is for the kernel applying > > your patch. > > I have changed the patch to create directories and files in > /sys/firmware/acpi/memory/ from Dave's comments. The files are > to export the following stuffs of each ACPI memory object for the > first version. I have updated the patch to show just information in real need. o min_address_range o max_address_range This patch is still for 2.6.8.1-mm3. Naveen, if I need to update the patch, please let me know. Thanks, Keiichiro Tokunaga Name: sysfs_memory.patch Status: Tested on 2.6.8.1-mm3 Signed-off-by: Keiichiro Tokunaga <tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org> Description: This patch is to create directory '/sys/firmware/acpi/memory/', directories for each ACPI memory object, and files under it. These files are to export information of ACPI memory object. This version just creates two files an ACPI memory object, min_address_range and max_address_range. What it looks like is: /sys/firmware/acpi/memory/MEM0/min_address_range, where MEM0 is an ACPI memory object name. --- drivers/acpi/memory.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 194 insertions(+), 5 deletions(-) diff -puN drivers/acpi/memory.c~sysfs_memory drivers/acpi/memory.c --- linux-2.6.8.1-mm3/drivers/acpi/memory.c~sysfs_memory 2004-09-16 10:19:00.000000000 +0900 +++ linux-2.6.8.1-mm3-kei/drivers/acpi/memory.c 2004-09-24 17:31:13.000000000 +0900 @@ -69,6 +69,15 @@ static struct acpi_driver acpi_memory_de }, }; +struct acpi_mem { + struct acpi_mem_device_ops *ops; + void (*release)(struct acpi_mem *mdev); + struct kobject kobj; +}; + +#define to_acpi_mem(n) container_of(n, struct acpi_mem, kobj) +#define acpi_mem_to_dev(n) container_of(n, struct acpi_memory_device, amem) + struct acpi_memory_device { acpi_handle handle; unsigned int state; /* State of the memory device */ @@ -76,8 +85,171 @@ struct acpi_memory_device { unsigned short read_write_attribute;/* memory read/write attribute */ u64 start_addr; /* Memory Range start physical addr */ u64 end_addr; /* Memory Range end physical addr */ + struct acpi_resource resource; + struct acpi_mem amem; +}; + +/* + * /sys/firmware/acpi/memory/ + */ +struct acpi_mem_attribute { + struct attribute attr; + ssize_t (*show)(struct acpi_mem *, char *); + ssize_t (*store)(struct acpi_mem *, const char *, size_t); +}; + +#define to_acpi_mem_attr(n) container_of(n, struct acpi_mem_attribute, attr) + +static ssize_t acpi_mem_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + struct acpi_mem *amem = to_acpi_mem(kobj); + struct acpi_mem_attribute *attribute = to_acpi_mem_attr(attr); + return attribute->show ? attribute->show(amem, buf) : 0; +} + +static ssize_t acpi_mem_attr_store(struct kobject *kobj, + struct attribute *attr, const char *buf, + size_t len) +{ + struct acpi_mem *amem = to_acpi_mem(kobj); + struct acpi_mem_attribute *attribute = to_acpi_mem_attr(attr); + return attribute->store ? attribute->store(amem, buf, len) : 0; +} + +static struct sysfs_ops acpi_mem_sysfs_ops = { + .show = acpi_mem_attr_show, + .store = acpi_mem_attr_store, +}; + +static void acpi_mem_release(struct kobject *kobj) +{ + sysfs_remove_dir(kobj); + if (kobj->kset) { + down_write(&kobj->kset->subsys->rwsem); + list_del_init(&kobj->entry); + up_write(&kobj->kset->subsys->rwsem); + } +} + +static struct kobj_type acpi_mem_ktype = { + .sysfs_ops = &acpi_mem_sysfs_ops, + .release = &acpi_mem_release, }; +static decl_subsys_name(acpi_mem, memory, &acpi_mem_ktype, NULL); + +static int acpi_mem_register(struct acpi_mem *amem) +{ + return kobject_register(&amem->kobj); +} + +int create_acpi_mem(struct acpi_memory_device *mem_device, + struct acpi_device *device) +{ + int result; + struct acpi_mem *amem = &mem_device->amem; + + ACPI_FUNCTION_TRACE("create_acpi_mem"); + + memset(amem, 0, sizeof(struct acpi_mem)); + kobject_set_name(&amem->kobj, device->pnp.bus_id); + kobj_set_kset_s(amem, acpi_mem_subsys); + amem->kobj.parent = &acpi_mem_subsys.kset.kobj; + + result = acpi_mem_register(amem); + if (result) + goto end; +end: + return_VALUE(result); +} + +int acpi_mem_fs_init(void) +{ + int result; + extern struct subsystem acpi_subsys; + + ACPI_FUNCTION_TRACE("acpi_mem_fs_init"); + + acpi_mem_subsys.kset.kobj.parent = &acpi_subsys.kset.kobj; + result = subsystem_register(&acpi_mem_subsys); + + return_VALUE(result); +} + +void acpi_mem_fs_exit(void) +{ + ACPI_FUNCTION_TRACE("acpi_mem_fs_exit"); + + subsystem_unregister(&acpi_mem_subsys); + + return_VOID; +} + +static int get_address64(struct acpi_mem *amem, + struct acpi_resource_address64 *address64) +{ + struct acpi_memory_device *mem_device = acpi_mem_to_dev(amem); + struct acpi_resource *resource; + + if (!mem_device) + return -ENODEV; + + resource = &mem_device->resource; + + acpi_resource_to_address64(resource, address64); + + if (address64->resource_type != ACPI_MEMORY_RANGE) + return -EINVAL; + + return 0; +} + +static ssize_t min_address_range_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%llx\n", address64.min_address_range); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_min_address_range = { + .attr = {.name = "min_address_range", .mode = S_IFREG | S_IRUGO}, + .show = min_address_range_read_file, +}; + +static ssize_t max_address_range_read_file(struct acpi_mem *amem, char *buf) +{ + int result; + struct acpi_resource_address64 address64; + + result = get_address64(amem, &address64); + if (result) + return result; + + result = sprintf(buf, "0x%llx\n", address64.max_address_range); + + return result; +} + +static struct acpi_mem_attribute acpi_mem_attr_max_address_range = { + .attr = {.name = "max_address_range", .mode = S_IFREG | S_IRUGO}, + .show = max_address_range_read_file, +}; + +static int fs_add_memory(struct acpi_mem *amem) +{ + sysfs_create_file(&amem->kobj, &acpi_mem_attr_min_address_range.attr); + sysfs_create_file(&amem->kobj, &acpi_mem_attr_max_address_range.attr); + + return 0; +} static int acpi_memory_get_device_resources(struct acpi_memory_device *mem_device) @@ -97,6 +269,7 @@ acpi_memory_get_device_resources(struct return_VALUE(-EINVAL); resource = (struct acpi_resource *) buffer.pointer; + mem_device->resource = *resource; switch (resource->id) { case ACPI_RSTYPE_ADDRESS16: @@ -413,17 +586,26 @@ acpi_memory_device_add(struct acpi_devic /* Get the range from the _CRS */ result = acpi_memory_get_device_resources(mem_device); - if (result) { - kfree(mem_device); - return_VALUE(result); - } - + if (result) + goto errout; + + result = create_acpi_mem(mem_device, device); + if (result) + goto errout; + + result = fs_add_memory(&mem_device->amem); + if (result) + goto errout; + /* Set the device state */ mem_device->state = MEMORY_POWER_ON_STATE; printk(KERN_INFO "%s \n", acpi_device_name(device)); return_VALUE(result); +errout: + kfree(mem_device); + return_VALUE(result); } static int @@ -527,6 +709,10 @@ acpi_memory_device_init (void) ACPI_FUNCTION_TRACE("acpi_memory_device_init"); + result = acpi_mem_fs_init(); + if (result) + return_VALUE(-ENODEV); + result = acpi_bus_register_driver(&acpi_memory_device_driver); if (result < 0) @@ -540,6 +726,7 @@ acpi_memory_device_init (void) if (ACPI_FAILURE (status)) { ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed\n")); acpi_bus_unregister_driver(&acpi_memory_device_driver); + acpi_mem_fs_exit(); return_VALUE(-ENODEV); } @@ -567,6 +754,8 @@ acpi_memory_device_exit (void) acpi_bus_unregister_driver(&acpi_memory_device_driver); + acpi_mem_fs_exit(); + return_VOID; } _ ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-09-24 8:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-16 14:07 [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object Tolentino, Matthew E
[not found] ` <D36CE1FCEFD3524B81CA12C6FE5BCAB007B6FA60-oCDej+MBycNZtRGVdHMbwrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2004-09-16 16:00 ` Keiichiro Tokunaga
2004-09-16 16:46 ` Keiichiro Tokunaga
[not found] ` <20040917014611.000055db.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2004-09-16 17:55 ` Dave Hansen
2004-09-17 1:43 ` Keiichiro Tokunaga
-- strict thread matches above, loose matches on Subject: below --
2004-09-09 10:54 [PATCH] ACPI based Memory Hotplug Driver Patch S, Naveen B
2004-09-10 14:02 ` Keiichiro Tokunaga
[not found] ` <20040910230200.73eb0374.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2004-09-16 10:47 ` [PATCH] /sys/firmware/acpi/memory/ for showing info of ACPI memory object Keiichiro Tokunaga
[not found] ` <20040916194725.562b50f0.tokunaga.keiich-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2004-09-24 8:46 ` Keiichiro Tokunaga
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox