From patchwork Wed Apr 8 15:32:28 2015
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Przemyslaw Marczak
X-Patchwork-Id: 459327
X-Patchwork-Delegate: sjg@chromium.org
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Received: from theia.denx.de (theia.denx.de [85.214.87.163])
by ozlabs.org (Postfix) with ESMTP id 1D15014011D
for ;
Thu, 9 Apr 2015 01:33:05 +1000 (AEST)
Received: from localhost (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id 639BFA7459;
Wed, 8 Apr 2015 17:33:00 +0200 (CEST)
Received: from theia.denx.de ([127.0.0.1])
by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 2RXlTI4fbxit; Wed, 8 Apr 2015 17:33:00 +0200 (CEST)
Received: from theia.denx.de (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id 49002A745C;
Wed, 8 Apr 2015 17:32:50 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id B3399A741C
for ; Wed, 8 Apr 2015 17:32:42 +0200 (CEST)
Received: from theia.denx.de ([127.0.0.1])
by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 3G59Gz5Grbtt for ;
Wed, 8 Apr 2015 17:32:42 +0200 (CEST)
X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5
NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested)
Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com
[210.118.77.11]) by theia.denx.de (Postfix) with ESMTPS id 29DA2A7421
for ; Wed, 8 Apr 2015 17:32:38 +0200 (CEST)
Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245])
by mailout1.w1.samsung.com
(Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit
(built Nov
17 2011)) with ESMTP id <0NMH004SEVD51G40@mailout1.w1.samsung.com>
for u-boot@lists.denx.de; Wed, 08 Apr 2015 16:36:41 +0100 (BST)
X-AuditID: cbfec7f5-b7f1e6d00000617c-cf-5525496717f6
Received: from eusync4.samsung.com ( [203.254.199.214])
by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 58.52.24956.76945255;
Wed, 08 Apr 2015 16:29:43 +0100 (BST)
Received: from AMDC1186.digital.local ([106.116.147.185])
by eusync4.samsung.com
(Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit
(built Nov
17 2011)) with ESMTPA id <0NMH001UYV68ZK40@eusync4.samsung.com>; Wed,
08 Apr 2015 16:32:36 +0100 (BST)
From: Przemyslaw Marczak
To: u-boot@lists.denx.de
Date: Wed, 08 Apr 2015 17:32:28 +0200
Message-id: <1428507149-19232-3-git-send-email-p.marczak@samsung.com>
X-Mailer: git-send-email 1.9.1
In-reply-to: <1428507149-19232-1-git-send-email-p.marczak@samsung.com>
References: <1428498114-7015-1-git-send-email-p.marczak@samsung.com>
<1428507149-19232-1-git-send-email-p.marczak@samsung.com>
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFnrJJMWRmVeSWpSXmKPExsVy+t/xa7rpnqqhBr9miFi8ebiZ0WLH5Rss
Ft+2bGO0eLu3k91i773PjA6sHrMbLrJ4nL2zg9Gjb8sqRo8T07+zBLBEcdmkpOZklqUW6dsl
cGUcuXKJpWCaQcWq3q3MDYx/1boYOTkkBEwkdv06zwJhi0lcuLeerYuRi0NIYCmjxOT1k9gh
nD4miderG5hBqtgEDCT2XDoDZosISEj86r/KCFLELLCWUWLarD52kISwQJjE9X3bmUBsFgFV
iebJf4DGcnDwCrhKrDxcALFNTuLkscmsIDangJvE0esvoJY1MEo8eHKFaQIj7wJGhlWMoqml
yQXFSem5RnrFibnFpXnpesn5uZsYIcHzdQfj0mNWhxgFOBiVeHg9rqiECrEmlhVX5h5ilOBg
VhLhrfJQDRXiTUmsrEotyo8vKs1JLT7EyMTBKdXAKLtXvzFjzqlYj5+bjI43Hn6/7cP5Gckz
Y98LORmGrv7SfOlVrVmOgvh9P/fCZyvm+Z0LZM1adkZCLcbuMwt/LnNJtYBCXeW/c06LH6hL
znzXZMiyttla+JDuuyf8ZWFqCueFftx7vMROJiR4Lu/MgsIlr14l2Jl1fIl2utl1qUBC5+B9
D1M+JZbijERDLeai4kQAV0I4A/wBAAA=
Cc: Przemyslaw Marczak
Subject: [U-Boot] [PATCH V2 2/3] dm: core: Extend struct udevice by
'.uclass_platdata' field.
X-BeenThere: u-boot@lists.denx.de
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: U-Boot discussion
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
MIME-Version: 1.0
Errors-To: u-boot-bounces@lists.denx.de
Sender: "U-Boot"
This commit adds 'uclass_platdata' field to 'struct udevice', which
can be automatically allocated at bind. The allocation size is defined
in 'struct uclass_driver' as 'per_device_platdata_auto_alloc_size'.
New device's flag is added: DM_FLAG_ALLOC_UCLASS_PDATA, which is used
for memory freeing at device unbind method.
As for other udevice's fields, a complementary function is added:
- dev_get_uclass_platdata()
Signed-off-by: Przemyslaw Marczak
Cc: Simon Glass
---
Changes V2:
- none
---
drivers/core/device-remove.c | 4 ++++
drivers/core/device.c | 33 +++++++++++++++++++++++++++++----
include/dm/device.h | 17 ++++++++++++++++-
include/dm/uclass.h | 4 ++++
4 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index 7fee1c0..6a16b4f 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -92,6 +92,10 @@ int device_unbind(struct udevice *dev)
free(dev->platdata);
dev->platdata = NULL;
}
+ if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) {
+ free(dev->uclass_platdata);
+ dev->uclass_platdata = NULL;
+ }
if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) {
free(dev->parent_platdata);
dev->parent_platdata = NULL;
diff --git a/drivers/core/device.c b/drivers/core/device.c
index ccaa99c..80eb55b 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -30,7 +30,7 @@ int device_bind(struct udevice *parent, const struct driver *drv,
{
struct udevice *dev;
struct uclass *uc;
- int ret = 0;
+ int size, ret = 0;
*devp = NULL;
if (!name)
@@ -79,9 +79,19 @@ int device_bind(struct udevice *parent, const struct driver *drv,
goto fail_alloc1;
}
}
- if (parent) {
- int size = parent->driver->per_child_platdata_auto_alloc_size;
+ size = uc->uc_drv->per_device_platdata_auto_alloc_size;
+ if (size) {
+ dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA;
+ dev->uclass_platdata = calloc(1, size);
+ if (!dev->uclass_platdata) {
+ ret = -ENOMEM;
+ goto fail_alloc2;
+ }
+ }
+
+ if (parent) {
+ size = parent->driver->per_child_platdata_auto_alloc_size;
if (!size) {
size = parent->uclass->uc_drv->
per_child_platdata_auto_alloc_size;
@@ -91,7 +101,7 @@ int device_bind(struct udevice *parent, const struct driver *drv,
dev->parent_platdata = calloc(1, size);
if (!dev->parent_platdata) {
ret = -ENOMEM;
- goto fail_alloc2;
+ goto fail_alloc3;
}
}
}
@@ -139,6 +149,11 @@ fail_uclass_bind:
free(dev->parent_platdata);
dev->parent_platdata = NULL;
}
+fail_alloc3:
+ if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) {
+ free(dev->uclass_platdata);
+ dev->uclass_platdata = NULL;
+ }
fail_alloc2:
if (dev->flags & DM_FLAG_ALLOC_PDATA) {
free(dev->platdata);
@@ -314,6 +329,16 @@ void *dev_get_parent_platdata(struct udevice *dev)
return dev->parent_platdata;
}
+void *dev_get_uclass_platdata(struct udevice *dev)
+{
+ if (!dev) {
+ dm_warn("%s: null device", __func__);
+ return NULL;
+ }
+
+ return dev->uclass_platdata;
+}
+
void *dev_get_priv(struct udevice *dev)
{
if (!dev) {
diff --git a/include/dm/device.h b/include/dm/device.h
index c11342c..ad002fe 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -30,8 +30,11 @@ struct driver_info;
/* DM is responsible for allocating and freeing parent_platdata */
#define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3)
+/* DM is responsible for allocating and freeing uclass_platdata */
+#define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4)
+
/* Allocate driver private data on a DMA boundary */
-#define DM_FLAG_ALLOC_PRIV_DMA (1 << 4)
+#define DM_FLAG_ALLOC_PRIV_DMA (1 << 5)
/**
* struct udevice - An instance of a driver
@@ -54,6 +57,7 @@ struct driver_info;
* @name: Name of device, typically the FDT node name
* @platdata: Configuration data for this device
* @parent_platdata: The parent bus's configuration data for this device
+ * @uclass_platdata: The uclass's configuration data for this device
* @of_offset: Device tree node offset for this device (- for none)
* @driver_data: Driver data word for the entry that matched this device with
* its driver
@@ -75,6 +79,7 @@ struct udevice {
const char *name;
void *platdata;
void *parent_platdata;
+ void *uclass_platdata;
int of_offset;
ulong driver_data;
struct udevice *parent;
@@ -210,6 +215,16 @@ void *dev_get_platdata(struct udevice *dev);
void *dev_get_parent_platdata(struct udevice *dev);
/**
+ * dev_get_uclass_platdata() - Get the uclass platform data for a device
+ *
+ * This checks that dev is not NULL, but no other checks for now
+ *
+ * @dev Device to check
+ * @return uclass's platform data, or NULL if none
+ */
+void *dev_get_uclass_platdata(struct udevice *dev);
+
+/**
* dev_get_parentdata() - Get the parent data for a device
*
* The parent data is data stored in the device but owned by the parent.
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index d57d804..b271472 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -65,6 +65,9 @@ struct udevice;
* @per_device_auto_alloc_size: Each device can hold private data owned
* by the uclass. If required this will be automatically allocated if this
* value is non-zero.
+ * @per_device_platdata_auto_alloc_size: Each device can hold platform data
+ * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero,
+ * then this will be automatically allocated.
* @per_child_auto_alloc_size: Each child device (of a parent in this
* uclass) can hold parent data for the device/uclass. This value is only
* used as a falback if this member is 0 in the driver.
@@ -90,6 +93,7 @@ struct uclass_driver {
int (*destroy)(struct uclass *class);
int priv_auto_alloc_size;
int per_device_auto_alloc_size;
+ int per_device_platdata_auto_alloc_size;
int per_child_auto_alloc_size;
int per_child_platdata_auto_alloc_size;
const void *ops;