diff mbox series

src/main.c: Add detection of host type for kernel backend

Message ID 20180912041503.20066-1-alistair@popple.id.au
State Superseded
Headers show
Series src/main.c: Add detection of host type for kernel backend | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/build-multiarch fail Test build-multiarch on branch master

Commit Message

Alistair Popple Sept. 12, 2018, 4:15 a.m. UTC
Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 src/main.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

Comments

Joel Stanley Sept. 12, 2018, 4:35 a.m. UTC | #1
On Wed, 12 Sep 2018 at 13:45, Alistair Popple <alistair@popple.id.au> wrote:
>
> Signed-off-by: Alistair Popple <alistair@popple.id.au>
> ---
>  src/main.c | 40 ++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/src/main.c b/src/main.c
> index 883e892..79f67a5 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -52,6 +52,8 @@
>  #include "p9r-fsi.dt.h"
>  #include "p9z-fsi.dt.h"
>  #include "p9-kernel.dt.h"
> +
> +#define FSI_CFAM_ID "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/cfam_id"
>  #endif
>
>  #ifdef TARGET_PPC
> @@ -59,6 +61,10 @@
>  #include "p9-host.dt.h"
>  #endif
>
> +#define CHIP_ID_P8  0xea
> +#define CHIP_ID_P9  0xd1
> +#define CHIP_ID_P8P 0xd3
> +
>  #define THREADS_PER_CORE       8
>
>  static enum backend backend = KERNEL;
> @@ -629,9 +635,39 @@ static int target_selection(void)
>
>         case KERNEL:
>                 if (device_node == NULL) {
> -                       PR_ERROR("kernel backend requires a device type\n");
> -                       return -1;
> +                       FILE *cfam_id_file;
> +
> +                       /* Try and determine the correct device type */
> +                       cfam_id_file = fopen(FSI_CFAM_ID, "r");


I suggest we do something like this, so it's a bit easier to debug
what's going on. At some point soon openbmc will gain non-root users,
and we will want to have messages for when a user is not-root and
can't open the file.

if (!cfam_id_file) {
     PR_DEBUG("%s: %s, assuming P9\n", strerror(errno), FSI_CFAM_ID);
     /* The support for POWER8 included the cfam_id
      * so if it doesn't exist assume we must be on
      * P9 */
    device_node = "p9";
    } else {

> +                               uint32_t cfam_id = 0;
> +
> +                               fscanf(cfam_id_file, "0x%" PRIx32, &cfam_id);
> +                               fclose(cfam_id_file);
> +
> +                               switch((cfam_id >> 4) & 0xff) {
> +                               case CHIP_ID_P9:
> +                                       device_node = "p9";
> +                                       break;
> +
> +                               case CHIP_ID_P8:
> +                               case CHIP_ID_P8P:
> +                                       device_node = "p8";
> +                                       break;
> +
> +                               default:
> +                                       PR_ERROR("Unknown chip-id detected\n");
> +                                       PR_ERROR("You will need to specify one with -d <host type>\n");

s/one/a host type/

> +                                       return -1;
> +                               }
> +                       } else {
> +                               /* The support for POWER8 included the cfam_id
> +                                * so if it doesn't exist assume we must be on
> +                                * P9 */
> +                               device_node = "p9";
> +                       }
>                 }
> +
>                 if (!strcmp(device_node, "p8"))
>                         pdbg_targets_init(&_binary_p8_kernel_dtb_o_start);
>                 else
> --
> 2.11.0
>
diff mbox series

Patch

diff --git a/src/main.c b/src/main.c
index 883e892..79f67a5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -52,6 +52,8 @@ 
 #include "p9r-fsi.dt.h"
 #include "p9z-fsi.dt.h"
 #include "p9-kernel.dt.h"
+
+#define FSI_CFAM_ID "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/cfam_id"
 #endif
 
 #ifdef TARGET_PPC
@@ -59,6 +61,10 @@ 
 #include "p9-host.dt.h"
 #endif
 
+#define CHIP_ID_P8  0xea
+#define CHIP_ID_P9  0xd1
+#define CHIP_ID_P8P 0xd3
+
 #define THREADS_PER_CORE	8
 
 static enum backend backend = KERNEL;
@@ -629,9 +635,39 @@  static int target_selection(void)
 
 	case KERNEL:
 		if (device_node == NULL) {
-			PR_ERROR("kernel backend requires a device type\n");
-			return -1;
+			FILE *cfam_id_file;
+
+			/* Try and determine the correct device type */
+			cfam_id_file = fopen(FSI_CFAM_ID, "r");
+			if (cfam_id_file) {
+				uint32_t cfam_id = 0;
+
+				fscanf(cfam_id_file, "0x%" PRIx32, &cfam_id);
+				fclose(cfam_id_file);
+
+				switch((cfam_id >> 4) & 0xff) {
+				case CHIP_ID_P9:
+					device_node = "p9";
+					break;
+
+				case CHIP_ID_P8:
+				case CHIP_ID_P8P:
+					device_node = "p8";
+					break;
+
+				default:
+					PR_ERROR("Unknown chip-id detected\n");
+					PR_ERROR("You will need to specify one with -d <host type>\n");
+					return -1;
+				}
+			} else {
+				/* The support for POWER8 included the cfam_id
+				 * so if it doesn't exist assume we must be on
+				 * P9 */
+				device_node = "p9";
+			}
 		}
+
 		if (!strcmp(device_node, "p8"))
 			pdbg_targets_init(&_binary_p8_kernel_dtb_o_start);
 		else