Skip to contentSkip to conversation

ata/pata_buddha: Probe via modalias instead of initcall

PATCH Superseded Max Staudt 4 participants 7 messages Jul 25, 2019 – Jul 29, 2019 libata

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Max Staudt

author
#0 lore raw

PATCH v2 1/1 ata/pata_buddha: Probe via modalias instead of initcall

Up until now, the pata_buddha driver would only check for cards on initcall time. Now, the kernel will call its probe function as soon as a compatible card is detected.

Device removal remains unimplemented. A WARN_ONCE() serves as a reminder.

v2: Rename 'zdev' to 'z' to make the patch easy to analyse with

    git diff --ignore-space-change
---
 drivers/ata/pata_buddha.c | 240 ++++++++++++++++++++++++++++------------------
 1 file changed, 146 insertions(+), 94 deletions(-)
drivers/ata/pata_buddha.c +146 -94
index 11a8044ff..76804a4c1 100644
@@ -19,6 +19,7 @@
 #include <linux/libata.h>
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/types.h>
 #include <linux/zorro.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_host.h>
@@ -29,7 +30,7 @@
 #include <asm/setup.h>
 
 #define DRV_NAME "pata_buddha"
-#define DRV_VERSION "0.1.0"
+#define DRV_VERSION "0.1.1"
 
 #define BUDDHA_BASE1	0x800
 #define BUDDHA_BASE2	0xa00
@@ -47,11 +48,11 @@ enum {
 	BOARD_XSURF
 };
 
