patch-2.4.22 linux-2.4.22/arch/sparc64/kernel/pci.c

Next file: linux-2.4.22/arch/sparc64/kernel/pci_sabre.c
Previous file: linux-2.4.22/arch/sparc64/kernel/ioctl32.c
Back to the patch index
Back to the overall index

diff -urN linux-2.4.21/arch/sparc64/kernel/pci.c linux-2.4.22/arch/sparc64/kernel/pci.c
@@ -97,7 +97,7 @@
 #define PCI_NUM_CONTROLLER_TYPES (sizeof(pci_controller_table) / \
 				  sizeof(pci_controller_table[0]))
 
-static void pci_controller_init(char *model_name, int namelen, int node)
+static int pci_controller_init(char *model_name, int namelen, int node)
 {
 	int i;
 
@@ -106,43 +106,83 @@
 			     pci_controller_table[i].model_name,
 			     namelen)) {
 			pci_controller_table[i].init(node, model_name);
-			return;
+			return 1;
 		}
 	}
 	printk("PCI: Warning unknown controller, model name [%s]\n",
 	       model_name);
 	printk("PCI: Ignoring controller...\n");
+
+	return 0;
 }
 
-/* Find each controller in the system, attach and initialize
- * software state structure for each and link into the
- * pci_controller_root.  Setup the controller enough such
- * that bus scanning can be done.
- */
-static void pci_controller_probe(void)
+static int pci_is_controller(char *model_name, int namelen, int node)
+{
+	int i;
+
+	for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) {
+		if (!strncmp(model_name,
+			     pci_controller_table[i].model_name,
+			     namelen)) {
+			return 1;
+		}
+	}
+	return 0;
+}
+
+
+static int pci_controller_scan(int (*handler)(char *, int, int))
 {
-	char namebuf[16];
+	char namebuf[64];
 	int node;
+	int count = 0;
 
-	printk("PCI: Probing for controllers.\n");
 	node = prom_getchild(prom_root_node);
 	while ((node = prom_searchsiblings(node, "pci")) != 0) {
 		int len;
 
-		len = prom_getproperty(node, "model",
-				       namebuf, sizeof(namebuf));
-		if (len > 0)
-			pci_controller_init(namebuf, len, node);
-		else {
-			len = prom_getproperty(node, "compatible",
-					       namebuf, sizeof(namebuf));
-			if (len > 0)
-				pci_controller_init(namebuf, len, node);
+		if ((len = prom_getproperty(node, "model", namebuf, sizeof(namebuf))) > 0 ||
+		    (len = prom_getproperty(node, "compatible", namebuf, sizeof(namebuf))) > 0) {
+			int item_len = 0;
+
+			/* Our value may be a multi-valued string in the
+			 * case of some compatible properties. For sanity,
+			 * only try the first one. */
+
+			while (namebuf[item_len] && len) {
+				len--;
+				item_len++;
+			}
+
+			if (handler(namebuf, item_len, node))
+				count++;
 		}
+
 		node = prom_getsibling(node);
 		if (!node)
 			break;
 	}
+
+	return count;
+}
+
+
+/* Is there some PCI controller in the system?  */
+int pcic_present(void)
+{
+	return pci_controller_scan(pci_is_controller);
+}
+
+/* Find each controller in the system, attach and initialize
+ * software state structure for each and link into the
+ * pci_controller_root.  Setup the controller enough such
+ * that bus scanning can be done.
+ */
+static void pci_controller_probe(void)
+{
+	printk("PCI: Probing for controllers.\n");
+
+	pci_controller_scan(pci_controller_init);
 }
 
 static void pci_scan_each_controller_bus(void)

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)