Skip to contentSkip to conversation

runtime platform detection in GENERIC kernels

Linux-ia64 Martin Hicks 3 participants 7 messages May 14, 2003 – May 20, 2003

lore
Share & tools
lore
#0 lore raw

Hello,

In the process of trying to get a GENERIC kernel running on SGI SN2 hardware we've run into a few instances where knowing what type of machine we are running on is useful. Would it be acceptable to make a macro such as is_sgi_sn2() to check this?

One of the specific situations is in console_init() (drivers/char/tty_io.c) where SN2 machines must use the sgi-l1_protocol driver and the rest of the IA64 machines just use the normal serial driver. A small check was added:

        mac_scc_console_init();
 #elif defined(CONFIG_PARISC)
        pdc_console_init();

+#elif defined(CONFIG_IA64_GENERIC)
+ if (is_sgi_sn2())
+ sgi_l1_serial_console_init();
+ else
+ serial_console_init();
#elif defined(CONFIG_SERIAL)

        serial_console_init();

#endif /* CONFIG_8xx */

The current patch is attached. It's a first draft. I'm looking comments on whether this (or something like it) has any chance of being accepted, and if so, any comments on the design of the facility.

mh

Signature · 60 lines
Wild Open Source Inc.                  [email protected]



===========================================================================
Index: linux/arch/ia64/kernel/setup.c
===========================================================================

--- /usr/tmp/TmpDir.30939-0/linux/arch/ia64/kernel/setup.c_1.33	Tue May 13 14:41:50 2003
+++ linux/arch/ia64/kernel/setup.c	Tue May 13 14:38:08 2003
@@ -63,6 +63,8 @@
  struct cpuinfo_ia64 _cpu_data[NR_CPUS] __attribute__ ((section ("__special_page_section")));
 #endif
 
+int machine_is_sgi_sn2;
+
 unsigned long ia64_cycles_per_usec;
 struct ia64_boot_param *ia64_boot_param;
 struct screen_info screen_info;
@@ -446,7 +448,11 @@
 	ia64_sal_init(efi.sal_systab);
 
 #ifdef CONFIG_IA64_GENERIC
-	machvec_init(acpi_get_sysname());
+	{
+		char *str = acpi_get_sysname();
+		machvec_init(str);
+		init_is_sgi_sn2(str);
+	}
 #endif
 
 	/*

===========================================================================
Index: linux/include/asm-ia64/system.h
===========================================================================

--- /usr/tmp/TmpDir.30939-0/linux/include/asm-ia64/system.h_1.25	Tue May 13 14:41:50 2003
+++ linux/include/asm-ia64/system.h	Tue May 13 14:40:26 2003
@@ -445,6 +445,20 @@
 #define task_running(rq, p)    (((rq)->curr == (p)) || spin_is_locked(&(p)->switch_lock))
 #define idle_needs_wakeup	0
 
+#ifdef CONFIG_IA64_GENERIC
+extern int machine_is_sgi_sn2;
+#define init_is_sgi_sn2(str) do { 		\
+	if (!strcmp(str,"sn2"))			\
+		machine_is_sgi_sn2=1;		\
+  } while (0)
+
+#define is_sgi_sn2() 	(machine_is_sgi_sn2)
+#elif CONFIG_IA64_SGI_SN
+#define is_sgi_sn2()	1
+#else
+#define is_sgi_sn2()	0
+#endif /* CONFIG_IA64_GENERIC */
+
 #endif /* __KERNEL__ */
 
 #endif /* __ASSEMBLY__ */
#1 lore raw

Why not just make a runtime strcmp to platform_name? Then
you could make a generic is_platform("sn2") type function/macro that everyone could use and you'd get rid of that nasty init function. If you realy need to make such a check in a perfmance path, it should probably be a machvec. Thanks,

Alex

Quoted 100 lines

Hello,

In the process of trying to get a GENERIC kernel running on SGI SN2 hardware we've run into a few instances where knowing what type of machine we are running on is useful. Would it be acceptable to make a macro such as is_sgi_sn2() to check this?

One of the specific situations is in console_init() (drivers/char/tty_io.c) where SN2 machines must use the sgi-l1_protocol driver and the rest of the IA64 machines just use the normal serial driver. A small check was added:

        mac_scc_console_init();
 #elif defined(CONFIG_PARISC)
        pdc_console_init();
(quoted diff) +5 -0
+#elif defined(CONFIG_IA64_GENERIC)
+       if (is_sgi_sn2())
+               sgi_l1_serial_console_init();
+       else
+               serial_console_init();
 #elif defined(CONFIG_SERIAL)
        serial_console_init();
 #endif /* CONFIG_8xx */

