From patchwork Fri Aug 30 15:53:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13785303 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E105A1B81D9 for ; Fri, 30 Aug 2024 15:53:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725033229; cv=none; b=J7TlPH0Z8eR/e1a/aD7iwosETFHrdeESDoTQfMGO9NVhfj0m+g6gL6U75X1aW5cyDyBmAg0t8GfF5uUvNgJTy0dMt3FRd50YNmSK65DvxwFUWdtiLq5OZCq4fCDVMqNzRATR/Rsw9+kdMTsOBrGmPq3Izbli5MkP+JxGIMY6Ixo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725033229; c=relaxed/simple; bh=gpFSyCvgrpx0Oj3e+0dxQBX+It0A2DwlY5+VK2vkdvk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dIhgKsQ+Sfkqt/VNA+rXg2HWS4KJenHAawXVNgCdMLDwWZos4B6Sr+BcP34M+guYOvOtQtIggNOB7LRF8TO8SeD6lFAvdDFyZ8W1tdjV+uXfgJYbfZugH3j3tOjhWs9Wt147o1HpxCZBEmlLY7LIA9lasmFpE6dLiJ72kGOTltY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dYTcmWmF; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dYTcmWmF" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1725033224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dLtlltP/W1dYapl9HluIcmIbLG5POT2yhvwdk7T+m/E=; b=dYTcmWmFyKsVD81wXOo/9HYbB0xRWD/Qf+Lcimb84ibmpzR/TuK2xQeBWR+nqSjPq8GQnL JSkeRCoHB0X8m/0kr8RVETeKLq9YOqQiOQU+APnH9rQaBbeI0drH3bgkIqhC0rUSUfaRf+ Z/GvZ96pmEJaRg9cjkbRc5715IZeDqo= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 1/2] sbi: Rename __*_sbi_ecall to sbi_* Date: Fri, 30 Aug 2024 17:53:39 +0200 Message-ID: <20240830155337.335534-5-andrew.jones@linux.dev> In-Reply-To: <20240830155337.335534-4-andrew.jones@linux.dev> References: <20240830155337.335534-4-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Let's name all SBI ecall wrappers with the same pattern of sbi_ and sbi__, even those that are local to the SBI tests. This is good for consistency and if those functions are ever promoted to the library then we won't have to change all their invocations. Signed-off-by: Andrew Jones --- riscv/sbi.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index 85cb7e589bdc..907bfbe5bb69 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -30,14 +30,21 @@ static void help(void) puts("An environ must be provided where expected values are given.\n"); } -static struct sbiret __base_sbi_ecall(int fid, unsigned long arg0) +static struct sbiret sbi_base(int fid, unsigned long arg0) { return sbi_ecall(SBI_EXT_BASE, fid, arg0, 0, 0, 0, 0, 0); } -static struct sbiret __dbcn_sbi_ecall(int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2) +static struct sbiret sbi_dbcn_write(unsigned long num_bytes, unsigned long base_addr_lo, + unsigned long base_addr_hi) { - return sbi_ecall(SBI_EXT_DBCN, fid, arg0, arg1, arg2, 0, 0, 0); + return sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, + num_bytes, base_addr_lo, base_addr_hi, 0, 0, 0); +} + +static struct sbiret sbi_dbcn_write_byte(uint8_t byte) +{ + return sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, byte, 0, 0, 0, 0, 0); } static void split_phys_addr(phys_addr_t paddr, unsigned long *hi, unsigned long *lo) @@ -98,7 +105,7 @@ static void check_base(void) report_prefix_push("base"); - ret = __base_sbi_ecall(SBI_EXT_BASE_GET_SPEC_VERSION, 0); + ret = sbi_base(SBI_EXT_BASE_GET_SPEC_VERSION, 0); if (ret.error || ret.value < 2) { report_skip("SBI spec version 0.2 or higher required"); return; @@ -114,7 +121,7 @@ static void check_base(void) report_prefix_push("impl_id"); if (env_or_skip("SBI_IMPL_ID")) { expected = (long)strtoul(getenv("SBI_IMPL_ID"), NULL, 0); - ret = __base_sbi_ecall(SBI_EXT_BASE_GET_IMP_ID, 0); + ret = sbi_base(SBI_EXT_BASE_GET_IMP_ID, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); @@ -122,17 +129,17 @@ static void check_base(void) report_prefix_push("impl_version"); if (env_or_skip("SBI_IMPL_VERSION")) { expected = (long)strtoul(getenv("SBI_IMPL_VERSION"), NULL, 0); - ret = __base_sbi_ecall(SBI_EXT_BASE_GET_IMP_VERSION, 0); + ret = sbi_base(SBI_EXT_BASE_GET_IMP_VERSION, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); report_prefix_push("probe_ext"); expected = getenv("SBI_PROBE_EXT") ? (long)strtoul(getenv("SBI_PROBE_EXT"), NULL, 0) : 1; - ret = __base_sbi_ecall(SBI_EXT_BASE_PROBE_EXT, SBI_EXT_BASE); + ret = sbi_base(SBI_EXT_BASE_PROBE_EXT, SBI_EXT_BASE); gen_report(&ret, 0, expected); report_prefix_push("unavailable"); - ret = __base_sbi_ecall(SBI_EXT_BASE_PROBE_EXT, 0xb000000); + ret = sbi_base(SBI_EXT_BASE_PROBE_EXT, 0xb000000); gen_report(&ret, 0, 0); report_prefix_pop(); report_prefix_pop(); @@ -141,7 +148,7 @@ static void check_base(void) if (env_or_skip("MVENDORID")) { expected = (long)strtoul(getenv("MVENDORID"), NULL, 0); assert(__riscv_xlen == 32 || !(expected >> 32)); - ret = __base_sbi_ecall(SBI_EXT_BASE_GET_MVENDORID, 0); + ret = sbi_base(SBI_EXT_BASE_GET_MVENDORID, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); @@ -149,7 +156,7 @@ static void check_base(void) report_prefix_push("marchid"); if (env_or_skip("MARCHID")) { expected = (long)strtoul(getenv("MARCHID"), NULL, 0); - ret = __base_sbi_ecall(SBI_EXT_BASE_GET_MARCHID, 0); + ret = sbi_base(SBI_EXT_BASE_GET_MARCHID, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); @@ -157,7 +164,7 @@ static void check_base(void) report_prefix_push("mimpid"); if (env_or_skip("MIMPID")) { expected = (long)strtoul(getenv("MIMPID"), NULL, 0); - ret = __base_sbi_ecall(SBI_EXT_BASE_GET_MIMPID, 0); + ret = sbi_base(SBI_EXT_BASE_GET_MIMPID, 0); gen_report(&ret, 0, expected); } report_prefix_pop(); @@ -292,7 +299,7 @@ static void dbcn_write_test(const char *s, unsigned long num_bytes) split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); do { - ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, num_bytes, base_addr_lo, base_addr_hi); + ret = sbi_dbcn_write(num_bytes, base_addr_lo, base_addr_hi); num_bytes -= ret.value; paddr += ret.value; split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); @@ -325,7 +332,7 @@ static void dbcn_high_write_test(const char *s, unsigned long num_bytes, /* * Only the write functionality is tested here. There's no easy way to - * non-interactively test the read functionality. + * non-interactively test SBI_EXT_DBCN_CONSOLE_READ. */ static void check_dbcn(void) { @@ -339,8 +346,7 @@ static void check_dbcn(void) report_prefix_push("dbcn"); - ret = __base_sbi_ecall(SBI_EXT_BASE_PROBE_EXT, SBI_EXT_DBCN); - if (!ret.value) { + if (!sbi_probe(SBI_EXT_DBCN)) { report_skip("DBCN extension unavailable"); report_prefix_pop(); return; @@ -393,7 +399,7 @@ static void check_dbcn(void) if (do_invalid_addr) { split_phys_addr(paddr, &base_addr_hi, &base_addr_lo); - ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE, 1, base_addr_lo, base_addr_hi); + ret = sbi_dbcn_write(1, base_addr_lo, base_addr_hi); report(ret.error == SBI_ERR_INVALID_PARAM, "address (error=%ld)", ret.error); } report_prefix_pop(); @@ -402,7 +408,7 @@ static void check_dbcn(void) report_prefix_push("write_byte"); puts("DBCN_WRITE TEST CHAR: "); - ret = __dbcn_sbi_ecall(SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, (u8)DBCN_WRITE_BYTE_TEST_BYTE, 0, 0); + ret = sbi_dbcn_write_byte(DBCN_WRITE_BYTE_TEST_BYTE); puts("\n"); report(ret.error == SBI_SUCCESS, "write success (error=%ld)", ret.error); report(ret.value == 0, "expected ret.value (%ld)", ret.value); From patchwork Fri Aug 30 15:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13785304 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E90021B86DD for ; Fri, 30 Aug 2024 15:53:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725033233; cv=none; b=Wc6XXBiYl07CSX3yj2+yiF9qNSiA7dpxgig5me+bbjdoVu3SCUEtaKWrBHaMuGRc+mSPsm1HbUN08vPGt02VvJ/XHtE0Sus3AwEZ9FuyDdzW2evyI25Qf0tYErFMv5ie+1gAg2OAx9GIT3gsEPgHQuu5FxpGqeGKvby8oljuD3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725033233; c=relaxed/simple; bh=B5Ptou+38oFmlHLIFp7fejSG33MAYNMakwm6qsa+/do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bUmJvOExZYCXX0ieyqesQhR1fJSEQd93tVM+4dgZA/Ou7Kw8zHcUI/iIXqeAIC4dEQcOw/W9h1u+EhG1xg9qPd5BNAocM5RVHSa2WRhGy3uX6fgtmaASrRo5AoLat5A2LlfBAHSV44U18JNj0808ClKvNYa1B+IOsdRjX0isSrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=pK52v/su; arc=none smtp.client-ip=95.215.58.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pK52v/su" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1725033229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jADyrI0MHQc0Ju+AG9jA0SQN7WaEFObFU45pTMK0mDM=; b=pK52v/suf/DcHSXj5RvlNslsyqhUzbxgkMH5xbuC0yZXGPx2YHeUSHYS5sYZ5xz5LVGuDL wJ/ozEtdmiijAU4GtzAsgYotSIZi1+kjch+sxb+PCheoaD0xtFKxHfV5POEr59PgMjBJ8x BYNmr5BHox4jXo9BHeMYhhnKETTB+00= From: Andrew Jones To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: atishp@rivosinc.com, cade.richard@berkeley.edu, jamestiotio@gmail.com Subject: [kvm-unit-tests PATCH 2/2] sbi: dbcn: Add write-byte test with more than byte given Date: Fri, 30 Aug 2024 17:53:40 +0200 Message-ID: <20240830155337.335534-6-andrew.jones@linux.dev> In-Reply-To: <20240830155337.335534-4-andrew.jones@linux.dev> References: <20240830155337.335534-4-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Try the write-byte function, but with a word full of characters. We should still get 'a' since that's in the least-significant byte. Signed-off-by: Andrew Jones --- riscv/sbi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/riscv/sbi.c b/riscv/sbi.c index 907bfbe5bb69..a1c97b93cdd0 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -407,12 +407,18 @@ static void check_dbcn(void) report_prefix_pop(); report_prefix_push("write_byte"); - puts("DBCN_WRITE TEST CHAR: "); + puts("DBCN_WRITE_BYTE TEST BYTE: "); ret = sbi_dbcn_write_byte(DBCN_WRITE_BYTE_TEST_BYTE); puts("\n"); report(ret.error == SBI_SUCCESS, "write success (error=%ld)", ret.error); report(ret.value == 0, "expected ret.value (%ld)", ret.value); + puts("DBCN_WRITE_BYTE TEST WORD: "); /* still expect 'a' in the output */ + ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE_BYTE, 0x64636261, 0, 0, 0, 0, 0); + puts("\n"); + report(ret.error == SBI_SUCCESS, "write success (error=%ld)", ret.error); + report(ret.value == 0, "expected ret.value (%ld)", ret.value); + report_prefix_pop(); report_prefix_pop(); }