mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] drm: mali-dp: Check hw version matches device-tree
@ 2017-01-23 13:46 Mihail Atanassov
  2017-01-23 13:46 ` [PATCH 2/2] drm: mali-dp: Check for sufficient address space Mihail Atanassov
  0 siblings, 1 reply; 3+ messages in thread
From: Mihail Atanassov @ 2017-01-23 13:46 UTC (permalink / raw)
  To: DRI devel; +Cc: Brian Starkey, Liviu Dudau, LKML, nd

Refuse to bind if the device-tree compatible string
lists a different hardware version.

Reviewed-by: Brian Starkey <brian.starkey@arm.com>
Signed-off-by: Mihail Atanassov <mihail.atanassov@arm.com>
---
 A couple of small improvements to driver-to-hardware binding.

 drivers/gpu/drm/arm/malidp_drv.c  | 52 +++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/arm/malidp_regs.h |  2 ++
 2 files changed, 54 insertions(+)

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index 32f746e..43238f4 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -256,6 +256,46 @@ static void malidp_lastclose(struct drm_device *drm)
 };
 MODULE_DEVICE_TABLE(of, malidp_drm_of_match);
 
+static bool malidp_is_compatible_hw_id(struct malidp_hw_device *hwdev,
+				       const struct of_device_id *dev_id)
+{
+	u32 core_id;
+	const char *compatstr_dp500 = "arm,mali-dp500";
+	bool is_dp500;
+	bool dt_is_dp500;
+
+	/*
+	 * The DP500 CORE_ID register is in a different location, so check it
+	 * first. If the product id field matches, then this is DP500, otherwise
+	 * check the DP550/650 CORE_ID register.
+	 */
+	core_id = malidp_hw_read(hwdev, MALIDP500_DC_BASE + MALIDP_DE_CORE_ID);
+	/* Offset 0x18 will never read 0x500 on products other than DP500. */
+	is_dp500 = (MALIDP_PRODUCT_ID(core_id) == 0x500);
+	dt_is_dp500 = strnstr(dev_id->compatible, compatstr_dp500,
+			      sizeof(dev_id->compatible)) != NULL;
+	if (is_dp500 != dt_is_dp500) {
+		DRM_ERROR("Device-tree expects %s, but hardware %s DP500.\n",
+			  dev_id->compatible, is_dp500 ? "is" : "is not");
+		return false;
+	} else if (!dt_is_dp500) {
+		u16 product_id;
+		char buf[32];
+
+		core_id = malidp_hw_read(hwdev,
+					 MALIDP550_DC_BASE + MALIDP_DE_CORE_ID);
+		product_id = MALIDP_PRODUCT_ID(core_id);
+		snprintf(buf, sizeof(buf), "arm,mali-dp%X", product_id);
+		if (!strnstr(dev_id->compatible, buf,
+			     sizeof(dev_id->compatible))) {
+			DRM_ERROR("Device-tree expects %s, but hardware is DP%03X.\n",
+				  dev_id->compatible, product_id);
+			return false;
+		}
+	}
+	return true;
+}
+
 #define MAX_OUTPUT_CHANNELS	3
 
 static int malidp_bind(struct device *dev)
@@ -266,6 +306,7 @@ static int malidp_bind(struct device *dev)
 	struct malidp_drm *malidp;
 	struct malidp_hw_device *hwdev;
 	struct platform_device *pdev = to_platform_device(dev);
+	struct of_device_id const *dev_id;
 	/* number of lines for the R, G and B output */
 	u8 output_width[MAX_OUTPUT_CHANNELS];
 	int ret = 0, i;
@@ -329,6 +370,17 @@ static int malidp_bind(struct device *dev)
 	clk_prepare_enable(hwdev->aclk);
 	clk_prepare_enable(hwdev->mclk);
 
+	dev_id = of_match_device(malidp_drm_of_match, dev);
+	if (!dev_id) {
+		ret = -EINVAL;
+		goto query_hw_fail;
+	}
+
+	if (!malidp_is_compatible_hw_id(hwdev, dev_id)) {
+		ret = -EINVAL;
+		goto query_hw_fail;
+	}
+
 	ret = hwdev->query_hw(hwdev);
 	if (ret) {
 		DRM_ERROR("Invalid HW configuration\n");
diff --git a/drivers/gpu/drm/arm/malidp_regs.h b/drivers/gpu/drm/arm/malidp_regs.h
index 73fecb3..7a89997 100644
--- a/drivers/gpu/drm/arm/malidp_regs.h
+++ b/drivers/gpu/drm/arm/malidp_regs.h
@@ -92,6 +92,8 @@
 #define MALIDP_DE_H_ACTIVE(x)		(((x) & 0x1fff) << 0)
 #define MALIDP_DE_V_ACTIVE(x)		(((x) & 0x1fff) << 16)
 
+#define MALIDP_PRODUCT_ID(__core_id) ((u32)(__core_id) >> 16)
+
 /* register offsets and bits specific to DP500 */
 #define MALIDP500_DC_BASE		0x00000
 #define MALIDP500_DC_CONTROL		0x0000c
-- 
1.8.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] drm: mali-dp: Check for sufficient address space
  2017-01-23 13:46 [PATCH 1/2] drm: mali-dp: Check hw version matches device-tree Mihail Atanassov
@ 2017-01-23 13:46 ` Mihail Atanassov
  2017-01-23 17:01   ` Liviu Dudau
  0 siblings, 1 reply; 3+ messages in thread
From: Mihail Atanassov @ 2017-01-23 13:46 UTC (permalink / raw)
  To: DRI devel; +Cc: Brian Starkey, Liviu Dudau, LKML, nd

If the device-tree 'reg' node doesn't reserve enough
space for the DP, fail to bind.

Reviewed-by: Brian Starkey <brian.starkey@arm.com>
Signed-off-by: Mihail Atanassov <mihail.atanassov@arm.com>
---
 drivers/gpu/drm/arm/malidp_drv.c  | 20 ++++++++++++++++++++
 drivers/gpu/drm/arm/malidp_regs.h |  2 ++
 2 files changed, 22 insertions(+)

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index 43238f4..66622a5 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -296,6 +296,20 @@ static bool malidp_is_compatible_hw_id(struct malidp_hw_device *hwdev,
 	return true;
 }
 
+static bool malidp_is_sufficient_address_space(const struct resource *res,
+					       const struct of_device_id *dev_id)
+{
+	resource_size_t res_size = resource_size(res);
+	const char *compatstr_dp500 = "arm,mali-dp500";
+
+	if (!strnstr(dev_id->compatible, compatstr_dp500,
+		     sizeof(dev_id->compatible)))
+		return res_size >= MALIDP550_ADDR_SPACE_SIZE;
+	else if (res_size < MALIDP500_ADDR_SPACE_SIZE)
+		return false;
+	return true;
+}
+
 #define MAX_OUTPUT_CHANNELS	3
 
 static int malidp_bind(struct device *dev)
@@ -376,6 +390,12 @@ static int malidp_bind(struct device *dev)
 		goto query_hw_fail;
 	}
 
+	if (!malidp_is_sufficient_address_space(res, dev_id)) {
+		DRM_ERROR("Insufficient address space in device-tree.\n");
+		ret = -EINVAL;
+		goto query_hw_fail;
+	}
+
 	if (!malidp_is_compatible_hw_id(hwdev, dev_id)) {
 		ret = -EINVAL;
 		goto query_hw_fail;
diff --git a/drivers/gpu/drm/arm/malidp_regs.h b/drivers/gpu/drm/arm/malidp_regs.h
index 7a89997..e0651d2 100644
--- a/drivers/gpu/drm/arm/malidp_regs.h
+++ b/drivers/gpu/drm/arm/malidp_regs.h
@@ -95,6 +95,7 @@
 #define MALIDP_PRODUCT_ID(__core_id) ((u32)(__core_id) >> 16)
 
 /* register offsets and bits specific to DP500 */
+#define MALIDP500_ADDR_SPACE_SIZE	0x01000
 #define MALIDP500_DC_BASE		0x00000
 #define MALIDP500_DC_CONTROL		0x0000c
 #define   MALIDP500_DC_CONFIG_REQ	(1 << 17)
@@ -127,6 +128,7 @@
 #define MALIDP500_CONFIG_ID		0x00fd4
 
 /* register offsets and bits specific to DP550/DP650 */
+#define MALIDP550_ADDR_SPACE_SIZE	0x10000
 #define MALIDP550_DE_CONTROL		0x00010
 #define MALIDP550_DE_LINE_COUNTER	0x00014
 #define MALIDP550_DE_AXI_CONTROL	0x00018
-- 
1.8.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] drm: mali-dp: Check for sufficient address space
  2017-01-23 13:46 ` [PATCH 2/2] drm: mali-dp: Check for sufficient address space Mihail Atanassov