The current patch is attached. It's a first draft. I'm looking comments on whether this (or something like it) has any chance of being accepted, and if so, any comments on the design of the facility.

mh

Signature · 11 lines
Wild Open Source Inc.                  [email protected]



====================================
=> Index: linux/arch/ia64/kernel/setup.c
====================================
=> 
--- /usr/tmp/TmpDir.30939-0/linux/arch/ia64/kernel/setup.c_1.33	Tue May
13 14:41:50 2003
+++ linux/arch/ia64/kernel/setup.c	Tue May 13 14:38:08 2003
(quoted diff) +2 -0
@@ -63,6 +63,8 @@
  struct cpuinfo_ia64 _cpu_data[NR_CPUS] __attribute__ ((section
 ("__special_page_section")));
 #endif
 
+int machine_is_sgi_sn2;
+
 unsigned long ia64_cycles_per_usec;
 struct ia64_boot_param *ia64_boot_param;

struct screen_info screen_info;

(quoted diff) +5 -1
@@ -446,7 +448,11 @@
 	ia64_sal_init(efi.sal_systab);
 
 #ifdef CONFIG_IA64_GENERIC
-	machvec_init(acpi_get_sysname());
+	{
+		char *str = acpi_get_sysname();
+		machvec_init(str);
+		init_is_sgi_sn2(str);
+	}
 #endif
 
 	/*

====================================
=> Index: linux/include/asm-ia64/system.h
====================================
=>
--- /usr/tmp/TmpDir.30939-0/linux/include/asm-ia64/system.h_1.25 Tue May 13 14:41:50 2003
+++ linux/include/asm-ia64/system.h Tue May 13 14:40:26 2003

(quoted diff) +14 -0
@@ -445,6 +445,20 @@
 #define task_running(rq, p)    (((rq)->curr = (p)) ||
 spin_is_locked(&(p)->switch_lock))
 #define idle_needs_wakeup	0
 
+#ifdef CONFIG_IA64_GENERIC
+extern int machine_is_sgi_sn2;
+#define init_is_sgi_sn2(str) do { 		\
+	if (!strcmp(str,"sn2"))			\
+		machine_is_sgi_sn2=1;		\
+  } while (0)
+
+#define is_sgi_sn2() 	(machine_is_sgi_sn2)
+#elif CONFIG_IA64_SGI_SN
+#define is_sgi_sn2()	1
+#else
+#define is_sgi_sn2()	0
+#endif /* CONFIG_IA64_GENERIC */
+
 #endif /* __KERNEL__ */
 

#endif /* __ASSEMBLY__ */

#2 lore raw
In reply to Martin Hicks
Quoted 6 lines · Alex Williamson

Why not just make a runtime strcmp to platform_name? Then
you could make a generic is_platform("sn2") type function/macro that everyone could use and you'd get rid of that nasty init function. If you realy need to make such a check in a perfmance path, it should probably be a machvec. Thanks,

That sounds fine to me. I was certainly aiming to keep this in non-performance critical regions. I'd actually like to restrict its use to init decisions, such as which serial console driver to use.

mh

Signature · 1 line
Wild Open Source Inc.                  [email protected]
#3 lore raw
In reply to Martin Hicks
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Alex" = Alex Williamson <[email protected]> writes:

Alex> Why not just make a runtime strcmp to platform_name? Then
Alex> you could make a generic is_platform("sn2") type function/macro Alex> that everyone could use and you'd get rid of that nasty init Alex> function. If you realy need to make such a check in a perfmance Alex> path, it should probably be a machvec. Thanks,

Hi Alex,

I think the main reason for this was to cache the strcmp result in an integer to make it faster.

Cheers,
Jes

#4 lore raw
In reply to Martin Hicks
Quoted 7 lines · Alex Williamson

Why not just make a runtime strcmp to platform_name? Then
you could make a generic is_platform("sn2") type function/macro that everyone could use and you'd get rid of that nasty init function. If you realy need to make such a check in a perfmance path, it should probably be a machvec. Thanks,

Here is the next iteration, based on your suggestions. It also caches the result of the first acpi_get_sysname() call, since this really shouldn't change while the machine is running.

This is against the linux-ia64-2.5 bk tree.

It does include the sn2 platform detection in acpi_get_sysname(), which may be duplicated in jbarnes' 2.5 patch.

mh

Signature · 78 lines
Wild Open Source Inc.                  [email protected]


=== arch/ia64/kernel/acpi.c 1.40 vs edited ==--- 1.40/arch/ia64/kernel/acpi.c	Sat May 10 03:28:45 2003
+++ edited/arch/ia64/kernel/acpi.c	Fri May 16 17:23:28 2003
@@ -73,31 +73,43 @@
 	struct acpi20_table_rsdp *rsdp;
 	struct acpi_table_xsdt *xsdt;
 	struct acpi_table_header *hdr;
