Skip to contentSkip to conversation

sal cleanup

PATCH In review Matthew Wilcox 3 participants 22 messages Feb 26, 2004 – Mar 3, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sal cleanup

This patch reorganises sal.c and adds two new functions:

- Split the body of the switch statement in ia64_sal_init() into separate functions.
- Delete min/max since they were only assigned to, never used.
- Print the version of the SAL implementation as well as the spec version it supports.
- Stop printing the pal_proc and sal_proc entry addresses.
- Don't print the SAL platform features line if there's no features.
- Remember the sal revision and version and add two functions to compare them.

Index: arch/ia64/kernel/sal.c
=================================RCS file: /var/cvs/linux-2.6/arch/ia64/kernel/sal.c,v retrieving revision 1.1

arch/ia64/kernel/sal.c +120 -73
diff -u -p -r1.1 sal.c
@@ -8,9 +8,9 @@
  */
 #include <linux/config.h>
 
+#include <linux/bcd.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
-#include <linux/smp.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
 
@@ -21,6 +21,9 @@
 spinlock_t sal_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
 unsigned long sal_platform_features;
 
+int sal_rev_major, sal_rev_minor;
+int sal_b_rev_major, sal_b_rev_minor;
+
 static struct {
 	void *addr;	/* function entry point */
 	void *gpval;	/* gp value to use */
@@ -86,13 +89,70 @@ ia64_sal_handler_init (void *entry_point
 	ia64_sal = (ia64_sal_handler) &pdesc;
 }
 
+static void __init sal_desc_entry_point(void *p)
+{
+	struct ia64_sal_desc_entry_point *ep = p;
+	ia64_pal_handler_init(__va(ep->pal_proc));
+	ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+}
+
+static void __init sal_desc_platform_feature(void *p)
+{
+	struct ia64_sal_desc_platform_feature *pf = p;
+	sal_platform_features = pf->feature_mask;
+	if (!sal_platform_features)
+		return;
+
+	printk(KERN_INFO "SAL: Platform features");
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
+		printk(" BusLock");
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
+		printk(" IRQ_Redirection");
+#ifdef CONFIG_SMP
+		if (no_int_routing)
+			smp_int_redirect &= ~SMP_IRQ_REDIRECTION;
+		else
+			smp_int_redirect |= SMP_IRQ_REDIRECTION;
+#endif
+	}
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
+		printk(" IPI_Redirection");
+#ifdef CONFIG_SMP
+		if (no_int_routing)
+			smp_int_redirect &= ~SMP_IPI_REDIRECTION;
+		else
+			smp_int_redirect |= SMP_IPI_REDIRECTION;
+#endif
+	}
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
+		printk(" ITC_Drift");
+	printk("\n");
+}
+
+#ifdef CONFIG_SMP
+static void __init sal_desc_ap_wakeup(void *p)
+{
+	struct ia64_sal_desc_ap_wakeup *ap = p;
+	
+	switch (ap->mechanism) {
+	case IA64_SAL_AP_EXTERNAL_INT:
+		ap_wakeup_vector = ap->vector;
+		printk(KERN_INFO "SAL: AP wakeup using external interrupt "
+				"vector 0x%lx\n", ap_wakeup_vector);
+		break;
+	default:
+		printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
+		break;
+	}
+}
+#else
+static void __init sal_desc_ap_wakeup(void *p) { }
+#endif
 
 void __init
 ia64_sal_init (struct ia64_sal_systab *systab)
 {
-	unsigned long min, max;
 	char *p;
-	struct ia64_sal_desc_entry_point *ep;
 	int i;
 
 	if (!systab) {
@@ -103,86 +163,73 @@ ia64_sal_init (struct ia64_sal_systab *s
 	if (strncmp(systab->signature, "SST_", 4) != 0)
 		printk(KERN_ERR "bad signature in system table!");
 
-	/*
-	 * revisions are coded in BCD, so %x does the job for us
-	 */
-	printk(KERN_INFO "SAL v%x.%02x: oem=%.32s, product=%.32s\n",
-	       systab->sal_rev_major, systab->sal_rev_minor,
-	       systab->oem_id, systab->product_id);
-
-	min = ~0UL;
-	max = 0;
+	sal_rev_major = BCD2BIN(systab->sal_rev_major);
+	sal_rev_minor = BCD2BIN(systab->sal_rev_minor);
+	sal_b_rev_major = BCD2BIN(systab->sal_b_rev_major);
+	sal_b_rev_minor = BCD2BIN(systab->sal_b_rev_minor);
+
+	printk(KERN_INFO "SAL %d.%d: oem=%.32s, product=%.32s, version %d.%d\n",
+			sal_rev_major, sal_rev_minor, systab->oem_id,
+			systab->product_id, sal_b_rev_major, sal_b_rev_minor);
 
 	p = (char *) (systab + 1);
 	for (i = 0; i < systab->entry_count; i++) {
 		/*
-		 * The first byte of each entry type contains the type descriptor.
+		 * The first byte of each entry type contains the type
+		 * descriptor.
 		 */
 		switch (*p) {
-		      case SAL_DESC_ENTRY_POINT:
-			ep = (struct ia64_sal_desc_entry_point *) p;
-			printk(KERN_INFO "SAL: entry: pal_proc=0x%lx, sal_proc=0x%lx\n",
-			       ep->pal_proc, ep->sal_proc);
-			ia64_pal_handler_init(__va(ep->pal_proc));
-			ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+		case SAL_DESC_ENTRY_POINT:
+			sal_desc_entry_point(p);
 			break;
-
-		      case SAL_DESC_PTC:
+		case SAL_DESC_PLATFORM_FEATURE:
+			sal_desc_platform_feature(p);
+			break;
+		case SAL_DESC_PTC:
 			ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
 			break;
-
-		      case SAL_DESC_AP_WAKEUP:
-#ifdef CONFIG_SMP
-		      {
-			      struct ia64_sal_desc_ap_wakeup *ap = (void *) p;
-
-			      switch (ap->mechanism) {
-				    case IA64_SAL_AP_EXTERNAL_INT:
-				      ap_wakeup_vector = ap->vector;
-				      printk(KERN_INFO "SAL: AP wakeup using external interrupt "
-					     "vector 0x%lx\n", ap_wakeup_vector);
-				      break;
-
-				    default:
-				      printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
-				      break;
-			      }
-			      break;
-		      }
-#endif
-		      case SAL_DESC_PLATFORM_FEATURE:
-		      {
-			      struct ia64_sal_desc_platform_feature *pf = (void *) p;
-			      sal_platform_features = pf->feature_mask;
-			      printk(KERN_INFO "SAL: Platform features ");
-
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
-				      printk("BusLock ");
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
-				      printk("IRQ_Redirection ");
-#ifdef CONFIG_SMP
-				      if (no_int_routing)
-					      smp_int_redirect &= ~SMP_IRQ_REDIRECTION;
-				      else
-					      smp_int_redirect |= SMP_IRQ_REDIRECTION;
-#endif
-			      }
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
-				      printk("IPI_Redirection ");
-#ifdef CONFIG_SMP
-				      if (no_int_routing)
-					      smp_int_redirect &= ~SMP_IPI_REDIRECTION;
-				      else
-					      smp_int_redirect |= SMP_IPI_REDIRECTION;
-#endif
-			      }
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
-				      printk("ITC_Drift ");
-			      printk("\n");
-			      break;
- 		      }
-
+		case SAL_DESC_AP_WAKEUP:
+			sal_desc_ap_wakeup(p);
+			break;
 		}
 		p += SAL_DESC_SIZE(*p);
 	}
+}
+
+/**
+ * sal_check_revision - Check the revision of the SAL spec supported by firmware
+ * @major: The major number of the SAL spec
+ * @minor: The minor number of the SAL spec
+ *
+ * This function returns 1 if the SAL implementation on this machine
+ * supports the required revision.  Use it as:
+ *
+ * if (sal_check_revision(3, 2)) { ... }
+ */
+int sal_check_revision(int major, int minor)
+{
+	if (major < sal_rev_major)
+		return 1;
+	if (major > sal_rev_major)
+		return 0;
+	return (minor <= sal_rev_minor);
+}
+
+/**
+ * sal_check_version - Check what version of SAL is installed
+ * @major: The major number of the implementation
+ * @minor: The minor number of the implementation
+ *
+ * This function returns 1 if the version of the implementation of SAL is
+ * equal or higher than the required version.  You can only use this function
+ * if you already know what manufacturer your SAL comes from as every vendor
+ * may have a different version.
+ */
+int sal_check_version(int major, int minor)
+{
+	if (major < sal_b_rev_major)
+		return 1;
+	if (major > sal_b_rev_major)
+		return 0;
+	return (minor <= sal_b_rev_minor);
 }