-static unsigned int buddha_bases[3] __initdata = {
+static unsigned int buddha_bases[3] = {
 	BUDDHA_BASE1, BUDDHA_BASE2, BUDDHA_BASE3
 };
 
-static unsigned int xsurf_bases[2] __initdata = {
+static unsigned int xsurf_bases[2] = {
 	XSURF_BASE1, XSURF_BASE2
 };
 
@@ -145,111 +146,162 @@ static struct ata_port_operations pata_xsurf_ops = {
 	.set_mode	= pata_buddha_set_mode,
 };
 
-static int __init pata_buddha_init_one(void)
+static int pata_buddha_probe(struct zorro_dev *z,
+			     const struct zorro_device_id *ent)
 {
-	struct zorro_dev *z = NULL;
-
-	while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
-		static const char *board_name[]
-			= { "Buddha", "Catweasel", "X-Surf" };
-		struct ata_host *host;
-		void __iomem *buddha_board;
-		unsigned long board;
-		unsigned int type, nr_ports = 2;
-		int i;
-
-		if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) {
-			type = BOARD_BUDDHA;
-		} else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL) {
-			type = BOARD_CATWEASEL;
-			nr_ports++;
-		} else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF) {
-			type = BOARD_XSURF;
-		} else
-			continue;
-
-		dev_info(&z->dev, "%s IDE controller\n", board_name[type]);
-
-		board = z->resource.start;
+	static const char * const board_name[]
+		= { "Buddha", "Catweasel", "X-Surf" };
+	struct ata_host *host;
+	void __iomem *buddha_board;
+	unsigned long board;
+	unsigned int type, nr_ports = 2;
+	int i;
+
+	switch (z->id) {
+	case ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA:
+	default:
+		type = BOARD_BUDDHA;
+		break;
+	case ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL:
+		type = BOARD_CATWEASEL;
+		nr_ports++;
+		break;
+	case ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF:
+		type = BOARD_XSURF;
+		break;
+	}
+
+	dev_info(&z->dev, "%s IDE controller\n", board_name[type]);
+
+	board = z->resource.start;
+
+	if (type != BOARD_XSURF) {
+		if (!devm_request_mem_region(&z->dev,
+					     board + BUDDHA_BASE1,
+					     0x800, DRV_NAME))
+			return -ENXIO;
+	} else {
+		if (!devm_request_mem_region(&z->dev,
+					     board + XSURF_BASE1,
+					     0x1000, DRV_NAME))
+			return -ENXIO;
+		if (!devm_request_mem_region(&z->dev,
+					     board + XSURF_BASE2,
+					     0x1000, DRV_NAME)) {
+			devm_release_mem_region(&z->dev,
+						board + XSURF_BASE1,
+						0x1000);
+			return -ENXIO;
+		}
+	}
+
+	/* allocate host */
+	host = ata_host_alloc(&z->dev, nr_ports);
+	if (!host)
+		goto err_ata_host_alloc;
+
+	buddha_board = ZTWO_VADDR(board);
+
+	/* enable the board IRQ on Buddha/Catweasel */
+	if (type != BOARD_XSURF)
+		z_writeb(0, buddha_board + BUDDHA_IRQ_MR);
+
+	for (i = 0; i < nr_ports; i++) {
+		struct ata_port *ap = host->ports[i];
+		void __iomem *base, *irqport;
+		unsigned long ctl = 0;
 
 		if (type != BOARD_XSURF) {
-			if (!devm_request_mem_region(&z->dev,
-						     board + BUDDHA_BASE1,
-						     0x800, DRV_NAME))
-				continue;
+			ap->ops = &pata_buddha_ops;
+			base = buddha_board + buddha_bases[i];
+			ctl = BUDDHA_CONTROL;
+			irqport = buddha_board + BUDDHA_IRQ + i * 0x40;
 		} else {
-			if (!devm_request_mem_region(&z->dev,
-						     board + XSURF_BASE1,
-						     0x1000, DRV_NAME))
-				continue;
-			if (!devm_request_mem_region(&z->dev,
-						     board + XSURF_BASE2,
-						     0x1000, DRV_NAME))
-				continue;
+			ap->ops = &pata_xsurf_ops;
+			base = buddha_board + xsurf_bases[i];
+			/* X-Surf has no CS1* (Control/AltStat) */
+			irqport = buddha_board + XSURF_IRQ;
 		}
 
-		/* allocate host */
-		host = ata_host_alloc(&z->dev, nr_ports);
-		if (!host)
-			continue;
-
-		buddha_board = ZTWO_VADDR(board);
-
-		/* enable the board IRQ on Buddha/Catweasel */
-		if (type != BOARD_XSURF)
-			z_writeb(0, buddha_board + BUDDHA_IRQ_MR);
-
-		for (i = 0; i < nr_ports; i++) {
-			struct ata_port *ap = host->ports[i];
-			void __iomem *base, *irqport;
-			unsigned long ctl = 0;
-
-			if (type != BOARD_XSURF) {
-				ap->ops = &pata_buddha_ops;
-				base = buddha_board + buddha_bases[i];
-				ctl = BUDDHA_CONTROL;
-				irqport = buddha_board + BUDDHA_IRQ + i * 0x40;
-			} else {
-				ap->ops = &pata_xsurf_ops;
-				base = buddha_board + xsurf_bases[i];
-				/* X-Surf has no CS1* (Control/AltStat) */
-				irqport = buddha_board + XSURF_IRQ;
-			}
-
-			ap->pio_mask = ATA_PIO4;
-			ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
-
-			ap->ioaddr.data_addr		= base;
-			ap->ioaddr.error_addr		= base + 2 + 1 * 4;
-			ap->ioaddr.feature_addr		= base + 2 + 1 * 4;
-			ap->ioaddr.nsect_addr		= base + 2 + 2 * 4;
-			ap->ioaddr.lbal_addr		= base + 2 + 3 * 4;
-			ap->ioaddr.lbam_addr		= base + 2 + 4 * 4;
-			ap->ioaddr.lbah_addr		= base + 2 + 5 * 4;
-			ap->ioaddr.device_addr		= base + 2 + 6 * 4;
-			ap->ioaddr.status_addr		= base + 2 + 7 * 4;
-			ap->ioaddr.command_addr		= base + 2 + 7 * 4;
-
-			if (ctl) {
-				ap->ioaddr.altstatus_addr = base + ctl;
-				ap->ioaddr.ctl_addr	  = base + ctl;
-			}
-
-			ap->private_data = (void *)irqport;
-
-			ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", board,
-				      ctl ? board + buddha_bases[i] + ctl : 0);
+		ap->pio_mask = ATA_PIO4;
+		ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
+
+		ap->ioaddr.data_addr		= base;
+		ap->ioaddr.error_addr		= base + 2 + 1 * 4;
+		ap->ioaddr.feature_addr		= base + 2 + 1 * 4;
+		ap->ioaddr.nsect_addr		= base + 2 + 2 * 4;
+		ap->ioaddr.lbal_addr		= base + 2 + 3 * 4;
+		ap->ioaddr.lbam_addr		= base + 2 + 4 * 4;
+		ap->ioaddr.lbah_addr		= base + 2 + 5 * 4;
+		ap->ioaddr.device_addr		= base + 2 + 6 * 4;
+		ap->ioaddr.status_addr		= base + 2 + 7 * 4;
+		ap->ioaddr.command_addr		= base + 2 + 7 * 4;
+
+		if (ctl) {
+			ap->ioaddr.altstatus_addr = base + ctl;
+			ap->ioaddr.ctl_addr	  = base + ctl;
 		}
 
-		ata_host_activate(host, IRQ_AMIGA_PORTS, ata_sff_interrupt,
-				  IRQF_SHARED, &pata_buddha_sht);
+		ap->private_data = (void *)irqport;
 
+		ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", board,
+			      ctl ? board + buddha_bases[i] + ctl : 0);
 	}
 
