Skip to content

Commit fe80b93

Browse files
committed
ide: merge ide_match_hwif() and ide_find_port()
* Change ide_match_hwif() argument from 'u8 bootable' to 'struct ide_port_info *d'. * Move ide_match_hwif() to ide-probe.c from setup-pci.c and rename it to ide_find_port_slot(). Update some comments while at it. * ide_find_port() can be now just a wrapper for ide_find_port_slot(). There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 078fdf7 commit fe80b93

4 files changed

Lines changed: 54 additions & 63 deletions

File tree

‎drivers/ide/ide-probe.c‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,52 @@ static int ide_sysfs_register_port(ide_hwif_t *hwif)
14441444
return rc;
14451445
}
14461446

1447+
/**
1448+
* ide_find_port_slot - find free ide_hwifs[] slot
1449+
* @d: IDE port info
1450+
*
1451+
* Return the new hwif. If we are out of free slots return NULL.
1452+
*/
1453+
1454+
ide_hwif_t *ide_find_port_slot(const struct ide_port_info *d)
1455+
{
1456+
ide_hwif_t *hwif;
1457+
int i;
1458+
u8 bootable = (d && (d->host_flags & IDE_HFLAG_NON_BOOTABLE)) ? 0 : 1;
1459+
1460+
/*
1461+
* Claim an unassigned slot.
1462+
*
1463+
* Give preference to claiming other slots before claiming ide0/ide1,
1464+
* just in case there's another interface yet-to-be-scanned
1465+
* which uses ports 0x1f0/0x170 (the ide0/ide1 defaults).
1466+
*
1467+
* Unless there is a bootable card that does not use the standard
1468+
* ports 0x1f0/0x170 (the ide0/ide1 defaults).
1469+
*/
1470+
if (bootable) {
1471+
for (i = 0; i < MAX_HWIFS; i++) {
1472+
hwif = &ide_hwifs[i];
1473+
if (hwif->chipset == ide_unknown)
1474+
return hwif;
1475+
}
1476+
} else {
1477+
for (i = 2; i < MAX_HWIFS; i++) {
1478+
hwif = &ide_hwifs[i];
1479+
if (hwif->chipset == ide_unknown)
1480+
return hwif;
1481+
}
1482+
for (i = 0; i < 2 && i < MAX_HWIFS; i++) {
1483+
hwif = &ide_hwifs[i];
1484+
if (hwif->chipset == ide_unknown)
1485+
return hwif;
1486+
}
1487+
}
1488+
1489+
return NULL;
1490+
}
1491+
EXPORT_SYMBOL_GPL(ide_find_port_slot);
1492+
14471493
int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
14481494
{
14491495
ide_hwif_t *hwif, *mate = NULL;

‎drivers/ide/ide.c‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,6 @@ static int ide_system_bus_speed(void)
232232
return pci_dev_present(pci_default) ? 33 : 50;
233233
}
234234

235-
ide_hwif_t *ide_find_port(void)
236-
{
237-
ide_hwif_t *hwif;
238-
int i;
239-
240-
for (i = 0; i < MAX_HWIFS; i++) {
241-
hwif = &ide_hwifs[i];
242-
if (hwif->chipset == ide_unknown)
243-
return hwif;
244-
}
245-
246-
return NULL;
247-
}
248-
EXPORT_SYMBOL_GPL(ide_find_port);
249-
250235
static struct resource* hwif_request_region(ide_hwif_t *hwif,
251236
unsigned long addr, int num)
252237
{

‎drivers/ide/setup-pci.c‎

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,6 @@
2020
#include <asm/io.h>
2121
#include <asm/irq.h>
2222

23-
24-
/**
25-
* ide_match_hwif - find free ide_hwifs[] slot
26-
* @bootable: bootable flag
27-
*
28-
* Return the new hwif. If we are out of free slots return NULL.
29-
*/
30-
31-
static ide_hwif_t *ide_match_hwif(u8 bootable)
32-
{
33-
ide_hwif_t *hwif;
34-
int h;
35-
36-
/*
37-
* Claim an unassigned slot.
38-
*
39-
* Give preference to claiming other slots before claiming ide0/ide1,
40-
* just in case there's another interface yet-to-be-scanned
41-
* which uses ports 1f0/170 (the ide0/ide1 defaults).
42-
*
43-
* Unless there is a bootable card that does not use the standard
44-
* ports 1f0/170 (the ide0/ide1 defaults). The (bootable) flag.
45-
*/
46-
if (bootable) {
47-
for (h = 0; h < MAX_HWIFS; ++h) {
48-
hwif = &ide_hwifs[h];
49-
if (hwif->chipset == ide_unknown)
50-
return hwif; /* pick an unused entry */
51-
}
52-
} else {
53-
for (h = 2; h < MAX_HWIFS; ++h) {
54-
hwif = ide_hwifs + h;
55-
if (hwif->chipset == ide_unknown)
56-
return hwif; /* pick an unused entry */
57-
}
58-
}
59-
for (h = 0; h < 2 && h < MAX_HWIFS; ++h) {
60-
hwif = ide_hwifs + h;
61-
if (hwif->chipset == ide_unknown)
62-
return hwif; /* pick an unused entry */
63-
}
64-
65-
return NULL;
66-
}
67-
6823
/**
6924
* ide_setup_pci_baseregs - place a PCI IDE controller native
7025
* @dev: PCI device of interface to switch native
@@ -320,7 +275,6 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
320275
{
321276
unsigned long ctl = 0, base = 0;
322277
ide_hwif_t *hwif;
323-
u8 bootable = (d->host_flags & IDE_HFLAG_NON_BOOTABLE) ? 0 : 1;
324278
struct hw_regs_s hw;
325279

326280
if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) {
@@ -346,7 +300,7 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev,
346300
base = port ? 0x170 : 0x1f0;
347301
}
348302

349-
hwif = ide_match_hwif(bootable);
303+
hwif = ide_find_port_slot(d);
350304
if (hwif == NULL) {
351305
printk(KERN_ERR "%s: too many IDE interfaces, no room in "
352306
"table\n", d->name);

‎include/linux/ide.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ typedef struct hw_regs_s {
170170
struct device *dev;
171171
} hw_regs_t;
172172

173-
struct hwif_s *ide_find_port(void);
174173
void ide_init_port_data(struct hwif_s *, unsigned int);
175174
void ide_init_port_hw(struct hwif_s *, hw_regs_t *);
176175

@@ -809,6 +808,13 @@ extern ide_hwif_t ide_hwifs[]; /* master data repository */
809808
#endif
810809
extern int noautodma;
811810

811+
ide_hwif_t *ide_find_port_slot(const struct ide_port_info *);
812+
813+
static inline ide_hwif_t *ide_find_port(void)
814+
{
815+
return ide_find_port_slot(NULL);
816+
}
817+
812818
extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs);
813819
int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
814820
int uptodate, int nr_sectors);

0 commit comments

Comments
 (0)