aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-07-23 13:55:57 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-07-23 13:55:57 -0400
commit48c3c1072651922ed153bcf0a33ea82cf20df390 (patch)
tree92ad23e3869e70731eca99394c08a3bf06b8753e /drivers
parent374e042c3e767ac2e5a40b78529220e0b3de793c (diff)
ide: add struct ide_host (take 3)
* Add struct ide_host which keeps pointers to host's ports. * Add ide_host_alloc[_all]() and ide_host_remove() helpers. * Pass 'struct ide_host *host' instead of 'u8 *idx' to ide_device_add[_all]() and rename it to ide_host_register[_all](). * Convert host drivers and core code to use struct ide_host. * Remove no longer needed ide_find_port(). * Make ide_find_port_slot() static. * Unexport ide_unregister(). v2: * Add missing 'struct ide_host *host' to macide.c. v3: * Fix build problem in pmac.c (s/ide_alloc_host/ide_host_alloc/) (Noticed by Stephen Rothwell). Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ide/arm/icside.c40
-rw-r--r--drivers/ide/arm/ide_arm.c12
-rw-r--r--drivers/ide/arm/palm_bk3710.c13
-rw-r--r--drivers/ide/arm/rapide.c17
-rw-r--r--drivers/ide/h8300/ide-h8300.c14
-rw-r--r--drivers/ide/ide-generic.c28
-rw-r--r--drivers/ide/ide-pnp.c17
-rw-r--r--drivers/ide/ide-probe.c94
-rw-r--r--drivers/ide/ide.c2
-rw-r--r--drivers/ide/legacy/buddha.c19
-rw-r--r--drivers/ide/legacy/falconide.c11
-rw-r--r--drivers/ide/legacy/gayle.c16
-rw-r--r--drivers/ide/legacy/ide-4drives.c23
-rw-r--r--drivers/ide/legacy/ide-cs.c46
-rw-r--r--drivers/ide/legacy/ide_platform.c23
-rw-r--r--drivers/ide/legacy/macide.c12
-rw-r--r--drivers/ide/legacy/q40ide.c15
-rw-r--r--drivers/ide/mips/au1xxx-ide.c25
-rw-r--r--drivers/ide/mips/swarm.c13
-rw-r--r--drivers/ide/pci/cmd640.c30
-rw-r--r--drivers/ide/pci/cs5520.c8
-rw-r--r--drivers/ide/pci/delkin_cb.c19
-rw-r--r--drivers/ide/pci/scc_pata.c24
-rw-r--r--drivers/ide/pci/sgiioc4.c13
-rw-r--r--drivers/ide/ppc/pmac.c10
-rw-r--r--drivers/ide/setup-pci.c48
26 files changed, 253 insertions, 339 deletions
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index 0283d162f7f7..6fa58425466a 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -72,7 +72,7 @@ struct icside_state {
72 void __iomem *ioc_base; 72 void __iomem *ioc_base;
73 unsigned int sel; 73 unsigned int sel;
74 unsigned int type; 74 unsigned int type;
75 ide_hwif_t *hwif[2]; 75 struct ide_host *host;
76}; 76};
77 77
78#define ICS_TYPE_A3IN 0 78#define ICS_TYPE_A3IN 0
@@ -442,10 +442,9 @@ static void icside_setup_ports(hw_regs_t *hw, void __iomem *base,
442static int __init 442static int __init
443icside_register_v5(struct icside_state *state, struct expansion_card *ec) 443icside_register_v5(struct icside_state *state, struct expansion_card *ec)
444{ 444{
445 ide_hwif_t *hwif;
446 void __iomem *base; 445 void __iomem *base;
446 struct ide_host *host;
447 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 447 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
448 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
449 448
450 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); 449 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
451 if (!base) 450 if (!base)
@@ -465,17 +464,15 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
465 464
466 icside_setup_ports(&hw, base, &icside_cardinfo_v5, ec); 465 icside_setup_ports(&hw, base, &icside_cardinfo_v5, ec);
467 466
468 hwif = ide_find_port(); 467 host = ide_host_alloc(NULL, hws);
469 if (!hwif) 468 if (host == NULL)
470 return -ENODEV; 469 return -ENODEV;
471 470
472 state->hwif[0] = hwif; 471 state->host = host;
473 472
474 ecard_set_drvdata(ec, state); 473 ecard_set_drvdata(ec, state);
475 474
476 idx[0] = hwif->index; 475 ide_host_register(host, NULL, hws);
477
478 ide_device_add(idx, NULL, hws);
479 476
480 return 0; 477 return 0;
481} 478}
@@ -492,12 +489,11 @@ static const struct ide_port_info icside_v6_port_info __initdata = {
492static int __init 489static int __init
493icside_register_v6(struct icside_state *state, struct expansion_card *ec) 490icside_register_v6(struct icside_state *state, struct expansion_card *ec)
494{ 491{
495 ide_hwif_t *hwif, *mate;
496 void __iomem *ioc_base, *easi_base; 492 void __iomem *ioc_base, *easi_base;
493 struct ide_host *host;
497 unsigned int sel = 0; 494 unsigned int sel = 0;
498 int ret; 495 int ret;
499 hw_regs_t hw[2], *hws[] = { &hw[0], NULL, NULL, NULL }; 496 hw_regs_t hw[2], *hws[] = { &hw[0], NULL, NULL, NULL };
500 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
501 struct ide_port_info d = icside_v6_port_info; 497 struct ide_port_info d = icside_v6_port_info;
502 498
503 ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); 499 ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
@@ -537,25 +533,11 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
537 icside_setup_ports(&hw[0], easi_base, &icside_cardinfo_v6_1, ec); 533 icside_setup_ports(&hw[0], easi_base, &icside_cardinfo_v6_1, ec);
538 icside_setup_ports(&hw[1], easi_base, &icside_cardinfo_v6_2, ec); 534 icside_setup_ports(&hw[1], easi_base, &icside_cardinfo_v6_2, ec);
539 535
540 /* 536 host = ide_host_alloc(&d, hws);
541 * Find and register the interfaces. 537 if (host == NULL)
542 */
543 hwif = ide_find_port();
544 if (hwif == NULL)
545 return -ENODEV; 538 return -ENODEV;
546 539
547 hwif->chipset = ide_acorn; 540 state->host = host;
548
549 idx[0] = hwif->index;
550
551 mate = ide_find_port();
552 if (mate) {
553 hws[1] = &hw[1];
554 idx[1] = mate->index;
555 }
556
557 state->hwif[0] = hwif;
558 state->hwif[1] = mate;
559 541
560 ecard_set_drvdata(ec, state); 542 ecard_set_drvdata(ec, state);
561 543
@@ -565,7 +547,7 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
565 d.dma_ops = NULL; 547 d.dma_ops = NULL;
566 } 548 }
567 549
568 ide_device_add(idx, &d, hws); 550 ide_host_register(host, &d, hws);
569 551
570 return 0; 552 return 0;
571 553
diff --git a/drivers/ide/arm/ide_arm.c b/drivers/ide/arm/ide_arm.c
index e9831bbd988a..9efd7a86db45 100644
--- a/drivers/ide/arm/ide_arm.c
+++ b/drivers/ide/arm/ide_arm.c
@@ -28,10 +28,9 @@
28 28
29static int __init ide_arm_init(void) 29static int __init ide_arm_init(void)
30{ 30{
31 ide_hwif_t *hwif; 31 struct ide_host *host;
32 unsigned long base = IDE_ARM_IO, ctl = IDE_ARM_IO + 0x206; 32 unsigned long base = IDE_ARM_IO, ctl = IDE_ARM_IO + 0x206;
33 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 33 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
34 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
35 34
36 if (!request_region(base, 8, DRV_NAME)) { 35 if (!request_region(base, 8, DRV_NAME)) {
37 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n", 36 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
@@ -51,12 +50,9 @@ static int __init ide_arm_init(void)
51 hw.irq = IDE_ARM_IRQ; 50 hw.irq = IDE_ARM_IRQ;
52 hw.chipset = ide_generic; 51 hw.chipset = ide_generic;
53 52
54 hwif = ide_find_port(); 53 host = ide_host_alloc(NULL, hws);
55 if (hwif) { 54 if (host)
56 idx[0] = hwif->index; 55 ide_host_register(host, NULL, hws);
57
58 ide_device_add(idx, NULL, hws);
59 }
60 56
61 return 0; 57 return 0;
62} 58}
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/arm/palm_bk3710.c
index 545563bc7e23..24389a571c37 100644
--- a/drivers/ide/arm/palm_bk3710.c
+++ b/drivers/ide/arm/palm_bk3710.c
@@ -347,11 +347,10 @@ static int __devinit palm_bk3710_probe(struct platform_device *pdev)
347{ 347{
348 struct clk *clk; 348 struct clk *clk;
349 struct resource *mem, *irq; 349 struct resource *mem, *irq;
350 ide_hwif_t *hwif; 350 struct ide_host *host;
351 unsigned long base, rate; 351 unsigned long base, rate;
352 int i; 352 int i;
353 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 353 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
354 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
355 354
356 clk = clk_get(NULL, "IDECLK"); 355 clk = clk_get(NULL, "IDECLK");
357 if (IS_ERR(clk)) 356 if (IS_ERR(clk))
@@ -393,15 +392,11 @@ static int __devinit palm_bk3710_probe(struct platform_device *pdev)
393 hw.irq = irq->start; 392 hw.irq = irq->start;
394 hw.chipset = ide_palm3710; 393 hw.chipset = ide_palm3710;
395 394
396 hwif = ide_find_port(); 395 host = ide_host_alloc(&palm_bk3710_port_info, hws);
397 if (hwif == NULL) 396 if (host == NULL)
398 goto out; 397 goto out;
399 398
400 i = hwif->index; 399 ide_host_register(host, &palm_bk3710_port_info, hws);
401
402 idx[0] = i;
403
404 ide_device_add(idx, &palm_bk3710_port_info, hws);
405 400
406 return 0; 401 return 0;
407out: 402out:
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c
index a45c2f694949..11f3307385de 100644
--- a/drivers/ide/arm/rapide.c
+++ b/drivers/ide/arm/rapide.c
@@ -32,11 +32,10 @@ static void rapide_setup_ports(hw_regs_t *hw, void __iomem *base,
32static int __devinit 32static int __devinit
33rapide_probe(struct expansion_card *ec, const struct ecard_id *id) 33rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
34{ 34{
35 ide_hwif_t *hwif;
36 void __iomem *base; 35 void __iomem *base;
36 struct ide_host *host;
37 int ret; 37 int ret;
38 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 38 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
39 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
40 39
41 ret = ecard_request_resources(ec); 40 ret = ecard_request_resources(ec);
42 if (ret) 41 if (ret)
@@ -53,17 +52,15 @@ rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
53 hw.chipset = ide_generic; 52 hw.chipset = ide_generic;
54 hw.dev = &ec->dev; 53 hw.dev = &ec->dev;
55 54
56 hwif = ide_find_port(); 55 host = ide_host_alloc(&rapide_port_info, hws);
57 if (hwif == NULL) { 56 if (host == NULL) {
58 ret = -ENOENT; 57 ret = -ENOENT;
59 goto release; 58 goto release;
60 } 59 }
61 60
62 idx[0] = hwif->index; 61 ide_host_register(host, &rapide_port_info, hws);
63 62
64 ide_device_add(idx, &rapide_port_info, hws); 63 ecard_set_drvdata(ec, host);
65
66 ecard_set_drvdata(ec, hwif);
67 goto out; 64 goto out;
68 65
69 release: 66 release:
@@ -74,11 +71,11 @@ rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
74 71
75static void __devexit rapide_remove(struct expansion_card *ec) 72static void __devexit rapide_remove(struct expansion_card *ec)
76{ 73{
77 ide_hwif_t *hwif = ecard_get_drvdata(ec); 74 struct ide_host *host = ecard_get_drvdata(ec);
78 75
79 ecard_set_drvdata(ec, NULL); 76 ecard_set_drvdata(ec, NULL);
80 77
81 ide_unregister(hwif); 78 ide_host_remove(host);
82 79
83 ecard_release_resources(ec); 80 ecard_release_resources(ec);
84} 81}
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c
index 84644e150531..15f76690a48c 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/h8300/ide-h8300.c
@@ -191,10 +191,8 @@ static const struct ide_port_info h8300_port_info = {
191 191
192static int __init h8300_ide_init(void) 192static int __init h8300_ide_init(void)
193{ 193{
194 ide_hwif_t *hwif; 194 struct ide_host *host;
195 int index;
196 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 195 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
197 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
198 196
199 printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n"); 197 printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n");
200 198
@@ -207,15 +205,11 @@ static int __init h8300_ide_init(void)
207 205
208 hw_setup(&hw); 206 hw_setup(&hw);
209 207
210 hwif = ide_find_port_slot(&h8300_port_info); 208 host = ide_host_alloc(&h8300_port_info, hws);
211 if (hwif == NULL) 209 if (host == NULL)
212 return -ENOENT; 210 return -ENOENT;
213 211
214 index = hwif->index; 212 ide_host_register(host, &h8300_port_info, hws);
215
216 idx[0] = index;
217
218 ide_device_add(idx, &h8300_port_info, hws);
219 213
220 return 0; 214 return 0;
221 215
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index a5c352abff59..e8818362eb46 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -28,27 +28,24 @@ MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
28 28
29static ssize_t store_add(struct class *cls, const char *buf, size_t n) 29static ssize_t store_add(struct class *cls, const char *buf, size_t n)
30{ 30{
31 ide_hwif_t *hwif; 31 struct ide_host *host;
32 unsigned int base, ctl; 32 unsigned int base, ctl;
33 int irq; 33 int irq;
34 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 34 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
35 u8 idx[] = { 0xff, 0xff, 0xff, 0xff };
36 35
37 if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3) 36 if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3)
38 return -EINVAL; 37 return -EINVAL;
39 38
40 hwif = ide_find_port();
41 if (hwif == NULL)
42 return -ENOENT;
43
44 memset(&hw, 0, sizeof(hw)); 39 memset(&hw, 0, sizeof(hw));
45 ide_std_init_ports(&hw, base, ctl); 40 ide_std_init_ports(&hw, base, ctl);
46 hw.irq = irq; 41 hw.irq = irq;
47 hw.chipset = ide_generic; 42 hw.chipset = ide_generic;
48 43
49 idx[0] = hwif->index; 44 host = ide_host_alloc(NULL, hws);
45 if (host == NULL)
46 return -ENOENT;
50 47
51 ide_device_add(idx, NULL, hws); 48 ide_host_register(host, NULL, hws);
52 49
53 return n; 50 return n;
54}; 51};
@@ -89,18 +86,16 @@ static int __init ide_generic_sysfs_init(void)
89static int __init ide_generic_init(void) 86static int __init ide_generic_init(void)
90{ 87{
91 hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS]; 88 hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS];
92 u8 idx[MAX_HWIFS]; 89 struct ide_host *host;
93 int i; 90 int i;
94 91
95 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module " 92 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module "
96 "parameter for probing all legacy ISA IDE ports\n"); 93 "parameter for probing all legacy ISA IDE ports\n");
97 94
98 for (i = 0; i < MAX_HWIFS; i++) { 95 for (i = 0; i < MAX_HWIFS; i++) {
99 ide_hwif_t *hwif;
100 unsigned long io_addr = ide_default_io_base(i); 96 unsigned long io_addr = ide_default_io_base(i);
101 97
102 hws[i] = NULL; 98 hws[i] = NULL;
103 idx[i] = 0xff;
104 99
105 if ((probe_mask & (1 << i)) && io_addr) { 100 if ((probe_mask & (1 << i)) && io_addr) {
106 if (!request_region(io_addr, 8, DRV_NAME)) { 101 if (!request_region(io_addr, 8, DRV_NAME)) {
@@ -118,23 +113,18 @@ static int __init ide_generic_init(void)
118 continue; 113 continue;
119 } 114 }
120 115
121 hwif = ide_find_port();
122 if (hwif == NULL)
123 continue;
124
125 hwif->chipset = ide_generic;
126
127 memset(&hw[i], 0, sizeof(hw[i])); 116 memset(&hw[i], 0, sizeof(hw[i]));
128 ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206); 117 ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206);
129 hw[i].irq = ide_default_irq(io_addr); 118 hw[i].irq = ide_default_irq(io_addr);
130 hw[i].chipset = ide_generic; 119 hw[i].chipset = ide_generic;
131 120
132 hws[i] = &hw[i]; 121 hws[i] = &hw[i];
133 idx[i] = i;
134 } 122 }
135 } 123 }
136 124
137 ide_device_add_all(idx, NULL, hws); 125 host = ide_host_alloc_all(NULL, hws);
126 if (host)
127 ide_host_register(host, NULL, hws);
138 128
139 if (ide_generic_sysfs_init()) 129 if (ide_generic_sysfs_init())
140 printk(KERN_ERR DRV_NAME ": failed to create ide_generic " 130 printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c
index 89cd5cbe8573..4458ca61897a 100644
--- a/drivers/ide/ide-pnp.c
+++ b/drivers/ide/ide-pnp.c
@@ -29,7 +29,7 @@ static struct pnp_device_id idepnp_devices[] = {
29 29
30static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) 30static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
31{ 31{
32 ide_hwif_t *hwif; 32 struct ide_host *host;
33 unsigned long base, ctl; 33 unsigned long base, ctl;
34 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 34 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
35 35
@@ -59,14 +59,11 @@ static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
59 hw.irq = pnp_irq(dev, 0); 59 hw.irq = pnp_irq(dev, 0);
60 hw.chipset = ide_generic; 60 hw.chipset = ide_generic;
61 61
62 hwif = ide_find_port(); 62 host = ide_host_alloc(NULL, hws);
63 if (hwif) { 63 if (host) {
64 u8 index = hwif->index; 64 pnp_set_drvdata(dev, host);
65 u8 idx[4] = { index, 0xff, 0xff, 0xff };
66 65
67 pnp_set_drvdata(dev, hwif); 66 ide_host_register(host, NULL, hws);
68
69 ide_device_add(idx, NULL, hws);
70 67
71 return 0; 68 return 0;
72 } 69 }
@@ -79,9 +76,9 @@ static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
79 76
80static void idepnp_remove(struct pnp_dev *dev) 77static void idepnp_remove(struct pnp_dev *dev)
81{ 78{
82 ide_hwif_t *hwif = pnp_get_drvdata(dev); 79 struct ide_host *host = pnp_get_drvdata(dev);
83 80
84 ide_unregister(hwif); 81 ide_host_remove(host);
85 82
86 release_region(pnp_port_start(dev, 1), 1); 83 release_region(pnp_port_start(dev, 1), 1);
87 release_region(pnp_port_start(dev, 0), 8); 84 release_region(pnp_port_start(dev, 0), 8);
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index c588066295db..84a89561ec0f 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1477,7 +1477,7 @@ static int ide_sysfs_register_port(ide_hwif_t *hwif)
1477 * Return the new hwif. If we are out of free slots return NULL. 1477 * Return the new hwif. If we are out of free slots return NULL.
1478 */ 1478 */
1479 1479
1480ide_hwif_t *ide_find_port_slot(const struct ide_port_info *d) 1480static ide_hwif_t *ide_find_port_slot(const struct ide_port_info *d)
1481{ 1481{
1482 ide_hwif_t *hwif; 1482 ide_hwif_t *hwif;
1483 int i; 1483 int i;
@@ -1523,14 +1523,63 @@ out_found:
1523 ide_init_port_data(hwif, i); 1523 ide_init_port_data(hwif, i);
1524 return hwif; 1524 return hwif;
1525} 1525}
1526EXPORT_SYMBOL_GPL(ide_find_port_slot);
1527 1526
1528int ide_device_add_all(u8 *idx, const struct ide_port_info *d, hw_regs_t **hws) 1527struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1528 hw_regs_t **hws)
1529{
1530 struct ide_host *host;
1531 int i;
1532
1533 host = kzalloc(sizeof(*host), GFP_KERNEL);
1534 if (host == NULL)
1535 return NULL;
1536
1537 for (i = 0; i < MAX_HWIFS; i++) {
1538 ide_hwif_t *hwif;
1539
1540 if (hws[i] == NULL)
1541 continue;
1542
1543 hwif = ide_find_port_slot(d);
1544 if (hwif) {
1545 hwif->chipset = hws[i]->chipset;
1546
1547 host->ports[i] = hwif;
1548 host->n_ports++;
1549 }
1550 }
1551
1552 if (host->n_ports == 0) {
1553 kfree(host);
1554 return NULL;
1555 }
1556
1557 return host;
1558}
1559EXPORT_SYMBOL_GPL(ide_host_alloc_all);
1560
1561struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1562{
1563 hw_regs_t *hws_all[MAX_HWIFS];
1564 int i;
1565
1566 for (i = 0; i < MAX_HWIFS; i++)
1567 hws_all[i] = (i < 4) ? hws[i] : NULL;
1568
1569 return ide_host_alloc_all(d, hws_all);
1570}
1571EXPORT_SYMBOL_GPL(ide_host_alloc);
1572
1573int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1574 hw_regs_t **hws)
1529{ 1575{
1530 ide_hwif_t *hwif, *mate = NULL; 1576 ide_hwif_t *hwif, *mate = NULL;
1577 u8 idx[MAX_HWIFS];
1531 int i, rc = 0; 1578 int i, rc = 0;
1532 1579
1533 for (i = 0; i < MAX_HWIFS; i++) { 1580 for (i = 0; i < MAX_HWIFS; i++) {
1581 idx[i] = host->ports[i] ? host->ports[i]->index : 0xff;
1582
1534 if (idx[i] == 0xff) { 1583 if (idx[i] == 0xff) {
1535 mate = NULL; 1584 mate = NULL;
1536 continue; 1585 continue;
@@ -1626,22 +1675,20 @@ int ide_device_add_all(u8 *idx, const struct ide_port_info *d, hw_regs_t **hws)
1626 1675
1627 return rc; 1676 return rc;
1628} 1677}
1629EXPORT_SYMBOL_GPL(ide_device_add_all); 1678EXPORT_SYMBOL_GPL(ide_host_register);
1630 1679
1631int ide_device_add(u8 *idx, const struct ide_port_info *d, hw_regs_t **hws) 1680void ide_host_remove(struct ide_host *host)
1632{ 1681{
1633 hw_regs_t *hws_all[MAX_HWIFS];
1634 u8 idx_all[MAX_HWIFS];
1635 int i; 1682 int i;
1636 1683
1637 for (i = 0; i < MAX_HWIFS; i++) { 1684 for (i = 0; i < MAX_HWIFS; i++) {
1638 hws_all[i] = (i < 4) ? hws[i] : NULL; 1685 if (host->ports[i])
1639 idx_all[i] = (i < 4) ? idx[i] : 0xff; 1686 ide_unregister(host->ports[i]);
1640 } 1687 }
1641 1688
1642 return ide_device_add_all(idx_all, d, hws_all); 1689 kfree(host);
1643} 1690}
1644EXPORT_SYMBOL_GPL(ide_device_add); 1691EXPORT_SYMBOL_GPL(ide_host_remove);
1645 1692
1646void ide_port_scan(ide_hwif_t *hwif) 1693void ide_port_scan(ide_hwif_t *hwif)
1647{ 1694{
@@ -1662,11 +1709,10 @@ void ide_port_scan(ide_hwif_t *hwif)
1662} 1709}
1663EXPORT_SYMBOL_GPL(ide_port_scan); 1710EXPORT_SYMBOL_GPL(ide_port_scan);
1664 1711
1665static void ide_legacy_init_one(u8 *idx, hw_regs_t **hws, hw_regs_t *hw, 1712static void ide_legacy_init_one(hw_regs_t **hws, hw_regs_t *hw,
1666 u8 port_no, const struct ide_port_info *d, 1713 u8 port_no, const struct ide_port_info *d,
1667 unsigned long config) 1714 unsigned long config)
1668{ 1715{
1669 ide_hwif_t *hwif;
1670 unsigned long base, ctl; 1716 unsigned long base, ctl;
1671 int irq; 1717 int irq;
1672 1718
@@ -1698,31 +1744,29 @@ static void ide_legacy_init_one(u8 *idx, hw_regs_t **hws, hw_regs_t *hw,
1698 hw->chipset = d->chipset; 1744 hw->chipset = d->chipset;
1699 hw->config = config; 1745 hw->config = config;
1700 1746
1701 hwif = ide_find_port_slot(d); 1747 hws[port_no] = hw;
1702 if (hwif) {
1703 hwif->chipset = hw->chipset;
1704
1705 hws[port_no] = hw;
1706 idx[port_no] = hwif->index;
1707 }
1708} 1748}
1709 1749
1710int ide_legacy_device_add(const struct ide_port_info *d, unsigned long config) 1750int ide_legacy_device_add(const struct ide_port_info *d, unsigned long config)
1711{ 1751{
1712 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 1752 struct ide_host *host;
1713 hw_regs_t hw[2], *hws[] = { NULL, NULL, NULL, NULL }; 1753 hw_regs_t hw[2], *hws[] = { NULL, NULL, NULL, NULL };
1714 1754
1715 memset(&hw, 0, sizeof(hw)); 1755 memset(&hw, 0, sizeof(hw));
1716 1756
1717 if ((d->host_flags & IDE_HFLAG_QD_2ND_PORT) == 0) 1757 if ((d->host_flags & IDE_HFLAG_QD_2ND_PORT) == 0)
1718 ide_legacy_init_one(idx, hws, &hw[0], 0, d, config); 1758 ide_legacy_init_one(hws, &hw[0], 0, d, config);
1719 ide_legacy_init_one(idx, hws, &hw[1], 1, d, config); 1759 ide_legacy_init_one(hws, &hw[1], 1, d, config);
1720 1760
1721 if (idx[0] == 0xff && idx[1] == 0xff && 1761 if (hws[0] == NULL && hws[1] == NULL &&
1722 (d->host_flags & IDE_HFLAG_SINGLE)) 1762 (d->host_flags & IDE_HFLAG_SINGLE))
1723 return -ENOENT; 1763 return -ENOENT;
1724 1764
1725 ide_device_add(idx, d, hws); 1765 host = ide_host_alloc(d, hws);
1766 if (host == NULL)
1767 return -ENOMEM;
1768
1769 ide_host_register(host, d, hws);
1726 1770
1727 return 0; 1771 return 0;
1728} 1772}
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 132b504168e9..7e9575d1aee3 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -276,8 +276,6 @@ void ide_unregister(ide_hwif_t *hwif)
276 mutex_unlock(&ide_cfg_mtx); 276 mutex_unlock(&ide_cfg_mtx);
277} 277}
278 278
279EXPORT_SYMBOL(ide_unregister);
280
281void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw) 279void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
282{ 280{
283 memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports)); 281 memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c
index c61bc6a1db36..2625667fab4c 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/legacy/buddha.c
@@ -150,18 +150,15 @@ static void __init buddha_setup_ports(hw_regs_t *hw, unsigned long base,
150 150
151static int __init buddha_init(void) 151static int __init buddha_init(void)
152{ 152{
153 ide_hwif_t *hwif;
154 int i;
155
156 struct zorro_dev *z = NULL; 153 struct zorro_dev *z = NULL;
154 struct ide_host *host;
157 u_long buddha_board = 0; 155 u_long buddha_board = 0;
158 BuddhaType type; 156 BuddhaType type;
159 int buddha_num_hwifs; 157 int buddha_num_hwifs, i;
160 158
161 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) { 159 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
162 unsigned long board; 160 unsigned long board;
163 hw_regs_t hw[MAX_NUM_HWIFS], *hws[] = { NULL, NULL, NULL, NULL }; 161 hw_regs_t hw[MAX_NUM_HWIFS], *hws[] = { NULL, NULL, NULL, NULL };
164 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
165 162
166 if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) { 163 if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) {
167 buddha_num_hwifs = BUDDHA_NUM_HWIFS; 164 buddha_num_hwifs = BUDDHA_NUM_HWIFS;
@@ -226,16 +223,12 @@ fail_base2:
226 buddha_setup_ports(&hw[i], base, ctl, irq_port, 223 buddha_setup_ports(&hw[i], base, ctl, irq_port,
227 ack_intr); 224 ack_intr);
228 225
229 hwif = ide_find_port(); 226 hws[i] = &hw[i];
230 if (hwif) {
231 hwif->chipset = ide_generic;
232
233 hws[i] = &hw[i];
234 idx[i] = hwif->index;
235 }
236 } 227 }
237 228
238 ide_device_add(idx, NULL, hws); 229 host = ide_host_alloc(NULL, hws);
230 if (host)
231 ide_host_register(host, NULL, hws);
239 } 232 }
240 233
241 return 0; 234 return 0;
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c
index 3e2c6125f031..4eb5c3f9fecc 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/legacy/falconide.c
@@ -112,7 +112,7 @@ static void __init falconide_setup_ports(hw_regs_t *hw)
112 112
113static int __init falconide_init(void) 113static int __init falconide_init(void)
114{ 114{
115 ide_hwif_t *hwif; 115 struct ide_host *host;
116 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 116 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
117 117
118 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE)) 118 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE))
@@ -127,13 +127,10 @@ static int __init falconide_init(void)
127 127
128 falconide_setup_ports(&hw); 128 falconide_setup_ports(&hw);
129 129
130 hwif = ide_find_port(); 130 host = ide_host_alloc(&falconide_port_info, hws);
131 if (hwif) { 131 if (host) {
132 u8 index = hwif->index;
133 u8 idx[4] = { index, 0xff, 0xff, 0xff };
134
135 ide_get_lock(NULL, NULL); 132 ide_get_lock(NULL, NULL);
136 ide_device_add(idx, &falconide_port_info, hws); 133 ide_host_register(host, &falconide_port_info, hws);
137 ide_release_lock(); 134 ide_release_lock();
138 } 135 }
139 136
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c
index 7baeefa870fa..13d22bded6b4 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/gayle.c
@@ -127,9 +127,9 @@ static int __init gayle_init(void)
127 unsigned long phys_base, res_start, res_n; 127 unsigned long phys_base, res_start, res_n;
128 unsigned long base, ctrlport, irqport; 128 unsigned long base, ctrlport, irqport;
129 ide_ack_intr_t *ack_intr; 129 ide_ack_intr_t *ack_intr;
130 struct ide_host *host;
130 int a4000, i; 131 int a4000, i;
131 hw_regs_t hw[GAYLE_NUM_HWIFS], *hws[] = { NULL, NULL, NULL, NULL }; 132 hw_regs_t hw[GAYLE_NUM_HWIFS], *hws[] = { NULL, NULL, NULL, NULL };
132 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
133 133
134 if (!MACH_IS_AMIGA) 134 if (!MACH_IS_AMIGA)
135 return -ENODEV; 135 return -ENODEV;
@@ -172,23 +172,17 @@ found:
172 return -EBUSY; 172 return -EBUSY;
173 173
174 for (i = 0; i < GAYLE_NUM_PROBE_HWIFS; i++) { 174 for (i = 0; i < GAYLE_NUM_PROBE_HWIFS; i++) {
175 ide_hwif_t *hwif;
176
177 base = (unsigned long)ZTWO_VADDR(phys_base + i * GAYLE_NEXT_PORT); 175 base = (unsigned long)ZTWO_VADDR(phys_base + i * GAYLE_NEXT_PORT);
178 ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0; 176 ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0;
179 177
180 gayle_setup_ports(&hw[i], base, ctrlport, irqport, ack_intr); 178 gayle_setup_ports(&hw[i], base, ctrlport, irqport, ack_intr);
181 179
182 hwif = ide_find_port(); 180 hws[i] = &hw[i];
183 if (hwif) {
184 hwif->chipset = ide_generic;
185
186 hws[i] = &hw[i];
187 idx[i] = hwif->index;
188 }
189 } 181 }
190 182
191 ide_device_add(idx, NULL, hws); 183 host = ide_host_alloc(NULL, hws);
184 if (host)
185 ide_host_register(host, NULL, hws);
192 186
193 return 0; 187 return 0;
194} 188}
diff --git a/drivers/ide/legacy/ide-4drives.c b/drivers/ide/legacy/ide-4drives.c
index 6310dc50e3c5..5935153ef2ad 100644
--- a/drivers/ide/legacy/ide-4drives.c
+++ b/drivers/ide/legacy/ide-4drives.c
@@ -28,10 +28,9 @@ static const struct ide_port_info ide_4drives_port_info = {
28 28
29static int __init ide_4drives_init(void) 29static int __init ide_4drives_init(void)
30{ 30{
31 ide_hwif_t *hwif, *mate; 31 struct ide_host *host;
32 unsigned long base = 0x1f0, ctl = 0x3f6; 32 unsigned long base = 0x1f0, ctl = 0x3f6;
33 hw_regs_t hw, *hws[] = { NULL, NULL, NULL, NULL }; 33 hw_regs_t hw, *hws[] = { &hw, &hw, NULL, NULL };
34 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
35 34
36 if (probe_4drives == 0) 35 if (probe_4drives == 0)
37 return -ENODEV; 36 return -ENODEV;
@@ -55,21 +54,9 @@ static int __init ide_4drives_init(void)
55 hw.irq = 14; 54 hw.irq = 14;
56 hw.chipset = ide_4drives; 55 hw.chipset = ide_4drives;
57 56
58 hwif = ide_find_port(); 57 host = ide_host_alloc(&ide_4drives_port_info, hws);
59 if (hwif) { 58 if (host)
60 hwif->chipset = ide_4drives; 59 ide_host_register(host, &ide_4drives_port_info, hws);
61
62 hws[0] = &hw;
63 idx[0] = hwif->index;
64 }
65
66 mate = ide_find_port();
67 if (mate) {
68 hws[1] = &hw;
69 idx[1] = mate->index;
70 }
71
72 ide_device_add(idx, &ide_4drives_port_info, hws);
73 60
74 return 0; 61 return 0;
75} 62}
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index f93d5454ebf8..1a4b9e6887fa 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -74,7 +74,7 @@ INT_MODULE_PARM(pc_debug, 0);
74 74
75typedef struct ide_info_t { 75typedef struct ide_info_t {
76 struct pcmcia_device *p_dev; 76 struct pcmcia_device *p_dev;
77 ide_hwif_t *hwif; 77 struct ide_host *host;
78 int ndev; 78 int ndev;
79 dev_node_t node; 79 dev_node_t node;
80} ide_info_t; 80} ide_info_t;
@@ -132,7 +132,7 @@ static int ide_probe(struct pcmcia_device *link)
132static void ide_detach(struct pcmcia_device *link) 132static void ide_detach(struct pcmcia_device *link)
133{ 133{
134 ide_info_t *info = link->priv; 134 ide_info_t *info = link->priv;
135 ide_hwif_t *hwif = info->hwif; 135 ide_hwif_t *hwif = info->host->ports[0];
136 unsigned long data_addr, ctl_addr; 136 unsigned long data_addr, ctl_addr;
137 137
138 DEBUG(0, "ide_detach(0x%p)\n", link); 138 DEBUG(0, "ide_detach(0x%p)\n", link);
@@ -157,13 +157,13 @@ static const struct ide_port_info idecs_port_info = {
157 .host_flags = IDE_HFLAG_NO_DMA, 157 .host_flags = IDE_HFLAG_NO_DMA,
158}; 158};
159 159
160static ide_hwif_t *idecs_register(unsigned long io, unsigned long ctl, 160static struct ide_host *idecs_register(unsigned long io, unsigned long ctl,
161 unsigned long irq, struct pcmcia_device *handle) 161 unsigned long irq, struct pcmcia_device *handle)
162{ 162{
163 struct ide_host *host;
163 ide_hwif_t *hwif; 164 ide_hwif_t *hwif;
164 int i; 165 int i;
165 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 166 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
166 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
167 167
168 if (!request_region(io, 8, DRV_NAME)) { 168 if (!request_region(io, 8, DRV_NAME)) {
169 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n", 169 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
@@ -184,26 +184,26 @@ static ide_hwif_t *idecs_register(unsigned long io, unsigned long ctl,
184 hw.chipset = ide_pci; 184 hw.chipset = ide_pci;
185 hw.dev = &handle->dev; 185 hw.dev = &handle->dev;
186 186
187 hwif = ide_find_port(); 187 host = ide_host_alloc(&idecs_port_info, hws);
188 if (hwif == NULL) 188 if (host == NULL)
189 goto out_release; 189 goto out_release;
190 190
191 idx[0] = hwif->index; 191 ide_host_register(host, &idecs_port_info, hws);
192 192
193 ide_device_add(idx, &idecs_port_info, hws); 193 hwif = host->ports[0];
194 194
195 if (hwif->present) 195 if (hwif->present)
196 return hwif; 196 return host;
197 197
198 /* retry registration in case device is still spinning up */ 198 /* retry registration in case device is still spinning up */
199 for (i = 0; i < 10; i++) { 199 for (i = 0; i < 10; i++) {
200 msleep(100); 200 msleep(100);
201 ide_port_scan(hwif); 201 ide_port_scan(hwif);
202 if (hwif->present) 202 if (hwif->present)
203 return hwif; 203 return host;
204 } 204 }
205 205
206 return hwif; 206 return host;
207 207
208out_release: 208out_release:
209 release_region(ctl, 1); 209 release_region(ctl, 1);
@@ -235,7 +235,7 @@ static int ide_config(struct pcmcia_device *link)
235 cistpl_cftable_entry_t *cfg; 235 cistpl_cftable_entry_t *cfg;
236 int pass, last_ret = 0, last_fn = 0, is_kme = 0; 236 int pass, last_ret = 0, last_fn = 0, is_kme = 0;
237 unsigned long io_base, ctl_base; 237 unsigned long io_base, ctl_base;
238 ide_hwif_t *hwif; 238 struct ide_host *host;
239 239
240 DEBUG(0, "ide_config(0x%p)\n", link); 240 DEBUG(0, "ide_config(0x%p)\n", link);
241 241
@@ -330,21 +330,21 @@ static int ide_config(struct pcmcia_device *link)
330 if (is_kme) 330 if (is_kme)
331 outb(0x81, ctl_base+1); 331 outb(0x81, ctl_base+1);
332 332
333 hwif = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link); 333 host = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link);
334 if (hwif == NULL && link->io.NumPorts1 == 0x20) { 334 if (host == NULL && link->io.NumPorts1 == 0x20) {
335 outb(0x02, ctl_base + 0x10); 335 outb(0x02, ctl_base + 0x10);
336 hwif = idecs_register(io_base + 0x10, ctl_base + 0x10, 336 host = idecs_register(io_base + 0x10, ctl_base + 0x10,
337 link->irq.AssignedIRQ, link); 337 link->irq.AssignedIRQ, link);
338 } 338 }
339 339
340 if (hwif == NULL) 340 if (host == NULL)
341 goto failed; 341 goto failed;
342 342
343 info->ndev = 1; 343 info->ndev = 1;
344 sprintf(info->node.dev_name, "hd%c", 'a' + hwif->index * 2); 344 sprintf(info->node.dev_name, "hd%c", 'a' + host->ports[0]->index * 2);
345 info->node.major = hwif->major; 345 info->node.major = host->ports[0]->major;
346 info->node.minor = 0; 346 info->node.minor = 0;
347 info->hwif = hwif; 347 info->host = host;
348 link->dev_node = &info->node; 348 link->dev_node = &info->node;
349 printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n", 349 printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n",
350 info->node.dev_name, link->conf.Vpp / 10, link->conf.Vpp % 10); 350 info->node.dev_name, link->conf.Vpp / 10, link->conf.Vpp % 10);
@@ -375,15 +375,15 @@ failed:
375static void ide_release(struct pcmcia_device *link) 375static void ide_release(struct pcmcia_device *link)
376{ 376{
377 ide_info_t *info = link->priv; 377 ide_info_t *info = link->priv;
378 ide_hwif_t *hwif = info->hwif; 378 struct ide_host *host = info->host;
379 379
380 DEBUG(0, "ide_release(0x%p)\n", link); 380 DEBUG(0, "ide_release(0x%p)\n", link);
381 381
382 if (info->ndev) { 382 if (info->ndev)
383 /* FIXME: if this fails we need to queue the cleanup somehow 383 /* FIXME: if this fails we need to queue the cleanup somehow
384 -- need to investigate the required PCMCIA magic */ 384 -- need to investigate the required PCMCIA magic */
385 ide_unregister(hwif); 385 ide_host_remove(host);
386 } 386
387 info->ndev = 0; 387 info->ndev = 0;
388 388
389 pcmcia_disable_device(link); 389 pcmcia_disable_device(link);
diff --git a/drivers/ide/legacy/ide_platform.c b/drivers/ide/legacy/ide_platform.c
index 3d71e336a221..58a942c6a131 100644
--- a/drivers/ide/legacy/ide_platform.c
+++ b/drivers/ide/legacy/ide_platform.c
@@ -52,11 +52,10 @@ static int __devinit plat_ide_probe(struct platform_device *pdev)
52{ 52{
53 struct resource *res_base, *res_alt, *res_irq; 53 struct resource *res_base, *res_alt, *res_irq;
54 void __iomem *base, *alt_base; 54 void __iomem *base, *alt_base;
55 ide_hwif_t *hwif;
56 struct pata_platform_info *pdata; 55 struct pata_platform_info *pdata;
56 struct ide_host *host;
57 int ret = 0, mmio = 0; 57 int ret = 0, mmio = 0;
58 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 58 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
59 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
60 struct ide_port_info d = platform_ide_port_info; 59 struct ide_port_info d = platform_ide_port_info;
61 60
62 pdata = pdev->dev.platform_data; 61 pdata = pdev->dev.platform_data;
@@ -93,12 +92,6 @@ static int __devinit plat_ide_probe(struct platform_device *pdev)
93 res_alt->start, res_alt->end - res_alt->start + 1); 92 res_alt->start, res_alt->end - res_alt->start + 1);
94 } 93 }
95 94
96 hwif = ide_find_port();
97 if (!hwif) {
98 ret = -ENODEV;
99 goto out;
100 }
101
102 memset(&hw, 0, sizeof(hw)); 95 memset(&hw, 0, sizeof(hw));
103 plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start); 96 plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
104 hw.dev = &pdev->dev; 97 hw.dev = &pdev->dev;
@@ -106,11 +99,15 @@ static int __devinit plat_ide_probe(struct platform_device *pdev)
106 if (mmio) 99 if (mmio)
107 d.host_flags |= IDE_HFLAG_MMIO; 100 d.host_flags |= IDE_HFLAG_MMIO;
108 101
109 idx[0] = hwif->index; 102 host = ide_host_alloc(&d, hws);
103 if (host == NULL) {
104 ret = -ENODEV;
105 goto out;
106 }
110 107
111 ide_device_add(idx, &d, hws); 108 ide_host_register(host, &d, hws);
112 109
113 platform_set_drvdata(pdev, hwif); 110 platform_set_drvdata(pdev, host);
114 111
115 return 0; 112 return 0;
116 113
@@ -120,9 +117,9 @@ out:
120 117
121static int __devexit plat_ide_remove(struct platform_device *pdev) 118static int __devexit plat_ide_remove(struct platform_device *pdev)
122{ 119{
123 ide_hwif_t *hwif = pdev->dev.driver_data; 120 struct ide_host *host = pdev->dev.driver_data;
124 121
125 ide_unregister(hwif); 122 ide_host_remove(host);
126 123
127 return 0; 124 return 0;
128} 125}
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index d839df2239fc..b49cf8c2b91a 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/macide.c
@@ -91,8 +91,8 @@ static const char *mac_ide_name[] =
91 91
92static int __init macide_init(void) 92static int __init macide_init(void)
93{ 93{
94 ide_hwif_t *hwif;
95 ide_ack_intr_t *ack_intr; 94 ide_ack_intr_t *ack_intr;
95 struct ide_host *host;
96 unsigned long base; 96 unsigned long base;
97 int irq; 97 int irq;
98 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 98 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
@@ -125,13 +125,9 @@ static int __init macide_init(void)
125 125
126 macide_setup_ports(&hw, base, irq, ack_intr); 126 macide_setup_ports(&hw, base, irq, ack_intr);
127 127
128 hwif = ide_find_port(); 128 host = ide_host_alloc(NULL, hws);
129 if (hwif) { 129 if (host)
130 u8 index = hwif->index; 130 ide_host_register(host, NULL, hws);
131 u8 idx[4] = { index, 0xff, 0xff, 0xff };
132
133 ide_device_add(idx, NULL, hws);
134 }
135 131
136 return 0; 132 return 0;
137} 133}
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index 2dc306f852a6..8fb4438a6afd 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/q40ide.c
@@ -131,10 +131,9 @@ static const char *q40_ide_names[Q40IDE_NUM_HWIFS]={
131 131
132static int __init q40ide_init(void) 132static int __init q40ide_init(void)
133{ 133{
134 struct ide_host *host;
134 int i; 135 int i;
135 ide_hwif_t *hwif;
136 hw_regs_t hw[Q40IDE_NUM_HWIFS], *hws[] = { NULL, NULL, NULL, NULL }; 136 hw_regs_t hw[Q40IDE_NUM_HWIFS], *hws[] = { NULL, NULL, NULL, NULL };
137 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
138 137
139 if (!MACH_IS_Q40) 138 if (!MACH_IS_Q40)
140 return -ENODEV; 139 return -ENODEV;
@@ -158,16 +157,12 @@ static int __init q40ide_init(void)
158 q40_ide_setup_ports(&hw[i], pcide_bases[i], NULL, 157 q40_ide_setup_ports(&hw[i], pcide_bases[i], NULL,
159 q40ide_default_irq(pcide_bases[i])); 158 q40ide_default_irq(pcide_bases[i]));
160 159
161 hwif = ide_find_port(); 160 hws[i] = &hw[i];
162 if (hwif) {
163 hwif->chipset = ide_generic;
164
165 hws[i] = &hw[i];
166 idx[i] = hwif->index;
167 }
168 } 161 }
169 162
170 ide_device_add(idx, &q40ide_port_info, hws); 163 host = ide_host_alloc(&q40ide_port_info, hws);
164 if (host)
165 ide_host_register(host, &q40ide_port_info, hws);
171 166
172 return 0; 167 return 0;
173} 168}
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index ed1c9a134079..903c628bddd0 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -563,11 +563,10 @@ static int au_ide_probe(struct device *dev)
563{ 563{
564 struct platform_device *pdev = to_platform_device(dev); 564 struct platform_device *pdev = to_platform_device(dev);
565 _auide_hwif *ahwif = &auide_hwif; 565 _auide_hwif *ahwif = &auide_hwif;
566 ide_hwif_t *hwif;
567 struct resource *res; 566 struct resource *res;
567 struct ide_host *host;
568 int ret = 0; 568 int ret = 0;
569 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 569 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
570 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
571 570
572#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA) 571#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
573 char *mode = "MWDMA2"; 572 char *mode = "MWDMA2";
@@ -604,25 +603,23 @@ static int au_ide_probe(struct device *dev)
604 goto out; 603 goto out;
605 } 604 }
606 605
607 hwif = ide_find_port();
608 if (hwif == NULL) {
609 ret = -ENOENT;
610 goto out;
611 }
612
613 memset(&hw, 0, sizeof(hw)); 606 memset(&hw, 0, sizeof(hw));
614 auide_setup_ports(&hw, ahwif); 607 auide_setup_ports(&hw, ahwif);
615 hw.irq = ahwif->irq; 608 hw.irq = ahwif->irq;
616 hw.dev = dev; 609 hw.dev = dev;
617 hw.chipset = ide_au1xxx; 610 hw.chipset = ide_au1xxx;
618 611
619 auide_hwif.hwif = hwif; 612 host = ide_host_alloc(&au1xxx_port_info, hws);
613 if (host == NULL) {
614 ret = -ENOENT;
615 goto out;
616 }
620 617
621 idx[0] = hwif->index; 618 ide_host_register(host, &au1xxx_port_info, hws);
622 619
623 ide_device_add(idx, &au1xxx_port_info, hws); 620 auide_hwif.hwif = host->ports[0];
624 621
625 dev_set_drvdata(dev, hwif); 622 dev_set_drvdata(dev, host);
626 623
627 printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode ); 624 printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode );
628 625
@@ -634,10 +631,10 @@ static int au_ide_remove(struct device *dev)
634{ 631{
635 struct platform_device *pdev = to_platform_device(dev); 632 struct platform_device *pdev = to_platform_device(dev);
636 struct resource *res; 633 struct resource *res;
637 ide_hwif_t *hwif = dev_get_drvdata(dev); 634 struct ide_host *host = dev_get_drvdata(dev);
638 _auide_hwif *ahwif = &auide_hwif; 635 _auide_hwif *ahwif = &auide_hwif;
639 636
640 ide_unregister(hwif); 637 ide_host_remove(host);
641 638
642 iounmap((void *)ahwif->regbase); 639 iounmap((void *)ahwif->regbase);
643 640
diff --git a/drivers/ide/mips/swarm.c b/drivers/ide/mips/swarm.c
index c1ffb83a2de7..b12d9d224831 100644
--- a/drivers/ide/mips/swarm.c
+++ b/drivers/ide/mips/swarm.c
@@ -72,12 +72,11 @@ static const struct ide_port_info swarm_port_info = {
72 */ 72 */
73static int __devinit swarm_ide_probe(struct device *dev) 73static int __devinit swarm_ide_probe(struct device *dev)
74{ 74{
75 ide_hwif_t *hwif;
76 u8 __iomem *base; 75 u8 __iomem *base;
76 struct ide_host *host;
77 phys_t offset, size; 77 phys_t offset, size;
78 int i; 78 int i;
79 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 79 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
80 u8 idx[] = { 0xff, 0xff, 0xff, 0xff };
81 80
82 if (!SIBYTE_HAVE_IDE) 81 if (!SIBYTE_HAVE_IDE)
83 return -ENODEV; 82 return -ENODEV;
@@ -116,15 +115,13 @@ static int __devinit swarm_ide_probe(struct device *dev)
116 hw.irq = K_INT_GB_IDE; 115 hw.irq = K_INT_GB_IDE;
117 hw.chipset = ide_generic; 116 hw.chipset = ide_generic;
118 117
119 hwif = ide_find_port_slot(&swarm_port_info); 118 host = ide_host_alloc(&swarm_port_info, hws);
120 if (hwif == NULL) 119 if (host == NULL)
121 goto err; 120 goto err;
122 121
123 idx[0] = hwif->index; 122 ide_host_register(host, &swarm_port_info, hws);
124 123
125 ide_device_add(idx, &swarm_port_info, hws); 124 dev_set_drvdata(dev, host);
126
127 dev_set_drvdata(dev, hwif);
128 125
129 return 0; 126 return 0;
130err: 127err:
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index ccde1e444e13..013697b8cef4 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -181,11 +181,6 @@ static u8 recovery_counts[4] = {16, 16, 16, 16}; /* Recovery count (encoded) */
181static DEFINE_SPINLOCK(cmd640_lock); 181static DEFINE_SPINLOCK(cmd640_lock);
182 182
183/* 183/*
184 * These are initialized to point at the devices we control
185 */
186static ide_hwif_t *cmd_hwif0, *cmd_hwif1;
187
188/*
189 * Interface to access cmd640x registers 184 * Interface to access cmd640x registers
190 */ 185 */
191static unsigned int cmd640_key; 186static unsigned int cmd640_key;
@@ -714,11 +709,11 @@ static int cmd640x_init_one(unsigned long base, unsigned long ctl)
714 */ 709 */
715static int __init cmd640x_init(void) 710static int __init cmd640x_init(void)
716{ 711{
712 struct ide_host *host;
717 int second_port_cmd640 = 0, rc; 713 int second_port_cmd640 = 0, rc;
718 const char *bus_type, *port2; 714 const char *bus_type, *port2;
719 u8 b, cfr; 715 u8 b, cfr;
720 hw_regs_t hw[2], *hws[] = { NULL, NULL, NULL, NULL }; 716 hw_regs_t hw[2], *hws[] = { NULL, NULL, NULL, NULL };
721 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
722 717
723 if (cmd640_vlb && probe_for_cmd640_vlb()) { 718 if (cmd640_vlb && probe_for_cmd640_vlb()) {
724 bus_type = "VLB"; 719 bus_type = "VLB";
@@ -781,17 +776,10 @@ static int __init cmd640x_init(void)
781 printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x" 776 printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x"
782 "\n", 'a' + cmd640_chip_version - 1, bus_type, cfr); 777 "\n", 'a' + cmd640_chip_version - 1, bus_type, cfr);
783 778
784 cmd_hwif0 = ide_find_port();
785
786 /* 779 /*
787 * Initialize data for primary port 780 * Initialize data for primary port
788 */ 781 */
789 if (cmd_hwif0) { 782 hws[0] = &hw[0];
790 cmd_hwif0->chipset = ide_cmd640;
791
792 hws[0] = &hw[0];
793 idx[0] = cmd_hwif0->index;
794 }
795 783
796 /* 784 /*
797 * Ensure compatibility by always using the slowest timings 785 * Ensure compatibility by always using the slowest timings
@@ -831,13 +819,9 @@ static int __init cmd640x_init(void)
831 /* 819 /*
832 * Initialize data for secondary cmd640 port, if enabled 820 * Initialize data for secondary cmd640 port, if enabled
833 */ 821 */
834 if (second_port_cmd640) { 822 if (second_port_cmd640)
835 cmd_hwif1 = ide_find_port(); 823 hws[1] = &hw[1];
836 if (cmd_hwif1) { 824
837 hws[1] = &hw[1];
838 idx[1] = cmd_hwif1->index;
839 }
840 }
841 printk(KERN_INFO "cmd640: %sserialized, secondary interface %s\n", 825 printk(KERN_INFO "cmd640: %sserialized, secondary interface %s\n",
842 second_port_cmd640 ? "" : "not ", port2); 826 second_port_cmd640 ? "" : "not ", port2);
843 827
@@ -845,7 +829,9 @@ static int __init cmd640x_init(void)
845 cmd640_dump_regs(); 829 cmd640_dump_regs();
846#endif 830#endif
847 831
848 ide_device_add(idx, &cmd640_port_info, hws); 832 host = ide_host_alloc(&cmd640_port_info, hws);
833 if (host)
834 ide_host_register(host, &cmd640_port_info, hws);
849 835
850 return 1; 836 return 1;
851} 837}
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index e8e7df1915bf..b8ec06d22c61 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -114,9 +114,9 @@ static const struct ide_port_info cyrix_chipsets[] __devinitdata = {
114 114
115static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id) 115static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id)
116{ 116{
117 struct ide_host *host;
117 const struct ide_port_info *d = &cyrix_chipsets[id->driver_data]; 118 const struct ide_port_info *d = &cyrix_chipsets[id->driver_data];
118 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL }; 119 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
119 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
120 120
121 ide_setup_pci_noise(dev, d); 121 ide_setup_pci_noise(dev, d);
122 122
@@ -138,9 +138,11 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
138 * do all the device setup for us 138 * do all the device setup for us
139 */ 139 */
140 140
141 ide_pci_setup_ports(dev, d, 14, &idx[0], &hw[0], &hws[0]); 141 ide_pci_setup_ports(dev, d, 14, &hw[0], &hws[0]);
142 142
143 ide_device_add(idx, d, hws); 143 host = ide_host_alloc(d, hws);
144 if (host)
145 ide_host_register(host, d, hws);
144 146
145 return 0; 147 return 0;
146} 148}
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c
index 33fe15db408a..5eb9d9325184 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/delkin_cb.c
@@ -56,11 +56,10 @@ static const struct ide_port_info delkin_cb_port_info = {
56static int __devinit 56static int __devinit
57delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id) 57delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
58{ 58{
59 struct ide_host *host;
59 unsigned long base; 60 unsigned long base;
60 ide_hwif_t *hwif = NULL;
61 int i, rc; 61 int i, rc;
62 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 62 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
63 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
64 63
65 rc = pci_enable_device(dev); 64 rc = pci_enable_device(dev);
66 if (rc) { 65 if (rc) {
@@ -87,17 +86,13 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
87 hw.dev = &dev->dev; 86 hw.dev = &dev->dev;
88 hw.chipset = ide_pci; /* this enables IRQ sharing */ 87 hw.chipset = ide_pci; /* this enables IRQ sharing */
89 88
90 hwif = ide_find_port(); 89 host = ide_host_alloc(&delkin_cb_port_info, hws);
91 if (hwif == NULL) 90 if (host == NULL)
92 goto out_disable; 91 goto out_disable;
93 92
94 i = hwif->index; 93 ide_host_register(host, &delkin_cb_port_info, hws);
95 94
96 idx[0] = i; 95 pci_set_drvdata(dev, host);
97
98 ide_device_add(idx, &delkin_cb_port_info, hws);
99
100 pci_set_drvdata(dev, hwif);
101 96
102 return 0; 97 return 0;
103 98
@@ -110,9 +105,9 @@ out_disable:
110static void 105static void
111delkin_cb_remove (struct pci_dev *dev) 106delkin_cb_remove (struct pci_dev *dev)
112{ 107{
113 ide_hwif_t *hwif = pci_get_drvdata(dev); 108 struct ide_host *host = pci_get_drvdata(dev);
114 109
115 ide_unregister(hwif); 110 ide_host_remove(host);
116 111
117 pci_release_regions(dev); 112 pci_release_regions(dev);
118 pci_disable_device(dev); 113 pci_disable_device(dev);
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index 5b1a0e950dfd..d5e2ba6bacd6 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -65,7 +65,7 @@
65 65
66static struct scc_ports { 66static struct scc_ports {
67 unsigned long ctl, dma; 67 unsigned long ctl, dma;
68 ide_hwif_t *hwif; /* for removing port from system */ 68 struct ide_host *host; /* for removing port from system */
69} scc_ports[MAX_HWIFS]; 69} scc_ports[MAX_HWIFS];
70 70
71/* PIO transfer mode table */ 71/* PIO transfer mode table */
@@ -586,15 +586,10 @@ static int scc_ide_setup_pci_device(struct pci_dev *dev,
586 const struct ide_port_info *d) 586 const struct ide_port_info *d)
587{ 587{
588 struct scc_ports *ports = pci_get_drvdata(dev); 588 struct scc_ports *ports = pci_get_drvdata(dev);
589 ide_hwif_t *hwif = NULL; 589 struct ide_host *host;
590 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 590 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
591 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
592 int i; 591 int i;
593 592
594 hwif = ide_find_port_slot(d);
595 if (hwif == NULL)
596 return -ENOMEM;
597
598 memset(&hw, 0, sizeof(hw)); 593 memset(&hw, 0, sizeof(hw));
599 for (i = 0; i <= 8; i++) 594 for (i = 0; i <= 8; i++)
600 hw.io_ports_array[i] = ports->dma + 0x20 + i * 4; 595 hw.io_ports_array[i] = ports->dma + 0x20 + i * 4;
@@ -602,9 +597,13 @@ static int scc_ide_setup_pci_device(struct pci_dev *dev,
602 hw.dev = &dev->dev; 597 hw.dev = &dev->dev;
603 hw.chipset = ide_pci; 598 hw.chipset = ide_pci;
604 599
605 idx[0] = hwif->index; 600 host = ide_host_alloc(d, hws);
601 if (host == NULL)
602 return -ENOMEM;
606 603
607 ide_device_add(idx, d, hws); 604 ide_host_register(host, d, hws);
605
606 ports->host = host;
608 607
609 return 0; 608 return 0;
610} 609}
@@ -848,8 +847,6 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif)
848{ 847{
849 struct scc_ports *ports = ide_get_hwifdata(hwif); 848 struct scc_ports *ports = ide_get_hwifdata(hwif);
850 849
851 ports->hwif = hwif;
852
853 /* PTERADD */ 850 /* PTERADD */
854 out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma); 851 out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma);
855 852
@@ -932,7 +929,8 @@ static int __devinit scc_init_one(struct pci_dev *dev, const struct pci_device_i
932static void __devexit scc_remove(struct pci_dev *dev) 929static void __devexit scc_remove(struct pci_dev *dev)
933{ 930{
934 struct scc_ports *ports = pci_get_drvdata(dev); 931 struct scc_ports *ports = pci_get_drvdata(dev);
935 ide_hwif_t *hwif = ports->hwif; 932 struct ide_host *host = ports->host;
933 ide_hwif_t *hwif = host->ports[0];
936 934
937 if (hwif->dmatable_cpu) { 935 if (hwif->dmatable_cpu) {
938 pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES, 936 pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES,
@@ -940,7 +938,7 @@ static void __devexit scc_remove(struct pci_dev *dev)
940 hwif->dmatable_cpu = NULL; 938 hwif->dmatable_cpu = NULL;
941 } 939 }
942 940
943 ide_unregister(hwif); 941 ide_host_remove(host);
944 942
945 iounmap((void*)ports->dma); 943 iounmap((void*)ports->dma);
946 iounmap((void*)ports->ctl); 944 iounmap((void*)ports->ctl);
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index 5598bd5936d9..440f43a86ad3 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -600,9 +600,8 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
600 unsigned long cmd_base, irqport; 600 unsigned long cmd_base, irqport;
601 unsigned long bar0, cmd_phys_base, ctl; 601 unsigned long bar0, cmd_phys_base, ctl;
602 void __iomem *virt_base; 602 void __iomem *virt_base;
603 ide_hwif_t *hwif; 603 struct ide_host *host;
604 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 604 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
605 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
606 struct ide_port_info d = sgiioc4_port_info; 605 struct ide_port_info d = sgiioc4_port_info;
607 606
608 /* Get the CmdBlk and CtrlBlk Base Registers */ 607 /* Get the CmdBlk and CtrlBlk Base Registers */
@@ -635,16 +634,14 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
635 hw.chipset = ide_pci; 634 hw.chipset = ide_pci;
636 hw.dev = &dev->dev; 635 hw.dev = &dev->dev;
637 636
638 hwif = ide_find_port_slot(&d);
639 if (hwif == NULL)
640 goto err;
641
642 /* Initializing chipset IRQ Registers */ 637 /* Initializing chipset IRQ Registers */
643 writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4)); 638 writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4));
644 639
645 idx[0] = hwif->index; 640 host = ide_host_alloc(&d, hws);
641 if (host == NULL)
642 goto err;
646 643
647 if (ide_device_add(idx, &d, hws)) 644 if (ide_host_register(host, &d, hws))
648 return -EIO; 645 return -EIO;
649 646
650 return 0; 647 return 0;
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index ee557d10a764..ecd2f28da1ba 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1039,9 +1039,9 @@ static int __devinit pmac_ide_setup_device(pmac_ide_hwif_t *pmif, hw_regs_t *hw)
1039{ 1039{
1040 struct device_node *np = pmif->node; 1040 struct device_node *np = pmif->node;
1041 const int *bidp; 1041 const int *bidp;
1042 struct ide_host *host;
1042 ide_hwif_t *hwif; 1043 ide_hwif_t *hwif;
1043 hw_regs_t *hws[] = { hw, NULL, NULL, NULL }; 1044 hw_regs_t *hws[] = { hw, NULL, NULL, NULL };
1044 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
1045 struct ide_port_info d = pmac_port_info; 1045 struct ide_port_info d = pmac_port_info;
1046 1046
1047 pmif->broken_dma = pmif->broken_dma_warn = 0; 1047 pmif->broken_dma = pmif->broken_dma_warn = 0;
@@ -1118,13 +1118,13 @@ static int __devinit pmac_ide_setup_device(pmac_ide_hwif_t *pmif, hw_regs_t *hw)
1118 pmif->mdev ? "macio" : "PCI", pmif->aapl_bus_id, 1118 pmif->mdev ? "macio" : "PCI", pmif->aapl_bus_id,
1119 pmif->mediabay ? " (mediabay)" : "", hw->irq); 1119 pmif->mediabay ? " (mediabay)" : "", hw->irq);
1120 1120
1121 hwif = ide_find_port_slot(&d); 1121 host = ide_host_alloc(&d, hws);
1122 if (hwif == NULL) 1122 if (host == NULL)
1123 return -ENOENT; 1123 return -ENOENT;
1124 1124
1125 idx[0] = hwif->index; 1125 ide_host_register(host, &d, hws);
1126 1126
1127 ide_device_add(idx, &d, hws); 1127 hwif = host->ports[0];
1128 1128
1129 return 0; 1129 return 0;
1130} 1130}
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index 804c3ef245f9..1c0c5570dec8 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -289,7 +289,7 @@ static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *
289} 289}
290 290
291/** 291/**
292 * ide_hwif_configure - configure an IDE interface 292 * ide_hw_configure - configure a hw_regs_t instance
293 * @dev: PCI device holding interface 293 * @dev: PCI device holding interface
294 * @d: IDE port info 294 * @d: IDE port info
295 * @port: port number 295 * @port: port number
@@ -300,23 +300,20 @@ static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *
300 * is done per interface port rather than per PCI device. There may be 300 * is done per interface port rather than per PCI device. There may be
301 * more than one port per device. 301 * more than one port per device.
302 * 302 *
303 * Returns the new hardware interface structure, or NULL on a failure 303 * Returns zero on success or an error code.
304 */ 304 */
305 305
306static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, 306static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
307 const struct ide_port_info *d, 307 unsigned int port, int irq, hw_regs_t *hw)
308 unsigned int port, int irq,
309 hw_regs_t *hw)
310{ 308{
311 unsigned long ctl = 0, base = 0; 309 unsigned long ctl = 0, base = 0;
312 ide_hwif_t *hwif;
313 310
314 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { 311 if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
315 if (ide_pci_check_iomem(dev, d, 2 * port) || 312 if (ide_pci_check_iomem(dev, d, 2 * port) ||
316 ide_pci_check_iomem(dev, d, 2 * port + 1)) { 313 ide_pci_check_iomem(dev, d, 2 * port + 1)) {
317 printk(KERN_ERR "%s: I/O baseregs (BIOS) are reported " 314 printk(KERN_ERR "%s: I/O baseregs (BIOS) are reported "
318 "as MEM for port %d!\n", d->name, port); 315 "as MEM for port %d!\n", d->name, port);
319 return NULL; 316 return -EINVAL;
320 } 317 }
321 318
322 ctl = pci_resource_start(dev, 2*port+1); 319 ctl = pci_resource_start(dev, 2*port+1);
@@ -330,7 +327,7 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
330 if (!base || !ctl) { 327 if (!base || !ctl) {
331 printk(KERN_ERR "%s: bad PCI BARs for port %d, skipping\n", 328 printk(KERN_ERR "%s: bad PCI BARs for port %d, skipping\n",
332 d->name, port); 329 d->name, port);
333 return NULL; 330 return -EINVAL;
334 } 331 }
335 332
336 memset(hw, 0, sizeof(*hw)); 333 memset(hw, 0, sizeof(*hw));
@@ -339,13 +336,7 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
339 hw->chipset = d->chipset ? d->chipset : ide_pci; 336 hw->chipset = d->chipset ? d->chipset : ide_pci;
340 ide_std_init_ports(hw, base, ctl | 2); 337 ide_std_init_ports(hw, base, ctl | 2);
341 338
342 hwif = ide_find_port_slot(d); 339 return 0;
343 if (hwif == NULL)
344 return NULL;
345
346 hwif->chipset = hw->chipset;
347
348 return hwif;
349} 340}
350 341
351#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 342#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
@@ -443,7 +434,6 @@ out:
443 * @dev: PCI device 434 * @dev: PCI device
444 * @d: IDE port info 435 * @d: IDE port info
445 * @pciirq: IRQ line 436 * @pciirq: IRQ line
446 * @idx: ATA index table to update
447 * @hw: hw_regs_t instances corresponding to this PCI IDE device 437 * @hw: hw_regs_t instances corresponding to this PCI IDE device
448 * @hws: hw_regs_t pointers table to update 438 * @hws: hw_regs_t pointers table to update
449 * 439 *
@@ -457,10 +447,9 @@ out:
457 */ 447 */
458 448
459void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d, 449void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
460 int pciirq, u8 *idx, hw_regs_t *hw, hw_regs_t **hws) 450 int pciirq, hw_regs_t *hw, hw_regs_t **hws)
461{ 451{
462 int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port; 452 int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port;
463 ide_hwif_t *hwif;
464 u8 tmp; 453 u8 tmp;
465 454
466 /* 455 /*
@@ -476,12 +465,10 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
476 continue; /* port not enabled */ 465 continue; /* port not enabled */
477 } 466 }
478 467
479 hwif = ide_hwif_configure(dev, d, port, pciirq, hw + port); 468 if (ide_hw_configure(dev, d, port, pciirq, hw + port))
480 if (hwif == NULL)
481 continue; 469 continue;
482 470
483 *(hws + port) = hw + port; 471 *(hws + port) = hw + port;
484 *(idx + port) = hwif->index;
485 } 472 }
486} 473}
487EXPORT_SYMBOL_GPL(ide_pci_setup_ports); 474EXPORT_SYMBOL_GPL(ide_pci_setup_ports);
@@ -554,7 +541,7 @@ out:
554 541
555int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d) 542int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d)
556{ 543{
557 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; 544 struct ide_host *host;
558 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL }; 545 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
559 int ret; 546 int ret;
560 547
@@ -562,9 +549,11 @@ int ide_setup_pci_device(struct pci_dev *dev, const struct ide_port_info *d)
562 549
563 if (ret >= 0) { 550 if (ret >= 0) {
564 /* FIXME: silent failure can happen */ 551 /* FIXME: silent failure can happen */
565 ide_pci_setup_ports(dev, d, ret, &idx[0], &hw[0], &hws[0]); 552 ide_pci_setup_ports(dev, d, ret, &hw[0], &hws[0]);
566 553
567 ide_device_add(idx, d, hws); 554 host = ide_host_alloc(d, hws);
555 if (host)
556 ide_host_register(host, d, hws);
568 } 557 }
569 558
570 return ret; 559 return ret;
@@ -575,9 +564,9 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
575 const struct ide_port_info *d) 564 const struct ide_port_info *d)
576{ 565{
577 struct pci_dev *pdev[] = { dev1, dev2 }; 566 struct pci_dev *pdev[] = { dev1, dev2 };
567 struct ide_host *host;
578 int ret, i; 568 int ret, i;
579 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL }; 569 hw_regs_t hw[4], *hws[] = { NULL, NULL, NULL, NULL };
580 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
581 570
582 for (i = 0; i < 2; i++) { 571 for (i = 0; i < 2; i++) {
583 ret = do_ide_setup_pci_device(pdev[i], d, !i); 572 ret = do_ide_setup_pci_device(pdev[i], d, !i);
@@ -590,11 +579,12 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
590 goto out; 579 goto out;
591 580
592 /* FIXME: silent failure can happen */ 581 /* FIXME: silent failure can happen */
593 ide_pci_setup_ports(pdev[i], d, ret, &idx[i*2], &hw[i*2], 582 ide_pci_setup_ports(pdev[i], d, ret, &hw[i*2], &hws[i*2]);
594 &hws[i*2]);
595 } 583 }
596 584
597 ide_device_add(idx, d, hws); 585 host = ide_host_alloc(d, hws);
586 if (host)
587 ide_host_register(host, d, hws);
598out: 588out:
599 return ret; 589 return ret;
600} 590}