hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/macintosh/macio_asic.c
....@@ -1,14 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Bus & driver management routines for devices within
34 * a MacIO ASIC. Interface to new driver model mostly
45 * stolen from the PCI version.
56 *
67 * Copyright (C) 2005 Ben. Herrenschmidt (benh@kernel.crashing.org)
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU General Public License
10
- * as published by the Free Software Foundation; either version
11
- * 2 of the License, or (at your option) any later version.
128 *
139 * TODO:
1410 *
....@@ -190,11 +186,11 @@
190186 return 0;
191187
192188 /* Grand Central has too large resource 0 on some machines */
193
- if (index == 0 && !strcmp(np->name, "gc"))
189
+ if (index == 0 && of_node_name_eq(np, "gc"))
194190 res->end = res->start + 0x1ffff;
195191
196192 /* Airport has bogus resource 2 */
197
- if (index >= 2 && !strcmp(np->name, "radio"))
193
+ if (index >= 2 && of_node_name_eq(np, "radio"))
198194 return 1;
199195
200196 #ifndef CONFIG_PPC64
....@@ -207,21 +203,21 @@
207203 * level of hierarchy, but I don't really feel the need
208204 * for it
209205 */
210
- if (!strcmp(np->name, "escc"))
206
+ if (of_node_name_eq(np, "escc"))
211207 return 1;
212208
213209 /* ESCC has bogus resources >= 3 */
214
- if (index >= 3 && !(strcmp(np->name, "ch-a") &&
215
- strcmp(np->name, "ch-b")))
210
+ if (index >= 3 && (of_node_name_eq(np, "ch-a") ||
211
+ of_node_name_eq(np, "ch-b")))
216212 return 1;
217213
218214 /* Media bay has too many resources, keep only first one */
219
- if (index > 0 && !strcmp(np->name, "media-bay"))
215
+ if (index > 0 && of_node_name_eq(np, "media-bay"))
220216 return 1;
221217
222218 /* Some older IDE resources have bogus sizes */
223
- if (!(strcmp(np->name, "IDE") && strcmp(np->name, "ATA") &&
224
- strcmp(np->type, "ide") && strcmp(np->type, "ata"))) {
219
+ if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") ||
220
+ of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) {
225221 if (index == 0 && (res->end - res->start) > 0xfff)
226222 res->end = res->start + 0xfff;
227223 if (index == 1 && (res->end - res->start) > 0xff)
....@@ -260,7 +256,7 @@
260256 irq_base = 64;
261257
262258 /* Fix SCC */
263
- if (strcmp(np->name, "ch-a") == 0) {
259
+ if (of_node_name_eq(np, "ch-a")) {
264260 macio_create_fixup_irq(dev, 0, 15 + irq_base);
265261 macio_create_fixup_irq(dev, 1, 4 + irq_base);
266262 macio_create_fixup_irq(dev, 2, 5 + irq_base);
....@@ -268,18 +264,18 @@
268264 }
269265
270266 /* Fix media-bay */
271
- if (strcmp(np->name, "media-bay") == 0) {
267
+ if (of_node_name_eq(np, "media-bay")) {
272268 macio_create_fixup_irq(dev, 0, 29 + irq_base);
273269 printk(KERN_INFO "macio: fixed media-bay irq on gatwick\n");
274270 }
275271
276272 /* Fix left media bay childs */
277
- if (dev->media_bay != NULL && strcmp(np->name, "floppy") == 0) {
273
+ if (dev->media_bay != NULL && of_node_name_eq(np, "floppy")) {
278274 macio_create_fixup_irq(dev, 0, 19 + irq_base);
279275 macio_create_fixup_irq(dev, 1, 1 + irq_base);
280276 printk(KERN_INFO "macio: fixed left floppy irqs\n");
281277 }
282
- if (dev->media_bay != NULL && strcasecmp(np->name, "ata4") == 0) {
278
+ if (dev->media_bay != NULL && of_node_name_eq(np, "ata4")) {
283279 macio_create_fixup_irq(dev, 0, 14 + irq_base);
284280 macio_create_fixup_irq(dev, 0, 3 + irq_base);
285281 printk(KERN_INFO "macio: fixed left ide irqs\n");
....@@ -360,9 +356,10 @@
360356 struct macio_dev *in_bay,
361357 struct resource *parent_res)
362358 {
359
+ char name[MAX_NODE_NAME_SIZE + 1];
363360 struct macio_dev *dev;
364361 const u32 *reg;
365
-
362
+
366363 if (np == NULL)
367364 return NULL;
368365
....@@ -385,7 +382,7 @@
385382 dma_set_max_seg_size(&dev->ofdev.dev, 65536);
386383 dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff);
387384
388
-#ifdef CONFIG_PCI
385
+#if defined(CONFIG_PCI) && defined(CONFIG_DMA_OPS)
389386 /* Set the DMA ops to the ones from the PCI device, this could be
390387 * fishy if we didn't know that on PowerMac it's always direct ops
391388 * or iommu ops that will work fine
....@@ -394,7 +391,7 @@
394391 */
395392 dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata;
396393 dev->ofdev.dev.dma_ops = chip->lbus.pdev->dev.dma_ops;
397
-#endif /* CONFIG_PCI */
394
+#endif /* CONFIG_PCI && CONFIG_DMA_OPS */
398395
399396 #ifdef DEBUG
400397 printk("preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n",
....@@ -402,6 +399,7 @@
402399 #endif
403400
404401 /* MacIO itself has a different reg, we use it's PCI base */
402
+ snprintf(name, sizeof(name), "%pOFn", np);
405403 if (np == chip->of_node) {
406404 dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s",
407405 chip->lbus.index,
....@@ -410,12 +408,12 @@
410408 #else
411409 0, /* NuBus may want to do something better here */
412410 #endif
413
- MAX_NODE_NAME_SIZE, np->name);
411
+ MAX_NODE_NAME_SIZE, name);
414412 } else {
415413 reg = of_get_property(np, "reg", NULL);
416414 dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s",
417415 chip->lbus.index,
418
- reg ? *reg : 0, MAX_NODE_NAME_SIZE, np->name);
416
+ reg ? *reg : 0, MAX_NODE_NAME_SIZE, name);
419417 }
420418
421419 /* Setup interrupts & resources */
....@@ -436,11 +434,8 @@
436434
437435 static int macio_skip_device(struct device_node *np)
438436 {
439
- if (strncmp(np->name, "battery", 7) == 0)
440
- return 1;
441
- if (strncmp(np->name, "escc-legacy", 11) == 0)
442
- return 1;
443
- return 0;
437
+ return of_node_name_prefix(np, "battery") ||
438
+ of_node_name_prefix(np, "escc-legacy");
444439 }
445440
446441 /**
....@@ -487,9 +482,9 @@
487482 root_res);
488483 if (mdev == NULL)
489484 of_node_put(np);
490
- else if (strncmp(np->name, "media-bay", 9) == 0)
485
+ else if (of_node_name_prefix(np, "media-bay"))
491486 mbdev = mdev;
492
- else if (strncmp(np->name, "escc", 4) == 0)
487
+ else if (of_node_name_prefix(np, "escc"))
493488 sdev = mdev;
494489 }
495490