+	ata_host_activate(host, IRQ_AMIGA_PORTS, ata_sff_interrupt,
+			  IRQF_SHARED, &pata_buddha_sht);
+
+
 	return 0;
+
+err_ata_host_alloc:
+	switch (type) {
+	case BOARD_BUDDHA:
+	case BOARD_CATWEASEL:
+	default:
+		devm_release_mem_region(&z->dev,
+					board + BUDDHA_BASE1,
+					0x800);
+		break;
+	case BOARD_XSURF:
+		devm_release_mem_region(&z->dev,
+					board + XSURF_BASE1,
+					0x1000);
+		devm_release_mem_region(&z->dev,
+					board + XSURF_BASE2,
+					0x1000);
+		break;
+	}
+
+	return -ENXIO;
+}
+
+static void pata_buddha_remove(struct zorro_dev *zdev)
+{
+	/* NOT IMPLEMENTED */
+
+	WARN_ONCE(1, "pata_buddha: Attempted to remove driver. This is not implemented yet.\n");
 }
 
-module_init(pata_buddha_init_one);
+static const struct zorro_device_id pata_buddha_zorro_tbl[] = {
+	{ ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA, },
+	{ ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL, },
+	{ ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, },
+	{ 0 }
+};
+
+MODULE_DEVICE_TABLE(zorro, pata_buddha_zorro_tbl);
+
+static struct zorro_driver pata_buddha_driver = {
+	.name           = "pata_buddha",
+	.id_table       = pata_buddha_zorro_tbl,
+	.probe          = pata_buddha_probe,
+	.remove         = pata_buddha_remove,
+};
+
+module_driver(pata_buddha_driver,
+	      zorro_register_driver,
+	      zorro_unregister_driver);
 
 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
 MODULE_DESCRIPTION("low-level driver for Buddha/Catweasel/X-Surf PATA");
Signature · 1 line
2.11.0
#1 lore raw

Hi Max,

Quoted 251 lines · Max Staudt

Up until now, the pata_buddha driver would only check for cards on initcall time. Now, the kernel will call its probe function as soon as a compatible card is detected.

Device removal remains unimplemented. A WARN_ONCE() serves as a reminder.

v2: Rename 'zdev' to 'z' to make the patch easy to analyse with

    git diff --ignore-space-change
---
 drivers/ata/pata_buddha.c | 240 ++++++++++++++++++++++++++++------------------
 1 file changed, 146 insertions(+), 94 deletions(-)
drivers/ata/pata_buddha.c +99 -93
index 11a8044ff..76804a4c1 100644
@@ -19,6 +19,7 @@
 #include <linux/libata.h>
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/types.h>
 #include <linux/zorro.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_host.h>
@@ -29,7 +30,7 @@
 #include <asm/setup.h>
 
 #define DRV_NAME "pata_buddha"
-#define DRV_VERSION "0.1.0"
+#define DRV_VERSION "0.1.1"
 
 #define BUDDHA_BASE1	0x800
 #define BUDDHA_BASE2	0xa00
@@ -47,11 +48,11 @@ enum {
 	BOARD_XSURF
 };
 