+	static char *sysname;
+
+	if (sysname)
+		return sysname;
 
 	rsdp_phys = acpi_find_rsdp();
 	if (!rsdp_phys) {
 		printk(KERN_ERR "ACPI 2.0 RSDP not found, default to \"dig\"\n");
-		return "dig";
+		sysname = "dig";
+		return sysname;
 	}
 
 	rsdp = (struct acpi20_table_rsdp *) __va(rsdp_phys);
 	if (strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1)) {
 		printk(KERN_ERR "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
-		return "dig";
+		sysname = "dig";
+		return sysname;
 	}
 
 	xsdt = (struct acpi_table_xsdt *) __va(rsdp->xsdt_address);
 	hdr = &xsdt->header;
 	if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1)) {
 		printk(KERN_ERR "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
-		return "dig";
+		sysname = "dig";
+		return sysname;
 	}
 
 	if (!strcmp(hdr->oem_id, "HP")) {
-		return "hpzx1";
+		sysname = "hpzx1";
+		return sysname;
+	} else if (!strcmp(hdr->oem_id, "SGI")) {
+		sysname = "sn2";
+		return sysname;
 	}
 
-	return "dig";
+	sysname = "sn2";
+	return sysname;
 #else
 # if defined (CONFIG_IA64_HP_SIM)
 	return "hpsim";
=== include/asm-ia64/system.h 1.37 vs edited ==--- 1.37/include/asm-ia64/system.h	Thu May 15 05:45:02 2003
+++ edited/include/asm-ia64/system.h	Fri May 16 16:50:51 2003
@@ -29,6 +29,7 @@
 
 #include <linux/kernel.h>
 #include <linux/types.h>
+#include <linux/string.h>
 
 struct pci_vector_struct {
 	__u16 segment;	/* PCI Segment number */
@@ -275,6 +276,14 @@
 } while (0)
 #define finish_arch_switch(rq, prev)	spin_unlock_irq(&(prev)->switch_lock)
 #define task_running(rq, p) 		((rq)->curr = (p) || spin_is_locked(&(p)->switch_lock))
+
+extern const char * acpi_get_sysname(void);
+static inline int ia64_platform_is(const char *str) 
+{
+	if (!strcmp(str,acpi_get_sysname()))	
+		return 1;
+	return 0;
+}
 
 #endif /* __KERNEL__ */
#5 lore raw
In reply to Martin Hicks
Quoted 4 lines · Martin Hicks

Here is the next iteration, based on your suggestions. It also caches the result of the first acpi_get_sysname() call, since this really shouldn't change while the machine is running.

Martin,

Everything is already in place to make this much easier.
I was thinking something more like this:

#define ia64_platform_is(x) (strcmp(x,platform_name) = 0)

The name is stored in the machvec, so you don't need to cache it anywhere else.

Alex

--
Alex Williamson HP Linux & Open Source Lab

#6 lore raw
In reply to Martin Hicks
Quoted 8 lines · Alex Williamson
Quoted 4 lines · Martin Hicks

Here is the next iteration, based on your suggestions. It also caches the result of the first acpi_get_sysname() call, since this really shouldn't change while the machine is running.

Martin,

Quoted 7 lines

Everything is already in place to make this much easier.
I was thinking something more like this:

#define ia64_platform_is(x) (strcmp(x,platform_name) = 0)

The name is stored in the machvec, so you don't need to cache it anywhere else.

Patch attached against Bjorn's 2.4 bk tree.

Signature · 35 lines
Wild Open Source Inc.                  [email protected]

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.1122  -> 1.1123 
#	include/asm-ia64/system.h	1.15    -> 1.16   
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/05/20	[email protected]	1.1123
# Add a small macro ia64_platform_is(platform) which checks
# if the platform is indeed "platform".
# --------------------------------------------
#
diff -Nru a/include/asm-ia64/system.h b/include/asm-ia64/system.h
--- a/include/asm-ia64/system.h	Tue May 20 19:54:44 2003
+++ b/include/asm-ia64/system.h	Tue May 20 19:54:44 2003
@@ -27,6 +27,7 @@
 
 #include <linux/kernel.h>
 #include <linux/types.h>
+#include <linux/string.h>
 
 struct pci_vector_struct {
 	__u16 segment;	/* PCI Segment number */
@@ -290,6 +291,8 @@
 	__switch_to(prev,next,last);					\
 } while (0)
 #endif
+
+#define ia64_platform_is(x) (!strcmp(x, platform_name))
 
 #endif /* __KERNEL__ */