Skip to contentSkip to conversation

drm/ast: use managed devres functions

PATCH Superseded Philipp Stanner 2 participants 2 messages Oct 30, 2023 – Nov 3, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/ast: use managed devres functions

Currently, tha ast-driver just maps the PCI-dev's regions with pcim_iomap(). It does not actually reserve the regions exclusively with, e.g., pci_request_regions().

Replace the calls to pcim_iomap() with ones to pcim_iomap_regions() to reserve and map the regions simultaneously.

---
¡Hola!
I picked up the memory-region-request-task from the DRM-TODO-List [1] and began with this driver.

Please have a first look. I wasn't entirely sure about -ENOMEM... for example, as far as my understanding goes, it should not be able to fail anyways in the second call.

I don't have the server-hardware, thus, can't test it on a physical machine.

Please tell me what you think.

P.

[1] https://dri.freedesktop.org/docs/drm/gpu/todo.html#request-memory-regions-in-all-drivers

---
 drivers/gpu/drm/ast/ast_main.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/ast/ast_main.c +11 -4
index dae365ed3969..1004c6628938 100644
@@ -444,9 +444,13 @@ struct ast_device *ast_device_create(const struct drm_driver *drv,
 	if (ret)
 		return ERR_PTR(ret);
 
-	ast->regs = pcim_iomap(pdev, 1, 0);
+	ret = pcim_iomap_regions(pdev, BIT(1), 0);
+	if (ret)
+		return ERR_PTR(ret);
+
+	ast->regs = pcim_iomap_table(pdev)[1];
 	if (!ast->regs)
-		return ERR_PTR(-EIO);
+		return ERR_PTR(-ENOMEM);
 
 	/*
 	 * After AST2500, MMIO is enabled by default, and it should be adopted
@@ -461,9 +465,12 @@ struct ast_device *ast_device_create(const struct drm_driver *drv,
 
 	/* "map" IO regs if the above hasn't done so already */
 	if (!ast->ioregs) {
-		ast->ioregs = pcim_iomap(pdev, 2, 0);
+		ret = pcim_iomap_regions(pdev, BIT(2), 0);
+		if (ret)
+			return ERR_PTR(ret);
+		ast->ioregs = pcim_iomap_table(pdev)[2];
 		if (!ast->ioregs)
-			return ERR_PTR(-EIO);
+			return ERR_PTR(-ENOMEM);
 	}
 
 	if (!ast_is_vga_enabled(dev)) {
Signature · 1 line
2.41.0
#1 lore raw
Quoted 9 lines · Philipp Stanner

Currently, tha ast-driver just maps the PCI-dev's regions with pcim_iomap(). It does not actually reserve the regions exclusively with, e.g., pci_request_regions().

Replace the calls to pcim_iomap() with ones to pcim_iomap_regions() to reserve and map the regions simultaneously.

Quoted 8 lines

---
¡Hola!
I picked up the memory-region-request-task from the DRM-TODO-List [1] and began with this driver.

Please have a first look. I wasn't entirely sure about -ENOMEM... for example, as far as my understanding goes, it should not be able to fail anyways in the second call.

Yes, you can remove these checks, other drivers don't do it:
https://elixir.bootlin.com/linux/latest/source/arch/x86/platform/intel-mid/pwr.c#L372

Quoted 3 lines

I don't have the server-hardware, thus, can't test it on a physical machine.

I've done a quick check on an AST2600, and it works.

Quoted 2 lines

Please tell me what you think.

That's a good patch, thanks for your contribution.

I'll wait for Thomas review, and with the checks removed, I can help push it to drm-misc-next.

Quoted 15 lines

P.

[1] https://dri.freedesktop.org/docs/drm/gpu/todo.html#request-memory-regions-in-all-drivers

---
  drivers/gpu/drm/ast/ast_main.c | 15 +++++++++++----
  1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/ast/ast_main.c +0 -0
index dae365ed3969..1004c6628938 100644
@@ -444,9 +444,13 @@ struct ast_device *ast_device_create(const struct drm_driver *drv,
  	if (ret)
  		return ERR_PTR(ret);

drivers/gpu/drm/ast/ast_main.c struct ast_device *ast_device_create(const struct drm_driver *drv, · line 453

Quoted 10 lines
drivers/gpu/drm/ast/ast_main.c +6 -2
 
-	ast->regs = pcim_iomap(pdev, 1, 0);
+	ret = pcim_iomap_regions(pdev, BIT(1), 0);
+	if (ret)
+		return ERR_PTR(ret);
+
+	ast->regs = pcim_iomap_table(pdev)[1];
  	if (!ast->regs)
-		return ERR_PTR(-EIO);
+		return ERR_PTR(-ENOMEM);

You can remove this check.

Quoted 5 lines
drivers/gpu/drm/ast/ast_main.c +0 -0
  	/*
  	 * After AST2500, MMIO is enabled by default, and it should be adopted
@@ -461,9 +465,12 @@ struct ast_device *ast_device_create(const struct drm_driver *drv,
 

drivers/gpu/drm/ast/ast_main.c struct ast_device *ast_device_create(const struct drm_driver *drv, · line 473

Quoted 10 lines
drivers/gpu/drm/ast/ast_main.c +5 -2
  	/* "map" IO regs if the above hasn't done so already */
  	if (!ast->ioregs) {
-		ast->ioregs = pcim_iomap(pdev, 2, 0);
+		ret = pcim_iomap_regions(pdev, BIT(2), 0);
+		if (ret)
+			return ERR_PTR(ret);
+		ast->ioregs = pcim_iomap_table(pdev)[2];
  		if (!ast->ioregs)
-			return ERR_PTR(-EIO);
+			return ERR_PTR(-ENOMEM);

you can remove this check too.

Quoted 3 lines
drivers/gpu/drm/ast/ast_main.c +0 -0
  	}
 
  	if (!ast_is_vga_enabled(dev)) {
Signature · 1 line
Jocelyn