Skip to content

Commit

Permalink
selftests/powerpc: Move Hash MMU check to utilities
Browse files Browse the repository at this point in the history
This moves a function to test if the MMU is in Hash mode
under the generic test utilities.

Signed-off-by: Sandipan Das <sandipan@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200604125610.649668-3-sandipan@linux.ibm.com
  • Loading branch information
Sandipan Das authored and Michael Ellerman committed Jun 30, 2020
1 parent 828ca43 commit c405b73
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/powerpc/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static inline bool have_hwcap2(unsigned long ftr2)
#endif

bool is_ppc64le(void);
int using_hash_mmu(bool *using_hash);

/* Yes, this is evil */
#define FAIL_IF(x) \
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/powerpc/mm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TEST_GEN_FILES := tempfile
top_srcdir = ../../../../..
include ../../lib.mk

$(TEST_GEN_PROGS): ../harness.c
$(TEST_GEN_PROGS): ../harness.c ../utils.c

$(OUTPUT)/prot_sao: ../utils.c

Expand Down
28 changes: 0 additions & 28 deletions tools/testing/selftests/powerpc/mm/bad_accesses.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,6 @@ int bad_access(char *p, bool write)
return 0;
}

static int using_hash_mmu(bool *using_hash)
{
char line[128];
FILE *f;
int rc;

f = fopen("/proc/cpuinfo", "r");
FAIL_IF(!f);

rc = 0;
while (fgets(line, sizeof(line), f) != NULL) {
if (strcmp(line, "MMU : Hash\n") == 0) {
*using_hash = true;
goto out;
}

if (strcmp(line, "MMU : Radix\n") == 0) {
*using_hash = false;
goto out;
}
}

rc = -1;
out:
fclose(f);
return rc;
}

static int test(void)
{
unsigned long i, j, addr, region_shift, page_shift, page_size;
Expand Down
28 changes: 28 additions & 0 deletions tools/testing/selftests/powerpc/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,31 @@ void set_dscr(unsigned long val)

asm volatile("mtspr %1,%0" : : "r" (val), "i" (SPRN_DSCR));
}

int using_hash_mmu(bool *using_hash)
{
char line[128];
FILE *f;
int rc;

f = fopen("/proc/cpuinfo", "r");
FAIL_IF(!f);

rc = 0;
while (fgets(line, sizeof(line), f) != NULL) {
if (strcmp(line, "MMU : Hash\n") == 0) {
*using_hash = true;
goto out;
}

if (strcmp(line, "MMU : Radix\n") == 0) {
*using_hash = false;
goto out;
}
}

rc = -1;
out:
fclose(f);
return rc;
}

0 comments on commit c405b73

Please sign in to comment.