[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 42/48] target/ppc/mmu_common.c: Simplify ppc6xx_tlb_pte_check(
|
From: |
BALATON Zoltan |
|
Subject: |
[PATCH v6 42/48] target/ppc/mmu_common.c: Simplify ppc6xx_tlb_pte_check() |
|
Date: |
Sat, 11 May 2024 03:46:23 +0200 (CEST) |
Invert conditions to avoid deep nested ifs and return early instead.
Remove some obvious comments that don't add more clarity.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
target/ppc/mmu_common.c | 44 ++++++++++++++++++-----------------------
1 file changed, 19 insertions(+), 25 deletions(-)
diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c
index a035cefcad..564fcc7cfb 100644
--- a/target/ppc/mmu_common.c
+++ b/target/ppc/mmu_common.c
@@ -99,32 +99,26 @@ static int ppc6xx_tlb_pte_check(mmu_ctx_t *ctx,
target_ulong pte0,
MMUAccessType access_type)
{
/* Check validity and table match */
- if (pte_is_valid(pte0) && ((pte0 >> 6) & 1) == pteh) {
- /* Check vsid & api */
- if ((pte0 & PTE_PTEM_MASK) == ctx->ptem) {
- if (ctx->raddr != (hwaddr)-1ULL) {
- /* all matches should have equal RPN, WIMG & PP */
- if ((ctx->raddr & PTE_CHECK_MASK) != (pte1 & PTE_CHECK_MASK)) {
- qemu_log_mask(CPU_LOG_MMU, "Bad RPN/WIMG/PP\n");
- return -3;
- }
- }
- /* Keep the matching PTE information */
- ctx->raddr = pte1;
- ctx->prot = ppc_hash32_pp_prot(ctx->key, pte1 & HPTE32_R_PP,
- ctx->nx);
- if (check_prot_access_type(ctx->prot, access_type)) {
- /* Access granted */
- qemu_log_mask(CPU_LOG_MMU, "PTE access granted !\n");
- return 0;
- } else {
- /* Access right violation */
- qemu_log_mask(CPU_LOG_MMU, "PTE access rejected\n");
- return -2;
- }
- }
+ if (!pte_is_valid(pte0) || ((pte0 >> 6) & 1) != pteh ||
+ (pte0 & PTE_PTEM_MASK) != ctx->ptem) {
+ return -1;
+ }
+ /* all matches should have equal RPN, WIMG & PP */
+ if (ctx->raddr != (hwaddr)-1ULL &&
+ (ctx->raddr & PTE_CHECK_MASK) != (pte1 & PTE_CHECK_MASK)) {
+ qemu_log_mask(CPU_LOG_MMU, "Bad RPN/WIMG/PP\n");
+ return -3;
+ }
+ /* Keep the matching PTE information */
+ ctx->raddr = pte1;
+ ctx->prot = ppc_hash32_pp_prot(ctx->key, pte1 & HPTE32_R_PP, ctx->nx);
+ if (check_prot_access_type(ctx->prot, access_type)) {
+ qemu_log_mask(CPU_LOG_MMU, "PTE access granted !\n");
+ return 0;
+ } else {
+ qemu_log_mask(CPU_LOG_MMU, "PTE access rejected\n");
+ return -2;
}
- return -1;
}
/* Software driven TLB helpers */
--
2.30.9
- [PATCH v6 17/48] target/ppc/mmu_common.c: Don't use mmu_ctx_t for mmu40x_get_physical_address(), (continued)
- [PATCH v6 17/48] target/ppc/mmu_common.c: Don't use mmu_ctx_t for mmu40x_get_physical_address(), BALATON Zoltan, 2024/05/10
- [PATCH v6 09/48] target/ppc/mmu_common.c: Move some debug logging, BALATON Zoltan, 2024/05/10
- [PATCH v6 08/48] target/ppc/mmu_common.c: Move else branch to avoid large if block, BALATON Zoltan, 2024/05/10
- [PATCH v6 30/48] target/ppc: Remove id_tlbs flag from CPU env, BALATON Zoltan, 2024/05/10
- [PATCH v6 43/48] target/ppc/mmu_common.c: Remove unused field from mmu_ctx_t, BALATON Zoltan, 2024/05/10
- [PATCH v6 41/48] target/ppc/mmu_common.c: Return directly in ppc6xx_tlb_pte_check(), BALATON Zoltan, 2024/05/10
- [PATCH v6 24/48] target/ppc/mmu_common.c: Simplify ppc_booke_xlate() part 2, BALATON Zoltan, 2024/05/10
- [PATCH v6 34/48] target/ppc: Add a function to check for page protection bit, BALATON Zoltan, 2024/05/10
- [PATCH v6 25/48] target/ppc/mmu_common.c: Split off real mode handling from get_physical_address_wtlb(), BALATON Zoltan, 2024/05/10
- [PATCH v6 36/48] target/ppc/mmu_common.c: Remove local name for a constant, BALATON Zoltan, 2024/05/10
- [PATCH v6 42/48] target/ppc/mmu_common.c: Simplify ppc6xx_tlb_pte_check(),
BALATON Zoltan <=
- [PATCH v6 33/48] target/ppc/mmu-radix64.c: Drop a local variable, BALATON Zoltan, 2024/05/10
- [PATCH v6 31/48] target/ppc: Split off common embedded TLB init, BALATON Zoltan, 2024/05/10
- [PATCH v6 28/48] target/ppc/mmu_common.c: Move mmu_ctx_t type to mmu_common.c, BALATON Zoltan, 2024/05/10
- [PATCH v6 23/48] target/ppc/mmu_common.c: Simplify ppc_booke_xlate() part 1, BALATON Zoltan, 2024/05/10
- [PATCH v6 19/48] target/ppc/mmu_common.c: Don't use mmu_ctx_t in mmubooke206_get_physical_address(), BALATON Zoltan, 2024/05/10
- [PATCH v6 20/48] target/ppc: Remove pp_check() and reuse ppc_hash32_pp_prot(), BALATON Zoltan, 2024/05/10
- [PATCH v6 47/48] target/ppc/mmu_common.c: Remove single use local variable, BALATON Zoltan, 2024/05/10
- [PATCH v6 48/48] target/ppc/mmu_common.c: Simplify a switch statement, BALATON Zoltan, 2024/05/10
- [PATCH v6 44/48] target/ppc/mmu_common.c: Remove hash field from mmu_ctx_t, BALATON Zoltan, 2024/05/10
- [PATCH v6 38/48] target/ppc/mmu_common.c: Remove single use local variable, BALATON Zoltan, 2024/05/10