Index: include/asm-ia64/sal.h
=================================RCS file: /var/cvs/linux-2.6/include/asm-ia64/sal.h,v retrieving revision 1.4

include/asm-ia64/sal.h +2 -0
diff -u -p -r1.4 sal.h
@@ -231,6 +231,8 @@ extern struct ia64_sal_desc_ptc *ia64_pt
 
 extern const char *ia64_sal_strerror (long status);
 extern void ia64_sal_init (struct ia64_sal_systab *sal_systab);
+extern int sal_check_revision(int major, int minor);
+extern int sal_check_version(int major, int minor);
 
 /* SAL information type encodings */
 enum {
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> - Don't print the SAL platform features line if there's no features.

How about printing "none" or something like that instead?

	--david
#2 lore raw
In reply to Matthew Wilcox
Quoted 1 line · David Mosberger

How about printing "none" or something like that instead?

Sure.

This patch reorganises sal.c and adds two new functions:

- Split the body of the switch statement in ia64_sal_init() into separate functions.
- Delete min/max since they were only assigned to, never used.
- Print the version of the SAL implementation as well as the spec version it supports.
- Stop printing the pal_proc and sal_proc entry addresses.
- Print "none" if there are no platform features.
- Remember the sal revision and version and add two functions to compare them.

Index: arch/ia64/kernel/sal.c
=================================RCS file: /var/cvs/linux-2.6/arch/ia64/kernel/sal.c,v retrieving revision 1.1

arch/ia64/kernel/sal.c +123 -73
diff -u -p -r1.1 sal.c
@@ -8,9 +8,9 @@
  */
 #include <linux/config.h>
 
+#include <linux/bcd.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
-#include <linux/smp.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
 
@@ -21,6 +21,9 @@
 spinlock_t sal_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
 unsigned long sal_platform_features;
 
+int sal_rev_major, sal_rev_minor;
+int sal_b_rev_major, sal_b_rev_minor;
+
 static struct {
 	void *addr;	/* function entry point */
 	void *gpval;	/* gp value to use */
@@ -86,13 +89,73 @@ ia64_sal_handler_init (void *entry_point
 	ia64_sal = (ia64_sal_handler) &pdesc;
 }
 
+static void __init sal_desc_entry_point(void *p)
+{
+	struct ia64_sal_desc_entry_point *ep = p;
+	ia64_pal_handler_init(__va(ep->pal_proc));
+	ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+}
+
+static void __init sal_desc_platform_feature(void *p)
+{
+	struct ia64_sal_desc_platform_feature *pf = p;
+	sal_platform_features = pf->feature_mask;
+
+	printk(KERN_INFO "SAL: Platform features");
+	if (!sal_platform_features) {
+		printk(" none\n");
+		return;
+	}
+
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
+		printk(" BusLock");
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
+		printk(" IRQ_Redirection");
+#ifdef CONFIG_SMP
+		if (no_int_routing)
+			smp_int_redirect &= ~SMP_IRQ_REDIRECTION;
+		else
+			smp_int_redirect |= SMP_IRQ_REDIRECTION;
+#endif
+	}
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
+		printk(" IPI_Redirection");
+#ifdef CONFIG_SMP
+		if (no_int_routing)
+			smp_int_redirect &= ~SMP_IPI_REDIRECTION;
+		else
+			smp_int_redirect |= SMP_IPI_REDIRECTION;
+#endif
+	}
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
+		printk(" ITC_Drift");
+	printk("\n");
+}
+
+#ifdef CONFIG_SMP
+static void __init sal_desc_ap_wakeup(void *p)
+{
+	struct ia64_sal_desc_ap_wakeup *ap = p;
+	
+	switch (ap->mechanism) {
+	case IA64_SAL_AP_EXTERNAL_INT:
+		ap_wakeup_vector = ap->vector;
+		printk(KERN_INFO "SAL: AP wakeup using external interrupt "
+				"vector 0x%lx\n", ap_wakeup_vector);
+		break;
+	default:
+		printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
+		break;
+	}
+}
+#else
+static void __init sal_desc_ap_wakeup(void *p) { }
+#endif
 
 void __init
 ia64_sal_init (struct ia64_sal_systab *systab)
 {
-	unsigned long min, max;
 	char *p;
-	struct ia64_sal_desc_entry_point *ep;
 	int i;
 
 	if (!systab) {
@@ -103,86 +166,73 @@ ia64_sal_init (struct ia64_sal_systab *s
 	if (strncmp(systab->signature, "SST_", 4) != 0)
 		printk(KERN_ERR "bad signature in system table!");
 
-	/*
-	 * revisions are coded in BCD, so %x does the job for us
-	 */
-	printk(KERN_INFO "SAL v%x.%02x: oem=%.32s, product=%.32s\n",
-	       systab->sal_rev_major, systab->sal_rev_minor,
-	       systab->oem_id, systab->product_id);
-
-	min = ~0UL;
-	max = 0;
+	sal_rev_major = BCD2BIN(systab->sal_rev_major);
+	sal_rev_minor = BCD2BIN(systab->sal_rev_minor);
+	sal_b_rev_major = BCD2BIN(systab->sal_b_rev_major);
+	sal_b_rev_minor = BCD2BIN(systab->sal_b_rev_minor);
+
+	printk(KERN_INFO "SAL %d.%d: oem=%.32s, product=%.32s, version %d.%d\n",
+			sal_rev_major, sal_rev_minor, systab->oem_id,
+			systab->product_id, sal_b_rev_major, sal_b_rev_minor);
 
 	p = (char *) (systab + 1);
 	for (i = 0; i < systab->entry_count; i++) {
 		/*
-		 * The first byte of each entry type contains the type descriptor.
+		 * The first byte of each entry type contains the type
+		 * descriptor.
 		 */
 		switch (*p) {
-		      case SAL_DESC_ENTRY_POINT:
-			ep = (struct ia64_sal_desc_entry_point *) p;
-			printk(KERN_INFO "SAL: entry: pal_proc=0x%lx, sal_proc=0x%lx\n",
-			       ep->pal_proc, ep->sal_proc);
-			ia64_pal_handler_init(__va(ep->pal_proc));
-			ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+		case SAL_DESC_ENTRY_POINT:
+			sal_desc_entry_point(p);
 			break;
-
-		      case SAL_DESC_PTC:
+		case SAL_DESC_PLATFORM_FEATURE:
+			sal_desc_platform_feature(p);
+			break;
+		case SAL_DESC_PTC:
 			ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
 			break;
-
-		      case SAL_DESC_AP_WAKEUP:
-#ifdef CONFIG_SMP
-		      {
-			      struct ia64_sal_desc_ap_wakeup *ap = (void *) p;
-
-			      switch (ap->mechanism) {
-				    case IA64_SAL_AP_EXTERNAL_INT:
-				      ap_wakeup_vector = ap->vector;
-				      printk(KERN_INFO "SAL: AP wakeup using external interrupt "
-					     "vector 0x%lx\n", ap_wakeup_vector);
-				      break;
-
-				    default:
-				      printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
-				      break;
-			      }
-			      break;
-		      }
-#endif
-		      case SAL_DESC_PLATFORM_FEATURE:
-		      {
-			      struct ia64_sal_desc_platform_feature *pf = (void *) p;
-			      sal_platform_features = pf->feature_mask;
-			      printk(KERN_INFO "SAL: Platform features ");
-
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
-				      printk("BusLock ");
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
-				      printk("IRQ_Redirection ");
-#ifdef CONFIG_SMP
-				      if (no_int_routing)
-					      smp_int_redirect &= ~SMP_IRQ_REDIRECTION;
-				      else
-					      smp_int_redirect |= SMP_IRQ_REDIRECTION;
-#endif
-			      }
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
-				      printk("IPI_Redirection ");
-#ifdef CONFIG_SMP
-				      if (no_int_routing)
-					      smp_int_redirect &= ~SMP_IPI_REDIRECTION;
-				      else
-					      smp_int_redirect |= SMP_IPI_REDIRECTION;
-#endif
-			      }
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
-				      printk("ITC_Drift ");
-			      printk("\n");
-			      break;
- 		      }
-
+		case SAL_DESC_AP_WAKEUP:
+			sal_desc_ap_wakeup(p);
+			break;
 		}
 		p += SAL_DESC_SIZE(*p);
 	}
+}
+
+/**
+ * sal_check_revision - Check the revision of the SAL spec supported by firmware
+ * @major: The major number of the SAL spec
+ * @minor: The minor number of the SAL spec
+ *
+ * This function returns 1 if the SAL implementation on this machine
+ * supports the required revision.  Use it as:
+ *
+ * if (sal_check_revision(3, 2)) { ... }
+ */
+int sal_check_revision(int major, int minor)
+{
+	if (major < sal_rev_major)
+		return 1;
+	if (major > sal_rev_major)
+		return 0;
+	return (minor <= sal_rev_minor);
+}
+
+/**
+ * sal_check_version - Check what version of SAL is installed
+ * @major: The major number of the implementation
+ * @minor: The minor number of the implementation
+ *
+ * This function returns 1 if the version of the implementation of SAL is
+ * equal or higher than the required version.  You can only use this function
+ * if you already know what manufacturer your SAL comes from as every vendor
+ * may have a different version.
+ */
+int sal_check_version(int major, int minor)
+{
+	if (major < sal_b_rev_major)
+		return 1;
+	if (major > sal_b_rev_major)
+		return 0;
+	return (minor <= sal_b_rev_minor);
 }