-static unsigned int buddha_bases[3] __initdata = {
+static unsigned int buddha_bases[3] = {
 	BUDDHA_BASE1, BUDDHA_BASE2, BUDDHA_BASE3
 };
 
-static unsigned int xsurf_bases[2] __initdata = {
+static unsigned int xsurf_bases[2] = {
 	XSURF_BASE1, XSURF_BASE2
 };
 
@@ -145,111 +146,162 @@ static struct ata_port_operations pata_xsurf_ops = {
 	.set_mode	= pata_buddha_set_mode,
 };
 
-static int __init pata_buddha_init_one(void)
+static int pata_buddha_probe(struct zorro_dev *z,
+			     const struct zorro_device_id *ent)
 {
-	struct zorro_dev *z = NULL;
-
-	while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
-		static const char *board_name[]
-			= { "Buddha", "Catweasel", "X-Surf" };
-		struct ata_host *host;
-		void __iomem *buddha_board;
-		unsigned long board;
-		unsigned int type, nr_ports = 2;
-		int i;
-
-		if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) {
-			type = BOARD_BUDDHA;
-		} else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL) {
-			type = BOARD_CATWEASEL;
-			nr_ports++;
-		} else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF) {
-			type = BOARD_XSURF;
-		} else
-			continue;
-
-		dev_info(&z->dev, "%s IDE controller\n", board_name[type]);
-
-		board = z->resource.start;
+	static const char * const board_name[]
+		= { "Buddha", "Catweasel", "X-Surf" };
+	struct ata_host *host;
+	void __iomem *buddha_board;
+	unsigned long board;
+	unsigned int type, nr_ports = 2;
+	int i;
+
+	switch (z->id) {
+	case ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA:
+	default:
+		type = BOARD_BUDDHA;
+		break;
+	case ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL:
+		type = BOARD_CATWEASEL;
+		nr_ports++;
+		break;
+	case ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF:
+		type = BOARD_XSURF;
+		break;
+	}
+
+	dev_info(&z->dev, "%s IDE controller\n", board_name[type]);
+
+	board = z->resource.start;
+
+	if (type != BOARD_XSURF) {
+		if (!devm_request_mem_region(&z->dev,
+					     board + BUDDHA_BASE1,
+					     0x800, DRV_NAME))
+			return -ENXIO;
+	} else {
+		if (!devm_request_mem_region(&z->dev,
+					     board + XSURF_BASE1,
+					     0x1000, DRV_NAME))
+			return -ENXIO;
+		if (!devm_request_mem_region(&z->dev,
+					     board + XSURF_BASE2,
+					     0x1000, DRV_NAME)) {
+			devm_release_mem_region(&z->dev,
+						board + XSURF_BASE1,
+						0x1000);
+			return -ENXIO;
+		}
+	}
+
+	/* allocate host */
+	host = ata_host_alloc(&z->dev, nr_ports);
+	if (!host)
+		goto err_ata_host_alloc;
+
+	buddha_board = ZTWO_VADDR(board);
+
+	/* enable the board IRQ on Buddha/Catweasel */
+	if (type != BOARD_XSURF)
+		z_writeb(0, buddha_board + BUDDHA_IRQ_MR);
+
+	for (i = 0; i < nr_ports; i++) {
+		struct ata_port *ap = host->ports[i];
+		void __iomem *base, *irqport;
+		unsigned long ctl = 0;
 
 		if (type != BOARD_XSURF) {
-			if (!devm_request_mem_region(&z->dev,
-						     board + BUDDHA_BASE1,
-						     0x800, DRV_NAME))
-				continue;
+			ap->ops = &pata_buddha_ops;
+			base = buddha_board + buddha_bases[i];
+			ctl = BUDDHA_CONTROL;
+			irqport = buddha_board + BUDDHA_IRQ + i * 0x40;
 		} else {
-			if (!devm_request_mem_region(&z->dev,
-						     board + XSURF_BASE1,
-						     0x1000, DRV_NAME))
-				continue;
-			if (!devm_request_mem_region(&z->dev,
-						     board + XSURF_BASE2,
-						     0x1000, DRV_NAME))
-				continue;
+			ap->ops = &pata_xsurf_ops;
+			base = buddha_board + xsurf_bases[i];
+			/* X-Surf has no CS1* (Control/AltStat) */
+			irqport = buddha_board + XSURF_IRQ;
 		}
 
-		/* allocate host */
-		host = ata_host_alloc(&z->dev, nr_ports);
-		if (!host)
-			continue;
-
-		buddha_board = ZTWO_VADDR(board);
-
-		/* enable the board IRQ on Buddha/Catweasel */
-		if (type != BOARD_XSURF)
-			z_writeb(0, buddha_board + BUDDHA_IRQ_MR);
-
-		for (i = 0; i < nr_ports; i++) {
-			struct ata_port *ap = host->ports[i];
-			void __iomem *base, *irqport;
-			unsigned long ctl = 0;
-
-			if (type != BOARD_XSURF) {
-				ap->ops = &pata_buddha_ops;
-				base = buddha_board + buddha_bases[i];
-				ctl = BUDDHA_CONTROL;
-				irqport = buddha_board + BUDDHA_IRQ + i * 0x40;
-			} else {
-				ap->ops = &pata_xsurf_ops;
-				base = buddha_board + xsurf_bases[i];
-				/* X-Surf has no CS1* (Control/AltStat) */
-				irqport = buddha_board + XSURF_IRQ;
-			}
-
-			ap->pio_mask = ATA_PIO4;
-			ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
-
-			ap->ioaddr.data_addr		= base;
-			ap->ioaddr.error_addr		= base + 2 + 1 * 4;
-			ap->ioaddr.feature_addr		= base + 2 + 1 * 4;
-			ap->ioaddr.nsect_addr		= base + 2 + 2 * 4;
-			ap->ioaddr.lbal_addr		= base + 2 + 3 * 4;
-			ap->ioaddr.lbam_addr		= base + 2 + 4 * 4;
-			ap->ioaddr.lbah_addr		= base + 2 + 5 * 4;
-			ap->ioaddr.device_addr		= base + 2 + 6 * 4;
-			ap->ioaddr.status_addr		= base + 2 + 7 * 4;
-			ap->ioaddr.command_addr		= base + 2 + 7 * 4;
-
-			if (ctl) {
-				ap->ioaddr.altstatus_addr = base + ctl;
-				ap->ioaddr.ctl_addr	  = base + ctl;
-			}
-
-			ap->private_data = (void *)irqport;
-
-			ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", board,
-				      ctl ? board + buddha_bases[i] + ctl : 0);
+		ap->pio_mask = ATA_PIO4;
+		ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
+
+		ap->ioaddr.data_addr		= base;
+		ap->ioaddr.error_addr		= base + 2 + 1 * 4;
+		ap->ioaddr.feature_addr		= base + 2 + 1 * 4;
+		ap->ioaddr.nsect_addr		= base + 2 + 2 * 4;
+		ap->ioaddr.lbal_addr		= base + 2 + 3 * 4;
+		ap->ioaddr.lbam_addr		= base + 2 + 4 * 4;
+		ap->ioaddr.lbah_addr		= base + 2 + 5 * 4;
+		ap->ioaddr.device_addr		= base + 2 + 6 * 4;
+		ap->ioaddr.status_addr		= base + 2 + 7 * 4;
+		ap->ioaddr.command_addr		= base + 2 + 7 * 4;
+
+		if (ctl) {
+			ap->ioaddr.altstatus_addr = base + ctl;
+			ap->ioaddr.ctl_addr	  = base + ctl;
 		}
 
-		ata_host_activate(host, IRQ_AMIGA_PORTS, ata_sff_interrupt,
-				  IRQF_SHARED, &pata_buddha_sht);
+		ap->private_data = (void *)irqport;
 
+		ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", board,
+			      ctl ? board + buddha_bases[i] + ctl : 0);
 	}
 