@ 2017-01-23 17:01   ` Liviu Dudau
  0 siblings, 0 replies; 3+ messages in thread
From: Liviu Dudau @ 2017-01-23 17:01 UTC (permalink / raw)
  To: Mihail Atanassov; +Cc: DRI devel, Brian Starkey, LKML, nd

On Mon, Jan 23, 2017 at 01:46:42PM +0000, Mihail Atanassov wrote:
> If the device-tree 'reg' node doesn't reserve enough
> space for the DP, fail to bind.
> 
> Reviewed-by: Brian Starkey <brian.starkey@arm.com>
> Signed-off-by: Mihail Atanassov <mihail.atanassov@arm.com>
> ---
>  drivers/gpu/drm/arm/malidp_drv.c  | 20 ++++++++++++++++++++
>  drivers/gpu/drm/arm/malidp_regs.h |  2 ++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
> index 43238f4..66622a5 100644
> --- a/drivers/gpu/drm/arm/malidp_drv.c
> +++ b/drivers/gpu/drm/arm/malidp_drv.c
> @@ -296,6 +296,20 @@ static bool malidp_is_compatible_hw_id(struct malidp_hw_device *hwdev,
>  	return true;
>  }
>  
> +static bool malidp_is_sufficient_address_space(const struct resource *res,
> +					       const struct of_device_id *dev_id)
> +{
> +	resource_size_t res_size = resource_size(res);
> +	const char *compatstr_dp500 = "arm,mali-dp500";
> +
> +	if (!strnstr(dev_id->compatible, compatstr_dp500,
> +		     sizeof(dev_id->compatible)))
> +		return res_size >= MALIDP550_ADDR_SPACE_SIZE;
> +	else if (res_size < MALIDP500_ADDR_SPACE_SIZE)
> +		return false;
> +	return true;
> +}
> +
>  #define MAX_OUTPUT_CHANNELS	3
>  
>  static int malidp_bind(struct device *dev)
> @@ -376,6 +390,12 @@ static int malidp_bind(struct device *dev)
>  		goto query_hw_fail;
>  	}
>  
> +	if (!malidp_is_sufficient_address_space(res, dev_id)) {
> +		DRM_ERROR("Insufficient address space in device-tree.\n");
> +		ret = -EINVAL;
> +		goto query_hw_fail;
> +	}
> +

Small nitpick: s/malidp_is_sufficient_address_space/malidp_has_sufficient_address_space/g

Otherwise, for the whole series:

Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>


>  	if (!malidp_is_compatible_hw_id(hwdev, dev_id)) {
>  		ret = -EINVAL;
>  		goto query_hw_fail;
> diff --git a/drivers/gpu/drm/arm/malidp_regs.h b/drivers/gpu/drm/arm/malidp_regs.h
> index 7a89997..e0651d2 100644
> --- a/drivers/gpu/drm/arm/malidp_regs.h
> +++ b/drivers/gpu/drm/arm/malidp_regs.h
> @@ -95,6 +95,7 @@
>  #define MALIDP_PRODUCT_ID(__core_id) ((u32)(__core_id) >> 16)
>  
>  /* register offsets and bits specific to DP500 */
> +#define MALIDP500_ADDR_SPACE_SIZE	0x01000
>  #define MALIDP500_DC_BASE		0x00000
>  #define MALIDP500_DC_CONTROL		0x0000c
>  #define   MALIDP500_DC_CONFIG_REQ	(1 << 17)
> @@ -127,6 +128,7 @@
>  #define MALIDP500_CONFIG_ID		0x00fd4
>  
>  /* register offsets and bits specific to DP550/DP650 */
> +#define MALIDP550_ADDR_SPACE_SIZE	0x10000
>  #define MALIDP550_DE_CONTROL		0x00010
>  #define MALIDP550_DE_LINE_COUNTER	0x00014
>  #define MALIDP550_DE_AXI_CONTROL	0x00018
> -- 
> 1.8.3
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-23 17:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-23 13:46 [PATCH 1/2] drm: mali-dp: Check hw version matches device-tree Mihail Atanassov
2017-01-23 13:46 ` [PATCH 2/2] drm: mali-dp: Check for sufficient address space Mihail Atanassov
2017-01-23 17:01   ` Liviu Dudau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®