Index: include/asm-ia64/sal.h
=================================RCS file: /var/cvs/linux-2.6/include/asm-ia64/sal.h,v retrieving revision 1.4

include/asm-ia64/sal.h +6 -4
diff -u -p -r1.4 sal.h
@@ -231,6 +231,8 @@ extern struct ia64_sal_desc_ptc *ia64_pt
 
 extern const char *ia64_sal_strerror (long status);
 extern void ia64_sal_init (struct ia64_sal_systab *sal_systab);
+extern int sal_check_revision(int major, int minor);
+extern int sal_check_version(int major, int minor);
 
 /* SAL information type encodings */
 enum {
@@ -741,10 +743,10 @@ ia64_sal_mc_set_params (u64 param_type, 
 
 /* Read from PCI configuration space */
 static inline s64
-ia64_sal_pci_config_read (u64 pci_config_addr, u64 size, u64 *value)
+ia64_sal_pci_config_read (u64 pci_config_addr, u64 size, u64 *value, int type)
 {
 	struct ia64_sal_retval isrv;
-	SAL_CALL(isrv, SAL_PCI_CONFIG_READ, pci_config_addr, size, 0, 0, 0, 0, 0);
+	SAL_CALL(isrv, SAL_PCI_CONFIG_READ, pci_config_addr, size, type, 0, 0, 0, 0);
 	if (value)
 		*value = isrv.v0;
 	return isrv.status;
@@ -752,11 +754,11 @@ ia64_sal_pci_config_read (u64 pci_config
 
 /* Write to PCI configuration space */
 static inline s64
-ia64_sal_pci_config_write (u64 pci_config_addr, u64 size, u64 value)
+ia64_sal_pci_config_write (u64 pci_config_addr, u64 size, u64 value, int type)
 {
 	struct ia64_sal_retval isrv;
 	SAL_CALL(isrv, SAL_PCI_CONFIG_WRITE, pci_config_addr, size, value,
-	         0, 0, 0, 0);
+	         type, 0, 0, 0);
 	return isrv.status;
 }
 
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#3 lore raw
In reply to Matthew Wilcox
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> On Thu, Feb 26, 2004 at 01:55:34PM -0800, David Mosberger

Quoted 1 line · Matthew> wrote:
Quoted 1 line

How about printing "none" or something like that instead?

Matthew> Sure.

Matthew> This patch reorganises sal.c and adds two new functions:

Matthew> - Split the body of the switch statement in Matthew> ia64_sal_init() into separate functions. - Delete min/max Matthew> since they were only assigned to, never used. - Print the Matthew> version of the SAL implementation as well as the spec Matthew> version it supports. - Stop printing the pal_proc and Matthew> sal_proc entry addresses. - Print "none" if there are no Matthew> platform features. - Remember the sal revision and version Matthew> and add two functions to compare them.

The patch also changes the arguments for ia64_sal_pci_config_read() and ia64_sal_pci_config_write(), without changing any callers. Why?

Also, how about putting a colon after "SAL Platform features"?

	--david
#4 lore raw
In reply to Matthew Wilcox
Quoted 3 lines · David Mosberger

The patch also changes the arguments for ia64_sal_pci_config_read() and ia64_sal_pci_config_write(), without changing any callers. Why?

Because I made a mistake; I intended to delete that part from that patch. It's part of the [3/4] patch I sent you earlier today.

Quoted 1 line

Also, how about putting a colon after "SAL Platform features"?

Sure. While we're nitpicking, how about deleting the 'oem=' and `product=' from the printk? It currently looks like:

SAL 3.1: oem=HP, product=, version 2.21

How about instead it reading

SAL 3.1: HP version 2.21

(if we filled in the product field, it'd read something like SAL 3.1: HP rx2600 version 2.21
)

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#5 lore raw
In reply to Matthew Wilcox
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> Sure. While we're nitpicking, how about deleting the Matthew> 'oem=' and `product=' from the printk? It currently looks Matthew> like:

Matthew> SAL 3.1: oem=HP, product=, version 2.21

Matthew> How about instead it reading

Matthew> SAL 3.1: HP version 2.21

Matthew> (if we filled in the product field, it'd read something Matthew> like SAL 3.1: HP rx2600 version 2.21 )

Sounds good to me. The extra blank kills me though... ;-)

	--david
#6 lore raw
In reply to Matthew Wilcox
Quoted 1 line · David Mosberger

Sounds good to me. The extra blank kills me though... ;-)

Weeeeeelllllllll.... if you're not allergic to trigraphs,

        printk(KERN_INFO "SAL %d.%d: %.32s %.32s%sversion %d.%d\n",
                        sal_rev_major, sal_rev_minor, systab->oem_id,
                        systab->product_id, systab->product_id[0] ? " " : "",
                        sal_b_rev_major, sal_b_rev_minor);

does the trick nicely ;-)

I'll send a patch when you've come to a decision about how you want the SAL revision comparison to look -- it all touches the same area of code.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#7 lore raw
In reply to Matthew Wilcox

On Fri, 27 Feb 2004 20:25:05 +0000 Matthew Wilcox wrote:

| On Fri, Feb 27, 2004 at 11:33:36AM -0800, David Mosberger wrote:
| > Sounds good to me.  The extra blank kills me though... ;-)
| 
| Weeeeeelllllllll.... if you're not allergic to trigraphs,
| 
|         printk(KERN_INFO "SAL %d.%d: %.32s %.32s%sversion %d.%d\n",
|                         sal_rev_major, sal_rev_minor, systab->oem_id,
|                         systab->product_id, systab->product_id[0] ? " " : "",
|                         sal_b_rev_major, sal_b_rev_minor);
| 
| does the trick nicely ;-)
| 
| I'll send a patch when you've come to a decision about how you want the
| SAL revision comparison to look -- it all touches the same area of code.