+	ata_host_activate(host, IRQ_AMIGA_PORTS, ata_sff_interrupt,
+			  IRQF_SHARED, &pata_buddha_sht);
+
+

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 264

Quoted 10 lines
drivers/ata/pata_buddha.c +9 -0
 	return 0;
+
+err_ata_host_alloc:
+	switch (type) {
+	case BOARD_BUDDHA:
+	case BOARD_CATWEASEL:
+	default:
+		devm_release_mem_region(&z->dev,
+					board + BUDDHA_BASE1,
+					0x800);

Could you please explain why this is needed now?

[ The whole idea of using devm_* helpers is to not have to release
resources explicitly. ]

Quoted 9 lines
drivers/ata/pata_buddha.c +9 -0
+		break;
+	case BOARD_XSURF:
+		devm_release_mem_region(&z->dev,
+					board + XSURF_BASE1,
+					0x1000);
+		devm_release_mem_region(&z->dev,
+					board + XSURF_BASE2,
+					0x1000);
+		break;

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 283

Quoted 10 lines
drivers/ata/pata_buddha.c +10 -0
+	}
+
+	return -ENXIO;
+}
+
+static void pata_buddha_remove(struct zorro_dev *zdev)
+{
+	/* NOT IMPLEMENTED */
+
+	WARN_ONCE(1, "pata_buddha: Attempted to remove driver. This is not implemented yet.\n");

Please try to implement it, should be as simple as:

static void pata_buddha_remove(struct zorro_dev *zdev)

{
	struct ata_host *host = dev_get_drvdata(&zdev->dev);

	ata_host_detach(host);
}

[ ata_host_alloc() in pata_buddha_probe() sets drvdata to host ]

The rest of the patch looks fine, thanks for working on this driver.

Quoted 15 lines
drivers/ata/pata_buddha.c +12 -1
 }
 
-module_init(pata_buddha_init_one);
+static const struct zorro_device_id pata_buddha_zorro_tbl[] = {
+	{ ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA, },
+	{ ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL, },
+	{ ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, },
+	{ 0 }
+};
+
+MODULE_DEVICE_TABLE(zorro, pata_buddha_zorro_tbl);
+
+static struct zorro_driver pata_buddha_driver = {
+	.name           = "pata_buddha",
+	.id_table       = pata_buddha_zorro_tbl,

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 307

Quoted 10 lines
drivers/ata/pata_buddha.c +7 -0
+	.probe          = pata_buddha_probe,
+	.remove         = pata_buddha_remove,
+};
+
+module_driver(pata_buddha_driver,
+	      zorro_register_driver,
+	      zorro_unregister_driver);
 
 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
 MODULE_DESCRIPTION("low-level driver for Buddha/Catweasel/X-Surf PATA");

PS Next time please also use scripts/get_maintainer.pl script to get
the list of people that should be added to Cc:, i.e.:

$ ./scripts/get_maintainer.pl -f drivers/ata/pata_buddha.c
Bartlomiej Zolnierkiewicz <[email protected]> (maintainer:LIBATA PATA DRIVERS)
Jens Axboe <[email protected]> (maintainer:LIBATA PATA DRIVERS)
[email protected] (open list:LIBATA PATA DRIVERS)
[email protected] (open list)

[ I've also added John, Michael & Geert to Cc: (as they were all
involved in the development of the initial driver version). ]

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

author
#2 lore raw
Quoted 11 lines · Bartlomiej Zolnierkiewicz

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 264

Quoted 8 lines
drivers/ata/pata_buddha.c +8 -0
+err_ata_host_alloc:
+	switch (type) {
+	case BOARD_BUDDHA:
+	case BOARD_CATWEASEL:
+	default:
+		devm_release_mem_region(&z->dev,
+					board + BUDDHA_BASE1,
+					0x800);

Could you please explain why this is needed now?

Quoted 2 lines

[ The whole idea of using devm_* helpers is to not have to release
resources explicitly. ]

My mistake. Thanks, I'll fix it.

Quoted 8 lines

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 283

Quoted 5 lines
drivers/ata/pata_buddha.c +5 -0
+static void pata_buddha_remove(struct zorro_dev *zdev)
+{
+	/* NOT IMPLEMENTED */
+
+	WARN_ONCE(1, "pata_buddha: Attempted to remove driver. This is not implemented yet.\n");

Please try to implement it, should be as simple as:

Quoted 8 lines

static void pata_buddha_remove(struct zorro_dev *zdev)

{
	struct ata_host *host = dev_get_drvdata(&zdev->dev);

	ata_host_detach(host);
}

[ ata_host_alloc() in pata_buddha_probe() sets drvdata to host ]

Seeing as the driver is almost 1:1 the same as pata_gayle, I see no reason against this.

Do you need me to test module removal on the real machine, or is it okay to take your suggestion as-is, given that it is already accepted in pata_gayle?

Quoted 1 line

The rest of the patch looks fine, thanks for working on this driver.

Thanks for reviewing it, and thanks for porting buddha to libata!

Quoted 11 lines

PS Next time please also use scripts/get_maintainer.pl script to get
the list of people that should be added to Cc:, i.e.:

$ ./scripts/get_maintainer.pl -f drivers/ata/pata_buddha.c
Bartlomiej Zolnierkiewicz <[email protected]> (maintainer:LIBATA PATA DRIVERS)
Jens Axboe <[email protected]> (maintainer:LIBATA PATA DRIVERS)
[email protected] (open list:LIBATA PATA DRIVERS)
[email protected] (open list)

[ I've also added John, Michael & Geert to Cc: (as they were all
involved in the development of the initial driver version). ]

Oops, thanks for fixing this.

Max

author
#3 lore raw
Quoted 7 lines · Max Staudt
Quoted 6 lines · Bartlomiej Zolnierkiewicz

Please try to implement it, should be as simple as:

static void pata_buddha_remove(struct zorro_dev *zdev)

{
	struct ata_host *host = dev_get_drvdata(&zdev->dev);
Quoted 8 lines
Quoted 4 lines
	ata_host_detach(host);
}

[ ata_host_alloc() in pata_buddha_probe() sets drvdata to host ]

Seeing as the driver is almost 1:1 the same as pata_gayle, I see no reason against this.

Do you need me to test module removal on the real machine, or is it okay to take your suggestion as-is, given that it is already accepted in pata_gayle?

Nevermind, I found a way to test it somewhat quickly. I can confirm that it works. Thanks for your suggestion!

Max

#4 lore raw
In reply to Bartlomiej Zolnierkiewicz

Hi Bartlomiej!

Quoted 2 lines · Bartlomiej Zolnierkiewicz

[ I've also added John, Michael & Geert to Cc: (as they were all
involved in the development of the initial driver version). ]