Where's the trigraph???

A conditional operator ("?:") [section 6.5.15 of C99 spec.] does not make a 'trigraph'.

Conditional operators are fine IMO, so long as the gcc extension of "omitted second operand implies repeat the first operand" is not used... :) This is ugly and prone to mistakes.

--
~Randy

#8 lore raw
In reply to Matthew Wilcox
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Randy.Dunlap

Randy> Where's the trigraph???

Thanks, you just saved me some typing... ;-)
(Trigraphs are a really ugly way to type curly braces and stuff like that for people who have keyboards without a curly brace key etc.)

Randy> A conditional operator ("?:") [section 6.5.15 of C99 spec.] Randy> does not make a 'trigraph'.

Randy> Conditional operators are fine IMO, so long as the gcc Randy> extension of "omitted second operand implies repeat the first Randy> operand" is not used... :) This is ugly and prone to Randy> mistakes.

Agreed. The patched looked perfectly fine to me.

	--david
#9 lore raw
In reply to Matthew Wilcox
Quoted 7 lines · David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Randy.Dunlap

Randy> Where's the trigraph???

Thanks, you just saved me some typing... ;-)
(Trigraphs are a really ugly way to type curly braces and stuff like that for people who have keyboards without a curly brace key etc.)

Oh, I don't know??! For some reason I'd thought that ?: was called a digraph and then confused it with trigraphs. I actually can't find a name for the ?: operator in the C FAQ.

Quoted 1 line

Agreed. The patched looked perfectly fine to me.

Great ;-) Now make a decision on how you want SAL version testing to work and I'll send you a patch.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#10 lore raw
In reply to Matthew Wilcox
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> I actually can't find a name for the ?: operator in the C Matthew> FAQ.

conditional expression?

Matthew> Great ;-) Now make a decision on how you want SAL version Matthew> testing to work and I'll send you a patch.

I'd really prefer sal_revision() combined with a SAL_VERSION() macro. I can just look at that and intuitively understand what it's doing (especially given the symmetry with the LINUX_VERSION macros), whereas with the sal_version_check() function, I have to go look at it's definition.

Thanks,

	--david
#11 lore raw
In reply to Matthew Wilcox
Quoted 6 lines · David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> I actually can't find a name for the ?: operator in the C Matthew> FAQ.

conditional expression?

I remembered I had a copy of the C99 spec ... 6.5.15 calls it the "conditional operator". I also found a document calling it the "ternary operator".

Quoted 5 lines

I'd really prefer sal_revision() combined with a SAL_VERSION() macro. I can just look at that and intuitively understand what it's doing (especially given the symmetry with the LINUX_VERSION macros), whereas with the sal_version_check() function, I have to go look at it's definition.

Okey dokey, done. I'll send it as a separate message to keep the ?:??! discussion out of the changelog ;-)

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#12 lore raw

PATCH 1/1 sal cleanup

In reply to Matthew Wilcox

This patch reorganises sal.c and adds a small amount of new functionality.

- Introduce sal_revision to report what revision of the SAL spec is supported by the system.
- Introduce sal_version to report what version of the vendor's SAL implementation is present.
- Introduce SAL_VERSION_CODE to allow for easy comparisons.
- Print the version at boot, and remove the 'oem=' and 'vendor=' strings.
- Refactor ia64_sal_init() into several smaller functions.
- Delete the dead variables 'max' and 'min'.
- Stop printing the pal_proc and sal_proc entry addresses.
- Print "None" if there are no SAL platform features.

Index: arch/ia64/kernel/sal.c
=================================RCS file: /var/cvs/linux-2.6/arch/ia64/kernel/sal.c,v retrieving revision 1.2

arch/ia64/kernel/sal.c +89 -72
diff -u -p -r1.2 sal.c
@@ -10,7 +10,6 @@
 
 #include <linux/kernel.h>
 #include <linux/init.h>
-#include <linux/smp.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
 
@@ -21,6 +20,12 @@
 spinlock_t sal_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
 unsigned long sal_platform_features;
 