Thanks a lot for your review, much appreciated!

FWIW, me, Michael and Geert are all on the linux-m68k list, so we are already in the loop. I also happened to talk with Max before regarding the driver!

We can test the driver on the test Amiga 4000 we have again which has a Buddha controller installed. Usually Michael builds the kernel for used for testing, but in case he's not around I can do that, too.

Thanks,
Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#5 lore raw
In reply to Max Staudt

Hi Max,

Quoted 4 lines · Max Staudt

Up until now, the pata_buddha driver would only check for cards on initcall time. Now, the kernel will call its probe function as soon as a compatible card is detected.

Quoted 8 lines

Device removal remains unimplemented. A WARN_ONCE() serves as a reminder.

v2: Rename 'zdev' to 'z' to make the patch easy to analyse with

    git diff --ignore-space-change

Thanks for your patch!

Quoted 11 lines
drivers/ata/pata_buddha.c +2 -1
@@ -145,111 +146,162 @@ static struct ata_port_operations pata_xsurf_ops = {
        .set_mode       = pata_buddha_set_mode,
 };
 
-static int __init pata_buddha_init_one(void)
+static int pata_buddha_probe(struct zorro_dev *z,
+                            const struct zorro_device_id *ent)
 {

[...]

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 172

Quoted 13 lines
drivers/ata/pata_buddha.c +13 -0
+       switch (z->id) {
+       case ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA:
+       default:
+               type = BOARD_BUDDHA;
+               break;
+       case ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL:
+               type = BOARD_CATWEASEL;
+               nr_ports++;
+               break;
+       case ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF:
+               type = BOARD_XSURF;
+               break;
+       }

Please obtain the type from ent->driver_data instead of using a switch() statement...

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 289

Quoted 5 lines
drivers/ata/pata_buddha.c +4 -1
-module_init(pata_buddha_init_one);
+static const struct zorro_device_id pata_buddha_zorro_tbl[] = {
+       { ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA, },
+       { ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL, },
+       { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, },

... after storing it in zorro_device_id.driver_data here.

drivers/ata/pata_buddha.c

Quoted 2 lines
drivers/ata/pata_buddha.c +2 -0
+       { 0 }
+};

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#6 lore raw
Quoted 17 lines · Geert Uytterhoeven

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 172

Quoted 13 lines
drivers/ata/pata_buddha.c +13 -0
+       switch (z->id) {
+       case ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA:
+       default:
+               type = BOARD_BUDDHA;
+               break;
+       case ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL:
+               type = BOARD_CATWEASEL;
+               nr_ports++;
+               break;
+       case ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF:
+               type = BOARD_XSURF;
+               break;
+       }

Please obtain the type from ent->driver_data instead of using a switch() statement...

Quoted 7 lines

drivers/ata/pata_buddha.c static struct ata_port_operations pata_xsurf_ops = { · line 289

Quoted 5 lines
drivers/ata/pata_buddha.c +4 -1
-module_init(pata_buddha_init_one);
+static const struct zorro_device_id pata_buddha_zorro_tbl[] = {
+       { ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA, },
+       { ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL, },
+       { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, },

... after storing it in zorro_device_id.driver_data here.

Thanks Geert for your feedback, this is a good idea. I'll make this change.

Max