+unsigned short sal_revision;
+unsigned short sal_version;
+
+#define SAL_MAJOR(x) ((x) >> 8)
+#define SAL_MINOR(x) ((x) & 0xff)
+
 static struct {
 	void *addr;	/* function entry point */
 	void *gpval;	/* gp value to use */
@@ -86,13 +91,75 @@ ia64_sal_handler_init (void *entry_point
 	ia64_sal = (ia64_sal_handler) &pdesc;
 }
 
+static void __init sal_desc_entry_point(void *p)
+{
+	struct ia64_sal_desc_entry_point *ep = p;
+	ia64_pal_handler_init(__va(ep->pal_proc));
+	ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+}
+
+#ifdef CONFIG_SMP
+static void __init set_smp_redirect(int flag)
+{
+	if (no_int_routing)
+		smp_int_redirect &= ~flag;
+	else
+		smp_int_redirect |= flag;
+}
+#else
+static void __init set_smp_redirect(int flag) { }
+#endif
+
+static void __init sal_desc_platform_feature(void *p)
+{
+	struct ia64_sal_desc_platform_feature *pf = p;
+	sal_platform_features = pf->feature_mask;
+
+	printk(KERN_INFO "SAL Platform features:");
+	if (!sal_platform_features) {
+		printk(" None\n");
+		return;
+	}
+
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
+		printk(" BusLock");
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
+		printk(" IRQ_Redirection");
+		set_smp_redirect(SMP_IRQ_REDIRECTION);
+	}
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
+		printk(" IPI_Redirection");
+		set_smp_redirect(SMP_IPI_REDIRECTION);
+	}
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
+		printk(" ITC_Drift");
+	printk("\n");
+}
+
+#ifdef CONFIG_SMP
+static void __init sal_desc_ap_wakeup(void *p)
+{
+	struct ia64_sal_desc_ap_wakeup *ap = p;
+	
+	switch (ap->mechanism) {
+	case IA64_SAL_AP_EXTERNAL_INT:
+		ap_wakeup_vector = ap->vector;
+		printk(KERN_INFO "SAL: AP wakeup using external interrupt "
+				"vector 0x%lx\n", ap_wakeup_vector);
+		break;
+	default:
+		printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
+		break;
+	}
+}
+#else
+static void __init sal_desc_ap_wakeup(void *p) { }
+#endif
 
 void __init
 ia64_sal_init (struct ia64_sal_systab *systab)
 {
-	unsigned long min, max;
 	char *p;
-	struct ia64_sal_desc_entry_point *ep;
 	int i;
 
 	if (!systab) {
@@ -103,85 +170,35 @@ ia64_sal_init (struct ia64_sal_systab *s
 	if (strncmp(systab->signature, "SST_", 4) != 0)
 		printk(KERN_ERR "bad signature in system table!");
 
-	/*
-	 * revisions are coded in BCD, so %x does the job for us
-	 */
-	printk(KERN_INFO "SAL v%x.%x: oem=%.32s, product=%.32s\n",
-	       systab->sal_rev_major, systab->sal_rev_minor,
-	       systab->oem_id, systab->product_id);
+	sal_revision = (systab->sal_rev_major << 8) | systab->sal_rev_minor;
+	sal_version = (systab->sal_b_rev_major << 8) | systab->sal_b_rev_minor;
 
-	min = ~0UL;
-	max = 0;
+	/* revisions are coded in BCD, so %x does the job for us */
+	printk(KERN_INFO "SAL %x.%x: %.32s %.32s%sversion %x.%x\n",
+			SAL_MAJOR(sal_revision), SAL_MINOR(sal_revision),
+			systab->oem_id, systab->product_id,
+			systab->product_id[0] ? " " : "",
+			SAL_MAJOR(sal_version), SAL_MINOR(sal_version));
 
 	p = (char *) (systab + 1);
 	for (i = 0; i < systab->entry_count; i++) {
 		/*
-		 * The first byte of each entry type contains the type descriptor.
+		 * The first byte of each entry type contains the type
+		 * descriptor.
 		 */
 		switch (*p) {
-		      case SAL_DESC_ENTRY_POINT:
-			ep = (struct ia64_sal_desc_entry_point *) p;
-			printk(KERN_INFO "SAL: entry: pal_proc=0x%lx, sal_proc=0x%lx\n",
-			       ep->pal_proc, ep->sal_proc);
-			ia64_pal_handler_init(__va(ep->pal_proc));
-			ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+		case SAL_DESC_ENTRY_POINT:
+			sal_desc_entry_point(p);
 			break;
-
-		      case SAL_DESC_PTC:
+		case SAL_DESC_PLATFORM_FEATURE:
+			sal_desc_platform_feature(p);
+			break;
+		case SAL_DESC_PTC:
 			ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
 			break;
-
-		      case SAL_DESC_AP_WAKEUP:
-#ifdef CONFIG_SMP
-		      {
-			      struct ia64_sal_desc_ap_wakeup *ap = (void *) p;
-
-			      switch (ap->mechanism) {
-				    case IA64_SAL_AP_EXTERNAL_INT:
-				      ap_wakeup_vector = ap->vector;
-				      printk(KERN_INFO "SAL: AP wakeup using external interrupt "
-					     "vector 0x%lx\n", ap_wakeup_vector);
-				      break;
-
-				    default:
-				      printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
-				      break;
-			      }
-			      break;
-		      }
-#endif
-		      case SAL_DESC_PLATFORM_FEATURE:
-		      {
-			      struct ia64_sal_desc_platform_feature *pf = (void *) p;
-			      sal_platform_features = pf->feature_mask;
-			      printk(KERN_INFO "SAL: Platform features ");
-
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
-				      printk("BusLock ");
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
-				      printk("IRQ_Redirection ");
-#ifdef CONFIG_SMP
-				      if (no_int_routing)
-					      smp_int_redirect &= ~SMP_IRQ_REDIRECTION;
-				      else
-					      smp_int_redirect |= SMP_IRQ_REDIRECTION;
-#endif
-			      }
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
-				      printk("IPI_Redirection ");
-#ifdef CONFIG_SMP
-				      if (no_int_routing)
-					      smp_int_redirect &= ~SMP_IPI_REDIRECTION;
-				      else
-					      smp_int_redirect |= SMP_IPI_REDIRECTION;
-#endif
-			      }
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
-				      printk("ITC_Drift ");
-			      printk("\n");
-			      break;
- 		      }
-
+		case SAL_DESC_AP_WAKEUP:
+			sal_desc_ap_wakeup(p);
+			break;
 		}
 		p += SAL_DESC_SIZE(*p);
 	}

Index: include/asm-ia64/sal.h
=================================RCS file: /var/cvs/linux-2.6/include/asm-ia64/sal.h,v retrieving revision 1.4

include/asm-ia64/sal.h +5 -0
diff -u -p -r1.4 sal.h
@@ -35,6 +35,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <linux/bcd.h>
 #include <linux/spinlock.h>
 #include <linux/efi.h>
 
@@ -229,6 +230,10 @@ typedef struct ia64_sal_desc_ap_wakeup {
 extern ia64_sal_handler ia64_sal;
 extern struct ia64_sal_desc_ptc *ia64_ptc_domain_info;
 
+extern unsigned short sal_revision;	/* supported SAL spec revision */
+extern unsigned short sal_version;	/* SAL version; OEM dependent */
+#define SAL_VERSION_CODE(major, minor) ((BIN2BCD(major) << 8) | BIN2BCD(minor))
+
 extern const char *ia64_sal_strerror (long status);
 extern void ia64_sal_init (struct ia64_sal_systab *sal_systab);
 
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#13 lore raw
In reply to Matthew Wilcox
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> This patch reorganises sal.c and adds a small amount of new Matthew> functionality.

The patch breaks UP kernels because SMP_IRQ_REDIRECTION and SMP_IPI_REDIRECTION aren't defined for UP kernels.

	--david
#14 lore raw
In reply to Matthew Wilcox

Well, this patch is giving me lots of grief. It appears that old (prototype) zx1 systems report a huge SAL version:

SAL 49.29: INTEL MSL REF SAL version 49.29

Unfortunately, the hardware is too old to upgrade to newer firmware, yet the hardware is good enough to be useful. Perhaps we could have a command-line option to override the SAL version?

	--david
#15 lore raw
In reply to Matthew Wilcox
Quoted 8 lines · David Mosberger

Well, this patch is giving me lots of grief. It appears that old (prototype) zx1 systems report a huge SAL version:

SAL 49.29: INTEL MSL REF SAL version 49.29

Unfortunately, the hardware is too old to upgrade to newer firmware, yet the hardware is good enough to be useful. Perhaps we could have a command-line option to override the SAL version?

I don't have an objection to doing that, but how about making it Just Work for this particular case? Something like ..

static void check_versions(struct ia64_sal_systab *systab)

{
        sal_revision = (systab->sal_rev_major << 8) | systab->sal_rev_minor;
        sal_version = (systab->sal_b_rev_major << 8) | systab->sal_b_rev_minor;

        /* Check for broken firmware */
        if ((sal_revision = SAL_VERSION_CODE(49, 29)) &&
                        (sal_version = SAL_VERSION_CODE(49, 29))) {
                sal_revision = SAL_VERSION_CODE(2, 8);
                sal_version = SAL_VERSION_CODE(0, 0);
        }
}

...

        if (strncmp(systab->signature, "SST_", 4) != 0)
                printk(KERN_ERR "bad signature in system table!");

        check_versions(systab);

        /* revisions are coded in BCD, so %x does the job for us */ 
        printk(KERN_INFO "SAL %x.%x: %.32s %.32s%sversion %x.%x\n",

...

SAL rev 2.8 was published in January 2000. It should be safe to claim compliance with this. The version number change I'm not 100% sure of, but it seems better than leaving it too high.

(I note this fix shows the wisdom of going with the SAL_VERSION_CODE option. Good call.)

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#16 lore raw
In reply to Matthew Wilcox
Quoted 7 lines · David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> This patch reorganises sal.c and adds a small amount of new Matthew> functionality.

The patch breaks UP kernels because SMP_IRQ_REDIRECTION and SMP_IPI_REDIRECTION aren't defined for UP kernels.

Ack, sorry. I'll change them to #defines.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#17 lore raw
In reply to Matthew Wilcox
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> I don't have an objection to doing that, but how about Matthew> making it Just Work for this particular case? Something Matthew> like ..

Well, that would be more convenient for me, but I don't know how many other "strange" SAL version numbers are out there in the wild. It's can be handy to have an override option when dealing with buggy firmware (fortunately, quite rare with production systems, but it's all to common with prototypes).

Just a caveat:

Matthew> SAL_VERSION_CODE(49, 29)

shouldn't these be in hex?

	--david
#18 lore raw
In reply to Matthew Wilcox
Quoted 11 lines · David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> I don't have an objection to doing that, but how about Matthew> making it Just Work for this particular case? Something Matthew> like ..

Well, that would be more convenient for me, but I don't know how many other "strange" SAL version numbers are out there in the wild. It's can be handy to have an override option when dealing with buggy firmware (fortunately, quite rare with production systems, but it's all to common with prototypes).

Yeah. That's why I moved it into a separate function so we can add other bad version numbers. If we were really keen, we could even add a check for the oem and product IDs matching, or a data table of known-bad BIOSes but let's keep it simple until we have to make it complex.

Quoted 5 lines

Just a caveat:

Matthew> SAL_VERSION_CODE(49, 29)

shouldn't these be in hex?

Nope, that's the beauty of it:

#define SAL_VERSION_CODE(major, minor) ((BIN2BCD(major) << 8) | BIN2BCD(minor))

BIN2BCD is defined in linux/bcd.h as ((((val)/10)<<4) + (val)%10)

So you get to specify things in decimal.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#19 lore raw
In reply to Matthew Wilcox
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> Yeah. That's why I moved it into a separate function so we Matthew> can add other bad version numbers. If we were really keen, Matthew> we could even add a check for the oem and product IDs Matthew> matching, or a data table of known-bad BIOSes but let's Matthew> keep it simple until we have to make it complex.

Well, I can live with either approach, so it's your call. It's just that a command-line option can come in handy when you're urgently trying to boot a kernel and you can't rebuild a kernel (like when trying to demo a new machine... ;-).

Matthew> SAL_VERSION_CODE(49, 29)

Quoted 1 line
Quoted 1 line

shouldn't these be in hex?

Matthew> Nope, that's the beauty of it:

Matthew> #define SAL_VERSION_CODE(major, minor) ((BIN2BCD(major) << Matthew> 8) | BIN2BCD(minor))

Matthew> BIN2BCD is defined in linux/bcd.h as ((((val)/10)<<4) + Matthew> (val)%10)

Matthew> So you get to specify things in decimal.

Ah, I missed that. Nice.

	--daivd
#20 lore raw
In reply to Matthew Wilcox

This patch reorganises sal.c and adds a small amount of new functionality.

- Introduce sal_revision to report what revision of the SAL spec is supported by the system.
- Introduce sal_version to report what version of the vendor's SAL implementation is present.
- Introduce SAL_VERSION_CODE to allow for easy comparisons.
- Print the version at boot, and remove the 'oem=' and 'vendor=' strings.
- Fix the revision if we have a known-bad firmware version.
- Refactor ia64_sal_init() into several smaller functions.
- Delete the dead variables 'max' and 'min'.
- Stop printing the pal_proc and sal_proc entry addresses.
- Print "None" if there are no SAL platform features.

Index: arch/ia64/kernel/sal.c
=================================RCS file: /var/cvs/linux-2.6/arch/ia64/kernel/sal.c,v retrieving revision 1.2

arch/ia64/kernel/sal.c +101 -71
diff -u -p -r1.2 sal.c
@@ -21,6 +21,12 @@
 spinlock_t sal_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
 unsigned long sal_platform_features;
 
+unsigned short sal_revision;
+unsigned short sal_version;
+
+#define SAL_MAJOR(x) ((x) >> 8)
+#define SAL_MINOR(x) ((x) & 0xff)
+
 static struct {
 	void *addr;	/* function entry point */
 	void *gpval;	/* gp value to use */
@@ -86,13 +92,88 @@ ia64_sal_handler_init (void *entry_point
 	ia64_sal = (ia64_sal_handler) &pdesc;
 }
 
+static void check_versions(struct ia64_sal_systab *systab)
+{
+	sal_revision = (systab->sal_rev_major << 8) | systab->sal_rev_minor;
+	sal_version = (systab->sal_b_rev_major << 8) | systab->sal_b_rev_minor;
+
+	/* Check for broken firmware */
+	if ((sal_revision = SAL_VERSION_CODE(49, 29)) &&
+			(sal_version = SAL_VERSION_CODE(49, 29))) {
+		sal_revision = SAL_VERSION_CODE(2, 8);
+		sal_version = SAL_VERSION_CODE(0, 0);
+	}
+}
+
+static void __init sal_desc_entry_point(void *p)
+{
+	struct ia64_sal_desc_entry_point *ep = p;
+	ia64_pal_handler_init(__va(ep->pal_proc));
+	ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+}
+
+#ifdef CONFIG_SMP
+static void __init set_smp_redirect(int flag)
+{
+	if (no_int_routing)
+		smp_int_redirect &= ~flag;
+	else
+		smp_int_redirect |= flag;
+}
+#else
+#define set_smp_redirect(flag) do { } while (0)
+#endif
+
+static void __init sal_desc_platform_feature(void *p)
+{
+	struct ia64_sal_desc_platform_feature *pf = p;
+	sal_platform_features = pf->feature_mask;
+
+	printk(KERN_INFO "SAL Platform features:");
+	if (!sal_platform_features) {
+		printk(" None\n");
+		return;
+	}
+
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
+		printk(" BusLock");
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
+		printk(" IRQ_Redirection");
+		set_smp_redirect(SMP_IRQ_REDIRECTION);
+	}
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
+		printk(" IPI_Redirection");
+		set_smp_redirect(SMP_IPI_REDIRECTION);
+	}
+	if (sal_platform_features & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
+		printk(" ITC_Drift");
+	printk("\n");
+}
+
+#ifdef CONFIG_SMP
+static void __init sal_desc_ap_wakeup(void *p)
+{
+	struct ia64_sal_desc_ap_wakeup *ap = p;
+	
+	switch (ap->mechanism) {
+	case IA64_SAL_AP_EXTERNAL_INT:
+		ap_wakeup_vector = ap->vector;
+		printk(KERN_INFO "SAL: AP wakeup using external interrupt "
+				"vector 0x%lx\n", ap_wakeup_vector);
+		break;
+	default:
+		printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
+		break;
+	}
+}
+#else
+static void __init sal_desc_ap_wakeup(void *p) { }
+#endif
 
 void __init
 ia64_sal_init (struct ia64_sal_systab *systab)
 {
-	unsigned long min, max;
 	char *p;
-	struct ia64_sal_desc_entry_point *ep;
 	int i;
 
 	if (!systab) {
@@ -103,85 +184,34 @@ ia64_sal_init (struct ia64_sal_systab *s
 	if (strncmp(systab->signature, "SST_", 4) != 0)
 		printk(KERN_ERR "bad signature in system table!");
 
-	/*
-	 * revisions are coded in BCD, so %x does the job for us
-	 */
-	printk(KERN_INFO "SAL v%x.%x: oem=%.32s, product=%.32s\n",
-	       systab->sal_rev_major, systab->sal_rev_minor,
-	       systab->oem_id, systab->product_id);
+	check_versions(systab);
 
-	min = ~0UL;
-	max = 0;
+	/* revisions are coded in BCD, so %x does the job for us */
+	printk(KERN_INFO "SAL %x.%x: %.32s %.32s%sversion %x.%x\n",
+			SAL_MAJOR(sal_revision), SAL_MINOR(sal_revision),
+			systab->oem_id, systab->product_id,
+			systab->product_id[0] ? " " : "",
+			SAL_MAJOR(sal_version), SAL_MINOR(sal_version));
 
 	p = (char *) (systab + 1);
 	for (i = 0; i < systab->entry_count; i++) {
 		/*
-		 * The first byte of each entry type contains the type descriptor.
+		 * The first byte of each entry type contains the type
+		 * descriptor.
 		 */
 		switch (*p) {
-		      case SAL_DESC_ENTRY_POINT:
-			ep = (struct ia64_sal_desc_entry_point *) p;
-			printk(KERN_INFO "SAL: entry: pal_proc=0x%lx, sal_proc=0x%lx\n",
-			       ep->pal_proc, ep->sal_proc);
-			ia64_pal_handler_init(__va(ep->pal_proc));
-			ia64_sal_handler_init(__va(ep->sal_proc), __va(ep->gp));
+		case SAL_DESC_ENTRY_POINT:
+			sal_desc_entry_point(p);
 			break;
-
-		      case SAL_DESC_PTC:
+		case SAL_DESC_PLATFORM_FEATURE:
+			sal_desc_platform_feature(p);
+			break;
+		case SAL_DESC_PTC:
 			ia64_ptc_domain_info = (ia64_sal_desc_ptc_t *)p;
 			break;
-
-		      case SAL_DESC_AP_WAKEUP:
-#ifdef CONFIG_SMP
-		      {
-			      struct ia64_sal_desc_ap_wakeup *ap = (void *) p;
-
-			      switch (ap->mechanism) {
-				    case IA64_SAL_AP_EXTERNAL_INT:
-				      ap_wakeup_vector = ap->vector;
-				      printk(KERN_INFO "SAL: AP wakeup using external interrupt "
-					     "vector 0x%lx\n", ap_wakeup_vector);
-				      break;
-
-				    default:
-				      printk(KERN_ERR "SAL: AP wakeup mechanism unsupported!\n");
-				      break;
-			      }
-			      break;
-		      }
-#endif
-		      case SAL_DESC_PLATFORM_FEATURE:
-		      {
-			      struct ia64_sal_desc_platform_feature *pf = (void *) p;
-			      sal_platform_features = pf->feature_mask;
-			      printk(KERN_INFO "SAL: Platform features ");
-
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_BUS_LOCK)
-				      printk("BusLock ");
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT) {
-				      printk("IRQ_Redirection ");
-#ifdef CONFIG_SMP
-				      if (no_int_routing)
-					      smp_int_redirect &= ~SMP_IRQ_REDIRECTION;
-				      else
-					      smp_int_redirect |= SMP_IRQ_REDIRECTION;
-#endif
-			      }
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT) {
-				      printk("IPI_Redirection ");
-#ifdef CONFIG_SMP
-				      if (no_int_routing)
-					      smp_int_redirect &= ~SMP_IPI_REDIRECTION;
-				      else
-					      smp_int_redirect |= SMP_IPI_REDIRECTION;
-#endif
-			      }
-			      if (pf->feature_mask & IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT)
-				      printk("ITC_Drift ");
-			      printk("\n");
-			      break;
- 		      }
-
+		case SAL_DESC_AP_WAKEUP:
+			sal_desc_ap_wakeup(p);
+			break;
 		}
 		p += SAL_DESC_SIZE(*p);
 	}

Index: include/asm-ia64/sal.h
=================================RCS file: /var/cvs/linux-2.6/include/asm-ia64/sal.h,v retrieving revision 1.4

include/asm-ia64/sal.h +5 -0
diff -u -p -r1.4 sal.h
@@ -35,6 +35,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <linux/bcd.h>
 #include <linux/spinlock.h>
 #include <linux/efi.h>
 
@@ -229,6 +230,10 @@ typedef struct ia64_sal_desc_ap_wakeup {
 extern ia64_sal_handler ia64_sal;
 extern struct ia64_sal_desc_ptc *ia64_ptc_domain_info;
 
+extern unsigned short sal_revision;	/* supported SAL spec revision */
+extern unsigned short sal_version;	/* SAL version; OEM dependent */
+#define SAL_VERSION_CODE(major, minor) ((BIN2BCD(major) << 8) | BIN2BCD(minor))
+
 extern const char *ia64_sal_strerror (long status);
 extern void ia64_sal_init (struct ia64_sal_systab *sal_systab);
 
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#21 lore raw
In reply to Matthew Wilcox
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Matthew Wilcox

Matthew> This patch reorganises sal.c and adds a small amount of new Matthew> functionality.

I already had your earlier patch in my tree, so I merged the changes by hand. Should show up in my bk repos shortly.

	--david