qemu.git
8 months agotarget/arm: Avoid shifts by -1 in tszimm_shr() and tszimm_shl()
Peter Maydell [Mon, 22 Jul 2024 17:29:56 +0000 (18:29 +0100)]
target/arm: Avoid shifts by -1 in tszimm_shr() and tszimm_shl()

The function tszimm_esz() returns a shift amount, or possibly -1 in
certain cases that correspond to unallocated encodings in the
instruction set.  We catch these later in the trans_ functions
(generally with an "a-esz < 0" check), but before we do the
decodetree-generated code will also call tszimm_shr() or tszimm_sl(),
which will use the tszimm_esz() return value as a shift count without
checking that it is not negative, which is undefined behaviour.

Avoid the UB by checking the return value in tszimm_shr() and
tszimm_shl().

Cc: qemu-stable@nongnu.org
Resolves: Coverity CID 15476171547694
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20240722172957.1041231-4-peter.maydell@linaro.org

8 months agotarget/arm: Fix UMOPA/UMOPS of 16-bit values
Peter Maydell [Mon, 22 Jul 2024 17:29:55 +0000 (18:29 +0100)]
target/arm: Fix UMOPA/UMOPS of 16-bit values

The UMOPA/UMOPS instructions are supposed to multiply unsigned 8 or
16 bit elements and accumulate the products into a 64-bit element.
In the Arm ARM pseudocode, this is done with the usual
infinite-precision signed arithmetic.  However our implementation
doesn't quite get it right, because in the DEF_IMOP_64() macro we do:
  sum += (NTYPE)(n >> 0) * (MTYPE)(m >> 0);

where NTYPE and MTYPE are uint16_t or int16_t.  In the uint16_t case,
the C usual arithmetic conversions mean the values are converted to
"int" type and the multiply is done as a 32-bit multiply.  This means
that if the inputs are, for example, 0xffff and 0xffff then the
result is 0xFFFE0001 as an int, which is then promoted to uint64_t
for the accumulation into sum; this promotion incorrectly sign
extends the multiply.

Avoid the incorrect sign extension by casting to int64_t before
the multiply, so we do the multiply as 64-bit signed arithmetic,
which is a type large enough that the multiply can never
overflow into the sign bit.

(The equivalent 8-bit operations in DEF_IMOP_32() are fine, because
the 8-bit multiplies can never overflow into the sign bit of a
32-bit integer.)

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2372
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20240722172957.1041231-3-peter.maydell@linaro.org

8 months agotarget/arm: Don't assert for 128-bit tile accesses when SVL is 128
Peter Maydell [Mon, 22 Jul 2024 17:29:54 +0000 (18:29 +0100)]
target/arm: Don't assert for 128-bit tile accesses when SVL is 128

For an instruction which accesses a 128-bit element tile when
the SVL is also 128 (for example MOV z0.Q, p0/M, ZA0H.Q[w0,0]),
we will assert in get_tile_rowcol():

qemu-system-aarch64: ../../tcg/tcg-op.c:926: tcg_gen_deposit_z_i32: Assertion `len > 0' failed.

This happens because we calculate
    len = ctz32(streaming_vec_reg_size(s)) - esz;$
but if the SVL and the element size are the same len is 0, and
the deposit operation asserts.

In this case the ZA storage contains exactly one 128 bit
element ZA tile, and the horizontal or vertical slice is just
that tile. This means that regardless of the index value in
the Ws register, we always access that tile. (In pseudocode terms,
we calculate (index + offset) MOD 1, which is 0.)

Special case the len == 0 case to avoid hitting the assertion
in tcg_gen_deposit_z_i32().

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20240722172957.1041231-2-peter.maydell@linaro.org

8 months agohw/misc/bcm2835_property: Reduce scope of variables in mbox push function
Peter Maydell [Tue, 23 Jul 2024 13:10:29 +0000 (14:10 +0100)]
hw/misc/bcm2835_property: Reduce scope of variables in mbox push function

In bcm2835_property_mbox_push(), some variables are defined at function scope
but used only in a smaller scope of the function:
 * tag, bufsize, resplen are used only in the body of the while() loop
 * tmp is used only for RPI_FWREQ_SET_POWER_STATE (and is badly named)

Declare these variables in the scope where they're needed, so the code
is easier to read.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20240723131029.1159908-5-peter.maydell@linaro.org

8 months agohw/misc/bcm2835_property: Restrict scope of start_num, number, otp_row
Peter Maydell [Tue, 23 Jul 2024 13:10:28 +0000 (14:10 +0100)]
hw/misc/bcm2835_property: Restrict scope of start_num, number, otp_row

In the long function bcm2835_property_mbox_push(), the variables
start_num, number and otp_row are used only in the four cases which
access OTP data, and their uses don't overlap with each other.

Make these variables have scope restricted to the cases where they're
used, so it's easier to read each individual case without having to
cross-refer up to the variable declaration at the top of the function
and check whether the variable is also used later in the loop.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20240723131029.1159908-4-peter.maydell@linaro.org

8 months agohw/misc/bcm2835_property: Avoid overflow in OTP access properties
Peter Maydell [Tue, 23 Jul 2024 13:10:27 +0000 (14:10 +0100)]
hw/misc/bcm2835_property: Avoid overflow in OTP access properties

Coverity points out that in our handling of the property
RPI_FWREQ_SET_CUSTOMER_OTP we have a potential overflow.  This
happens because we read start_num and number from the guest as
unsigned 32 bit integers, but then the variable 'n' we use as a loop
counter as we iterate from start_num to start_num + number is only an
"int".  That means that if the guest passes us a very large start_num
we will interpret it as negative.  This will result in an assertion
failure inside bcm2835_otp_set_row(), which checks that we didn't
pass it an invalid row number.

A similar issue applies to all the properties for accessing OTP rows
where we are iterating through with a start and length read from the
guest.

Use uint32_t for the loop counter to avoid this problem. Because in
all cases 'n' is only used as a loop counter, we can do this as
part of the for(), restricting its scope to exactly where we need it.

Resolves: Coverity CID 1549401
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20240723131029.1159908-3-peter.maydell@linaro.org

8 months agohw/misc/bcm2835_property: Fix handling of FRAMEBUFFER_SET_PALETTE
Peter Maydell [Tue, 23 Jul 2024 13:10:26 +0000 (14:10 +0100)]
hw/misc/bcm2835_property: Fix handling of FRAMEBUFFER_SET_PALETTE

The documentation of the "Set palette" mailbox property at
https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface#set-palette
says it has the form:

    Length: 24..1032
    Value:
        u32: offset: first palette index to set (0-255)
        u32: length: number of palette entries to set (1-256)
        u32...: RGBA palette values (offset to offset+length-1)

We get this wrong in a couple of ways:
 * we aren't checking the offset and length are in range, so the guest
   can make us spin for a long time by providing a large length
 * the bounds check on our loop is wrong: we should iterate through
   'length' palette entries, not 'length - offset' entries

Fix the loop to implement the bounds checks and get the loop
condition right. In the process, make the variables local to
this switch case, rather than function-global, so it's clearer
what type they are when reading the code.

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20240723131029.1159908-2-peter.maydell@linaro.org

8 months agohvf: arm: Do not advance PC when raising an exception
Akihiko Odaki [Sat, 20 Jul 2024 09:30:54 +0000 (18:30 +0900)]
hvf: arm: Do not advance PC when raising an exception

This is identical with commit 30a1690f2402 ("hvf: arm: Do not advance
PC when raising an exception") but for writes instead of reads.

Fixes: a2260983c655 ("hvf: arm: Add support for GICv3")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8 months agohvf: arm: Properly disable PMU
Akihiko Odaki [Sat, 20 Jul 2024 09:30:53 +0000 (18:30 +0900)]
hvf: arm: Properly disable PMU

Setting pmu property used to have no effect for hvf so fix it.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8 months agohvf: arm: Raise an exception for sysreg by default
Akihiko Odaki [Sat, 20 Jul 2024 09:30:52 +0000 (18:30 +0900)]
hvf: arm: Raise an exception for sysreg by default

Any sysreg access results in an exception unless defined otherwise so
we should raise an exception by default.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8 months agotarget/arm/kvm: Do not silently remove PMU
Akihiko Odaki [Sat, 20 Jul 2024 09:30:50 +0000 (18:30 +0900)]
target/arm/kvm: Do not silently remove PMU

kvm_arch_init_vcpu() used to remove PMU when it is not available even
if the CPU model needs one. It is semantically incorrect, and may
continue execution on a misbehaving host that advertises a CPU model
while lacking its PMU. Keep the PMU when the CPU model needs one, and
let kvm_arm_vcpu_init() fail if the KVM implementation mismatches with
our expectation.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8 months agotarget/arm/kvm: Set PMU for host only when available
Akihiko Odaki [Sat, 20 Jul 2024 09:30:49 +0000 (18:30 +0900)]
target/arm/kvm: Set PMU for host only when available

target/arm/kvm.c checked PMU availability but unconditionally set the
PMU feature flag for the host CPU model, which is confusing. Set the
feature flag only when available.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8 months agohw/arm/smmuv3: Assert input to oas2bits() is valid
Mostafa Saleh [Mon, 29 Jul 2024 12:34:18 +0000 (13:34 +0100)]
hw/arm/smmuv3: Assert input to oas2bits() is valid

Coverity has spotted a possible problem with the OAS handling
(CID 1558464), where the error return of oas2bits() -1 is not
checked, which can cause an overflow in oas value.

oas2bits() is only called with valid inputs, harden the function
to assert that.

Reported-By: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Mostafa Saleh <smostafa@google.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Message-id: 20240722103531.2377348-1-smostafa@google.com
Link: https://lore.kernel.org/qemu-devel/CAFEAcA-H=n-3mHC+eL6YjfL1m+x+b+Fk3mkgZbN74WNxifFVow@mail.gmail.com/
Signed-off-by: Mostafa Saleh <smostafa@google.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8 months agohw/char/bcm2835_aux: Fix assert when receive FIFO fills up
Frederik van Hövell [Mon, 29 Jul 2024 12:34:18 +0000 (13:34 +0100)]
hw/char/bcm2835_aux: Fix assert when receive FIFO fills up

When a bare-metal application on the raspi3 board reads the
AUX_MU_STAT_REG MMIO register while the device's buffer is
at full receive FIFO capacity
(i.e. `s->read_count == BCM2835_AUX_RX_FIFO_LEN`) the
assertion `assert(s->read_count < BCM2835_AUX_RX_FIFO_LEN)`
fails.

Reported-by: Cryptjar <cryptjar@junk.studio>
Suggested-by: Cryptjar <cryptjar@junk.studio>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/459
Signed-off-by: Frederik van Hövell <frederik@fvhovell.nl>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
[PMM: commit message tweaks]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8 months agoMerge tag 'pull-ppc-for-9.1-2-20240726-1' of https://gitlab.com/npiggin/qemu into...
Richard Henderson [Fri, 26 Jul 2024 05:10:45 +0000 (15:10 +1000)]
Merge tag 'pull-ppc-for-9.1-2-20240726-1' of https://gitlab.com/npiggin/qemu into staging

fixes

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCgAdFiEETkN92lZhb0MpsKeVZ7MCdqhiHK4FAmai5TsACgkQZ7MCdqhi
# HK4rgA//eh0ax3JnBGma1rVEDL5n5cdEYV+ATFYGc529CUZFUar3IMqSw3in8bJy
# uvQ6Cr/7IuusNEtoiYtdN1yNasqsm3fZB/hZ/Ekz32TsbpBRdkJW3ucavAu2rGM/
# EKRo7Y8gciy/Mj9y2JlIZqsDqYe+gribfGQvIg27DX+caAW/lKQdAdt4oJMTSdmr
# XR8JjtMdhUazKrI+bc/4EG6tIQyUdp+S1/z1q6Wthqt58dNRElTjkD9op4AsUWMu
# CE4a8ALCZoj3P3m+xf7xi7fT2JC2xgmNRCi3KbbhVEHdbFB6ViNYNuEYRS6GmpdC
# C6J/ZR6QXs6KB1KO7EyB+vsuxLX4Eb8aeCFxwMlzJ9Fo4g8JudABXOFzYTKX1xBn
# DUIGX91YACV43M2MvP/KuEU4zWpREO+U8MbQs/6s6fYsnCO2eKVJt/0Aaf1hmk37
# gY5Ak2DRx5TBvxlFy87zgHxHWTh/dGZodpN3IvCIDzVLnHGFlfluJbFRaoZSOecb
# 1vxDHORjIruLcAxNVEGkJ/6MxOrnjjoUzSPUQcbgJ5BpFZOdeGLiMAULu/HBLBd9
# 7dvVw+PeNEPJttYumljOD6nYc/jENhLQsvkc3++bwGNc/rpi4YngtB4jhT1HV2Cl
# oLool2ooKZgV4qx6IzeYo9feElvWVNK5XPzqDpSDlt9MaI+yTYM=
# =FxPm
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 26 Jul 2024 09:52:27 AM AEST
# gpg:                using RSA key 4E437DDA56616F4329B0A79567B30276A8621CAE
# gpg: Good signature from "Nicholas Piggin <npiggin@gmail.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 4E43 7DDA 5661 6F43 29B0  A795 67B3 0276 A862 1CAE

* tag 'pull-ppc-for-9.1-2-20240726-1' of https://gitlab.com/npiggin/qemu: (96 commits)
  target/ppc: Remove includes from mmu-book3s-v3.h
  target/ppc/mmu-radix64: Remove externally unused parts from header
  target/ppc: Unexport some functions from mmu-book3s-v3.h
  target/ppc/mmu-hash32.c: Move get_pteg_offset32() to the header
  target/ppc/mmu-hash32.c: Inline and remove ppc_hash32_pte_raddr()
  target/ppc/mmu_common.c: Remove mmu_ctx_t
  target/ppc/mmu_common.c: Stop using ctx in get_bat_6xx_tlb()
  target/ppc: Remove bat_size_prot()
  target/ppc/mmu_common.c: Use defines instead of numeric constants
  target/ppc/mmu_common.c: Rename function parameter
  target/ppc/mmu_common.c: Stop using ctx in ppc6xx_tlb_check()
  target/ppc/mmu_common.c: Remove key field from mmu_ctx_t
  target/ppc/mmu_common.c: Init variable in function that relies on it
  target/ppc/mmu-hash32.c: Inline and remove ppc_hash32_pte_prot()
  target/ppc: Add function to get protection key for hash32 MMU
  target/ppc/mmu_common.c: Remove ptem field from mmu_ctx_t
  target/ppc/mmu_common.c: Inline and remove ppc6xx_tlb_pte_check()
  target/ppc/mmu_common.c: Simplify a switch statement
  target/ppc/mmu_common.c: Remove single use local variable
  target/ppc/mmu_common.c: Convert local variable to bool
  ...

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8 months agotarget/ppc: Remove includes from mmu-book3s-v3.h
BALATON Zoltan [Sun, 26 May 2024 23:13:08 +0000 (01:13 +0200)]
target/ppc: Remove includes from mmu-book3s-v3.h

Drop includes from header that is not needed by the header itself and
only include them from C files that really need it.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Acked-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu-radix64: Remove externally unused parts from header
BALATON Zoltan [Sun, 26 May 2024 23:13:07 +0000 (01:13 +0200)]
target/ppc/mmu-radix64: Remove externally unused parts from header

Move the parts not needed outside of mmu-radix64.c from the header to
the C file to leave only parts in the header that need to be exported.
Also drop unneded include of this header.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Acked-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Unexport some functions from mmu-book3s-v3.h
BALATON Zoltan [Sun, 26 May 2024 23:13:06 +0000 (01:13 +0200)]
target/ppc: Unexport some functions from mmu-book3s-v3.h

The ppc_hash64_hpt_base() and ppc_hash64_hpt_mask() functions are
mostly used by mmu-hash64.c only but there is one call to
ppc_hash64_hpt_mask() in hw/ppc/spapr_vhyp_mmu.c.in a helper function
that can be moved to mmu-hash64.c which allows these functions to be
removed from the header.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu-hash32.c: Move get_pteg_offset32() to the header
BALATON Zoltan [Sun, 26 May 2024 23:13:05 +0000 (01:13 +0200)]
target/ppc/mmu-hash32.c: Move get_pteg_offset32() to the header

This function is a simple shared function, move it to other similar
static inline functions in the header.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu-hash32.c: Inline and remove ppc_hash32_pte_raddr()
BALATON Zoltan [Sun, 26 May 2024 23:13:04 +0000 (01:13 +0200)]
target/ppc/mmu-hash32.c: Inline and remove ppc_hash32_pte_raddr()

This function is used only once and does not add more clarity than
doing it inline.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove mmu_ctx_t
BALATON Zoltan [Sun, 26 May 2024 23:13:03 +0000 (01:13 +0200)]
target/ppc/mmu_common.c: Remove mmu_ctx_t

Completely get rid of mmu_ctx_t after converting the remaining
functions to pass raddr and prot without the context struct.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Stop using ctx in get_bat_6xx_tlb()
BALATON Zoltan [Sun, 26 May 2024 23:13:02 +0000 (01:13 +0200)]
target/ppc/mmu_common.c: Stop using ctx in get_bat_6xx_tlb()

Pass raddr and prot in function parameters instead

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Remove bat_size_prot()
BALATON Zoltan [Sun, 26 May 2024 23:13:01 +0000 (01:13 +0200)]
target/ppc: Remove bat_size_prot()

There is already a hash32_bat_prot() function that does most if this
and the rest can be inlined. Export hash32_bat_prot() and rename it to
ppc_hash32_bat_prot() to match other functions and use it in
get_bat_6xx_tlb().

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Use defines instead of numeric constants
BALATON Zoltan [Sun, 26 May 2024 23:13:00 +0000 (01:13 +0200)]
target/ppc/mmu_common.c: Use defines instead of numeric constants

Replace some BAT related constants with defines from mmu-hash32.h

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Rename function parameter
BALATON Zoltan [Sun, 26 May 2024 23:12:59 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Rename function parameter

Rename parameter of get_bat_6xx_tlb() from virtual to eaddr to match
other functions.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Stop using ctx in ppc6xx_tlb_check()
BALATON Zoltan [Sun, 26 May 2024 23:12:58 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Stop using ctx in ppc6xx_tlb_check()

Pass raddr and prot in function parameters instead.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove key field from mmu_ctx_t
BALATON Zoltan [Sun, 26 May 2024 23:12:57 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove key field from mmu_ctx_t

Pass it as a function parameter and remove it from mmu_ctx_t.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Init variable in function that relies on it
BALATON Zoltan [Sun, 26 May 2024 23:12:56 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Init variable in function that relies on it

The ppc6xx_tlb_check() relies on the caller to initialise raddr field
in ctx. Move this init from the only caller into the function.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu-hash32.c: Inline and remove ppc_hash32_pte_prot()
BALATON Zoltan [Sun, 26 May 2024 23:12:55 +0000 (01:12 +0200)]
target/ppc/mmu-hash32.c: Inline and remove ppc_hash32_pte_prot()

This is used only once and can be inlined.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Add function to get protection key for hash32 MMU
BALATON Zoltan [Sun, 26 May 2024 23:12:54 +0000 (01:12 +0200)]
target/ppc: Add function to get protection key for hash32 MMU

Add a function to get key bit from SR and use it instead of open coded
version.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove ptem field from mmu_ctx_t
BALATON Zoltan [Sun, 26 May 2024 23:12:53 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove ptem field from mmu_ctx_t

Instead of passing around ptem in context use it once in the same
function so it can be removed from mmu_ctx_t.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Inline and remove ppc6xx_tlb_pte_check()
BALATON Zoltan [Sun, 26 May 2024 23:12:51 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Inline and remove ppc6xx_tlb_pte_check()

This function is only called once and we can make the caller simpler
by inlining it.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Simplify a switch statement
BALATON Zoltan [Sun, 26 May 2024 23:12:50 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Simplify a switch statement

In mmu6xx_get_physical_address() the switch handles all cases so the
default is never reached and can be dropped. Also group together cases
which just return -4.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove single use local variable
BALATON Zoltan [Sun, 26 May 2024 23:12:49 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove single use local variable

In mmu6xx_get_physical_address() tagtet_page_bits local is declared
only to use TARGET_PAGE_BITS once. Drop the unneeded variable.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Convert local variable to bool
BALATON Zoltan [Sun, 26 May 2024 23:12:48 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Convert local variable to bool

In mmu6xx_get_physical_address() ds is used as bool, declare it as
such. Also use named constant instead of hex value.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove nx field from mmu_ctx_t
BALATON Zoltan [Sun, 26 May 2024 23:12:47 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove nx field from mmu_ctx_t

Pass it as a parameter instead. Also use named constants instead of
hex values when extracting bits from SR.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove pte_update_flags()
BALATON Zoltan [Sun, 26 May 2024 23:12:46 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove pte_update_flags()

This function is used only once, its return value is ignored and one
of its parameter is a return value from a previous call. It is better
to inline it in the caller and remove it.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove hash field from mmu_ctx_t
BALATON Zoltan [Sun, 26 May 2024 23:12:45 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove hash field from mmu_ctx_t

Return hash value via a parameter and remove it from mmu_ctx.t.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove unused field from mmu_ctx_t
BALATON Zoltan [Sun, 26 May 2024 23:12:44 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove unused field from mmu_ctx_t

The eaddr field of mmu_ctx_t is set once but never used so can be
removed.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Simplify ppc6xx_tlb_pte_check()
BALATON Zoltan [Sun, 26 May 2024 23:12:43 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Simplify ppc6xx_tlb_pte_check()

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>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Return directly in ppc6xx_tlb_pte_check()
BALATON Zoltan [Sun, 26 May 2024 23:12:42 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Return directly in ppc6xx_tlb_pte_check()

Instead of using a local ret variable return directly and remove the
local.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove yet another single use local variable
BALATON Zoltan [Sun, 26 May 2024 23:12:41 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove yet another single use local variable

In ppc6xx_tlb_pte_check() the pp variable is used only once to pass it
to a function parameter with the same name. Remove the local and
inline the value. Also use named constant for the hex value to make it
clearer.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove another single use local variable
BALATON Zoltan [Sun, 26 May 2024 23:12:40 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove another single use local variable

In ppc6xx_tlb_pte_check() the pteh variable is used only once to
compare to the h parameter of the function. Inline its value and use
pteh name for the function parameter which is more descriptive.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove single use local variable
BALATON Zoltan [Sun, 26 May 2024 23:12:39 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove single use local variable

The ptev variable in ppc6xx_tlb_pte_check() is used only once and just
obfuscates an otherwise clear value. Get rid of it.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove single use local variable
BALATON Zoltan [Sun, 26 May 2024 23:12:38 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove single use local variable

The ptem variable in ppc6xx_tlb_pte_check() is used only once,
simplify by removing it as the value is already clear itself without
adding a local name for it.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc/mmu_common.c: Remove local name for a constant
BALATON Zoltan [Sun, 26 May 2024 23:12:37 +0000 (01:12 +0200)]
target/ppc/mmu_common.c: Remove local name for a constant

The mmask local variable is a less descriptive local name for a
constant. Drop it and use the constant directly in the two places it
is needed.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Reorganise and rename ppc_hash32_pp_prot()
BALATON Zoltan [Sun, 26 May 2024 23:12:36 +0000 (01:12 +0200)]
target/ppc: Reorganise and rename ppc_hash32_pp_prot()

Reorganise ppc_hash32_pp_prot() swapping the if legs so it does not
test for negative first and clean up to make it shorter. Also rename
it to ppc_hash32_prot().

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc : Update VSX storage access insns to use tcg_gen_qemu _ld/st_i128.
Chinmay Rath [Tue, 9 Jul 2024 11:43:41 +0000 (17:13 +0530)]
target/ppc : Update VSX storage access insns to use tcg_gen_qemu _ld/st_i128.

Updated many VSX instructions to use tcg_gen_qemu_ld/st_i128, instead of using
tcg_gen_qemu_ld/st_i64 consecutively.
Introduced functions {get,set}_vsr_full to facilitate the above & for future use.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Update VMX storage access insns to use tcg_gen_qemu_ld/st_i128.
Chinmay Rath [Tue, 9 Jul 2024 11:43:40 +0000 (17:13 +0530)]
target/ppc: Update VMX storage access insns to use tcg_gen_qemu_ld/st_i128.

Updated instructions {l, st}vx to use tcg_gen_qemu_ld/st_i128,
instead of using 64 bits loads/stores in succession.
Introduced functions {get, set}_avr_full in vmx-impl.c.inc to
facilitate the above, and potential future usage.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move get/set_avr64 functions to vmx-impl.c.inc.
Chinmay Rath [Tue, 9 Jul 2024 11:43:39 +0000 (17:13 +0530)]
target/ppc: Move get/set_avr64 functions to vmx-impl.c.inc.

Those functions are used to ld/st data to and from Altivec registers,
in 64 bits chunks, and are only used in vmx-impl.c.inc file,
hence the clean-up movement.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move VSX fp compare insns to decodetree.
Chinmay Rath [Tue, 18 Jun 2024 08:58:31 +0000 (14:28 +0530)]
target/ppc: Move VSX fp compare insns to decodetree.

Moving the following instructions to decodetree specification:

xvcmp{eq, gt, ge, ne}{s, d}p : XX3-form

The changes were verified by validating that the tcg-ops generated for those
instructions remain the same which were captured using the '-d in_asm,op' flag.

Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move VSX vector storage access insns to decodetree.
Chinmay Rath [Tue, 18 Jun 2024 08:58:30 +0000 (14:28 +0530)]
target/ppc: Move VSX vector storage access insns to decodetree.

Moving the following instructions to decodetree specification:

  lxv{b16, d2, h8, w4, ds, ws}x   : X-form
  stxv{b16, d2, h8, w4}x          : X-form

The changes were verified by validating that the tcg-ops generated for those
instructions remain the same, which were captured using the '-d in_asm,op' flag.

Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move VSX vector with length storage access insns to decodetree.
Chinmay Rath [Tue, 18 Jun 2024 08:58:29 +0000 (14:28 +0530)]
target/ppc: Move VSX vector with length storage access insns to decodetree.

Moving the following instructions to decodetree specification :

        {l, st}xvl(l)           : X-form

The changes were verified by validating that the tcg-ops generated by those
instructions remain the same, which were captured using the '-d in_asm,op' flag.

Also added a new function do_ea_calc_ra to calculate the effective address :
EA <- (RA == 0) ? 0 : GPR[RA], which is now used by the above-said insns,
and shall be used later by (p){lx, stx}vp insns.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
[np: Fix 32-bit build]
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Moving VSX scalar storage access insns to decodetree.
Chinmay Rath [Tue, 18 Jun 2024 08:58:28 +0000 (14:28 +0530)]
target/ppc: Moving VSX scalar storage access insns to decodetree.

Moving the following instructions to decodetree specification :

lxs{d, iwa, ibz, ihz, iwz, sp}x : X-form
stxs{d, ib, ih, iw, sp}x : X-form

The changes were verified by validating that the tcg-ops generated by those
instructions remain the same, which were captured using the '-d in_asm,op' flag.

Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move VSX logical instructions to decodetree.
Chinmay Rath [Thu, 23 May 2024 09:48:21 +0000 (15:18 +0530)]
target/ppc: Move VSX logical instructions to decodetree.

Moving the following instructions to decodetree specification :

xxl{and, andc, or, orc, nor, xor, nand, eqv} : XX3-form

The changes were verified by validating that the tcg ops generated by those
instructions remain the same, which were captured with the '-d in_asm,op' flag.

Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move VSX arithmetic and max/min insns to decodetree.
Chinmay Rath [Thu, 23 May 2024 09:48:20 +0000 (15:18 +0530)]
target/ppc: Move VSX arithmetic and max/min insns to decodetree.

Moving the following instructions to decodetree specification:

x{s, v}{add, sub, mul, div}{s, d}p : XX3-form
xs{max, min}dp, xv{max, min}{s, d}p : XX3-form

The changes were verfied by validating that the tcg ops generated by those
instructions remain the same, which were captured with the '-d in_asm,op' flag.

Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move ISA300 flag check out of do_helper_XX3.
Chinmay Rath [Thu, 23 May 2024 09:48:19 +0000 (15:18 +0530)]
target/ppc: Move ISA300 flag check out of do_helper_XX3.

Moving PPC2_ISA300 flag check out of do_helper_XX3 method in vmx-impl.c.inc
so that the helper can be used with other instructions as well.

Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Improve VMX integer add/sub saturate instructions.
Chinmay Rath [Thu, 23 May 2024 09:44:54 +0000 (15:14 +0530)]
target/ppc: Improve VMX integer add/sub saturate instructions.

No need for a full comparison; xor produces non-zero bits for QC just fine.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Chinmay Rath <rath.chinmay@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move VMX integer add/sub saturate insns to decodetree.
Chinmay Rath [Thu, 23 May 2024 09:44:53 +0000 (15:14 +0530)]
target/ppc: Move VMX integer add/sub saturate insns to decodetree.

Moving the following instructions to decodetree specification :

v{add,sub}{u,s}{b,h,w}s : VX-form

The changes were verified by validating that the tcg ops generated by those
instructions remain the same, which were captured with the '-d in_asm,op' flag.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: Dump more END state with 'info pic'
Frederic Barrat [Wed, 24 Jul 2024 21:21:30 +0000 (16:21 -0500)]
pnv/xive2: Dump more END state with 'info pic'

Additional END state 'info pic' information as added.  The 'ignore',
'crowd' and 'precluded escalation control' bits of an Event Notification
Descriptor are all used when delivering an interrupt targeting a VP-group
or crowd.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: Refine TIMA 'info pic' output
Frederic Barrat [Wed, 24 Jul 2024 21:21:29 +0000 (16:21 -0500)]
pnv/xive2: Refine TIMA 'info pic' output

In XIVE Gen 2 there were some minor changes to the TIMA header that were
updated when printed.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: Move xive2_nvp_pic_print_info() to xive2.c
Frederic Barrat [Wed, 24 Jul 2024 21:21:28 +0000 (16:21 -0500)]
pnv/xive2: Move xive2_nvp_pic_print_info() to xive2.c

Moving xive2_nvp_pic_print_info() to align with the other "pic_print_info"
functions.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: Fail VST entry address computation if table has no VSD
Frederic Barrat [Wed, 24 Jul 2024 21:21:27 +0000 (16:21 -0500)]
pnv/xive2: Fail VST entry address computation if table has no VSD

Fail VST entry address computation if firmware doesn't define a descriptor
for one of the Virtualization Structure Tables (VST), there's no point in
trying to compute the address of its entry.  Abort the operation and log
an error.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: Set Translation Table for the NVC port space
Frederic Barrat [Wed, 24 Jul 2024 21:21:26 +0000 (16:21 -0500)]
pnv/xive2: Set Translation Table for the NVC port space

Set Translation Table for the NVC port space is missing.  The xive model
doesn't take into account the remapping of IO operations via the Set
Translation Table but firmware is allowed to define it for the Notify
Virtual Crowd (NVC), like it's already done for the other VST tables.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: Enable VST NVG and NVC index compression
Frederic Barrat [Wed, 24 Jul 2024 21:21:25 +0000 (16:21 -0500)]
pnv/xive2: Enable VST NVG and NVC index compression

Enable NVG and NVC VST tables for index compression which indicates the number
of bits the address is shifted to the right for the table accesses.
The compression values are defined as:
   0000 - No compression
   0001 - 1 bit shift
   0010 - 2 bit shift
   ....
   1000 - 8 bit shift
   1001-1111 - No compression

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: Configure Virtualization Structure Tables through the PC
Frederic Barrat [Wed, 24 Jul 2024 21:21:24 +0000 (16:21 -0500)]
pnv/xive2: Configure Virtualization Structure Tables through the PC

Both the virtualization layer (VC) and presentation layer (PC) need to
be configured to access the VSTs. Since the information is redundant,
the xive model combines both into one set of tables and only the
definitions going through the VC are kept. The definitions through the
PC are ignored. That works well as long as firmware calls the VC for
all the tables.

For the NVG and NVC tables, it can make sense to only configure them
with the PC, since they are only used by the presenter. So this patch
allows firmware to configure the VST tables through the PC as well.
The definitions are still shared, since the VST tables can be set
through both the VC and/or PC, they are dynamically re-mapped in
memory by first deleting the memory subregion.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: Add NVG and NVC to cache watch facility
Frederic Barrat [Wed, 24 Jul 2024 21:21:23 +0000 (16:21 -0500)]
pnv/xive2: Add NVG and NVC to cache watch facility

The cache watch facility uses the same register interface to handle
entries in the NVP, NVG and NVC tables. A bit-field in the 'watchX
specification' register tells the table type. So far, that bit-field
was not read and the code assumed a read/write to the NVP table.

This patch allows to read/write entries in the NVG and NVC table as
well.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive: Support cache flush and queue sync inject with notifications
Nicholas Piggin [Wed, 24 Jul 2024 21:21:22 +0000 (16:21 -0500)]
pnv/xive: Support cache flush and queue sync inject with notifications

Adds support for writing a completion notification byte in memory
whenever a cache flush or queue sync inject operation is requested by
software.  QEMU does not cache any of the XIVE data that is in memory and
therefore it simply writes the completion notification byte at the time
that the operation is requested.

Co-authored-by: Glenn Miles <milesg@linux.vnet.ibm.com>
Signed-off-by: Glenn Miles <milesg@linux.vnet.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agogitlab-ci: Use -fno-sanitize=function in the clang-user job
Richard Henderson [Tue, 23 Jul 2024 23:25:42 +0000 (09:25 +1000)]
gitlab-ci: Use -fno-sanitize=function in the clang-user job

With -fsanitize=undefined, which implies -fsanitize=function,
clang will add a "type signature" before functions.
It accesses funcptr-8 and funcptr-4 to do so.

The generated TCG prologue is directly on a page boundary,
so these accesses segfault.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20240723232543.18093-1-richard.henderson@linaro.org>

8 months agoMerge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging
Richard Henderson [Thu, 25 Jul 2024 23:34:59 +0000 (09:34 +1000)]
Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging

Pull request

Peter's AioContext thread_pool_min/max fix

# -----BEGIN PGP SIGNATURE-----
#
# iQEzBAABCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmaisQUACgkQnKSrs4Gr
# c8jd8QgAu28jTRhvqBFq9BTX4deN3P025Pqkh4oEiK/mT1yoa1W2WtAt9irgMS9v
# TQaSPwknGF61y8fChlmsDKx6TT3EVo4lryTwc9MS2cnkwWH4nxA4Udf6VsiYKYHg
# RB2OkCiZeEjejuZkIfBcDLkrStxtKfoE4PUZAzP+NQ4uWJCpFqPT6sUhXlkAHqyC
# 0nuyCD7ixxp2KBzyemKgsHEoQJPWvz4x17+DMjBFOWf55wBZVdvQciJQoHYmnKOK
# 8m0VW6QuC5TsgAUz5NUUyNigHzK0TgduCdNkogTOy8Hl0wst/UHGzPe+9VyPglmi
# jOu8eZaVy/5DUoJWX5l7u/4U/XNeKQ==
# =Yf0z
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 26 Jul 2024 06:09:41 AM AEST
# gpg:                using RSA key 8695A8BFD3F97CDAAC35775A9CA4ABB381AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" [full]
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>" [full]

* tag 'block-pull-request' of https://gitlab.com/stefanha/qemu:
  util/async.c: Forbid negative min/max in aio_context_set_thread_pool_params()

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8 months agopnv/xive2: Structure/define alignment changes
Michael Kowal [Wed, 24 Jul 2024 21:21:21 +0000 (16:21 -0500)]
pnv/xive2: Structure/define alignment changes

Made changes to some structure and define elements to ease review in
next patchset.

Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agopnv/xive2: XIVE2 Cache Watch, Cache Flush and Sync Injection support
Frederic Barrat [Wed, 24 Jul 2024 21:21:20 +0000 (16:21 -0500)]
pnv/xive2: XIVE2 Cache Watch, Cache Flush and Sync Injection support

XIVE offers a 'cache watch facility', which allows software to read/update
a potentially cached table entry with no software lock. There's one such
facility in the Virtualization Controller (VC) to update the ESB and END
entries and one in the Presentation Controller (PC) to update the
NVP/NVG/NVC entries.

Each facility has 4 cache watch engines to control the updates and
firmware can request an available engine by querying the hardware
'watch_assign' register of the VC or PC. The engine is then reserved and
is released after the data is updated by reading the 'watch_spec' register
(which also allows to check for a conflict during the update).
If no engine is available, the special value 0xFF is returned and
firmware is expected to repeat the request until an engine becomes
available.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Kowal <kowal@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotests/qtest: Add pnv-spi-seeprom qtest
Chalapathi V [Wed, 26 Jun 2024 09:05:28 +0000 (04:05 -0500)]
tests/qtest: Add pnv-spi-seeprom qtest

In this commit Write a qtest pnv-spi-seeprom-test to check the
SPI transactions between spi controller and seeprom device.

Signed-off-by: Chalapathi V <chalapathi.v@linux.ibm.com>
Acked-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Caleb Schlossin <calebs@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agohw/ppc: SPI controller wiring to P10 chip
Chalapathi V [Wed, 26 Jun 2024 09:05:27 +0000 (04:05 -0500)]
hw/ppc: SPI controller wiring to P10 chip

In this commit, create SPI controller on p10 chip and connect cs irq.

The QOM tree of pnv-spi and seeprom are.
/machine (powernv10-machine)
  /chip[0] (power10_v2.0-pnv-chip)
    /pib_spic[2] (pnv-spi)
      /pnv-spi-bus.2 (SSI)
      /xscom-spi[0] (memory-region)

/machine (powernv10-machine)
  /peripheral-anon (container)
    /device[0] (25csm04)
      /WP#[0] (irq)
      /ssi-gpio-cs[0] (irq)

(qemu) qom-get /machine/peripheral-anon /device[76] "parent_bus"
"/machine/chip[0]/pib_spic[2]/pnv-spi-bus.2"

Signed-off-by: Chalapathi V <chalapathi.v@linux.ibm.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agohw/block: Add Microchip's 25CSM04 to m25p80
Chalapathi V [Wed, 26 Jun 2024 09:05:26 +0000 (04:05 -0500)]
hw/block: Add Microchip's 25CSM04 to m25p80

Add Microchip's 25CSM04 Serial EEPROM to m25p80.  25CSM04 provides 4 Mbits
of Serial EEPROM utilizing the Serial Peripheral Interface (SPI) compatible
bus. The device is organized as 524288 bytes of 8 bits each (512Kbyte) and
is optimized for use in consumer and industrial applications where reliable
and dependable nonvolatile memory storage is essential.

Signed-off-by: Chalapathi V <chalapathi.v@linux.ibm.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agohw/ssi: Extend SPI model
Chalapathi V [Wed, 26 Jun 2024 09:05:25 +0000 (04:05 -0500)]
hw/ssi: Extend SPI model

In this commit SPI shift engine and sequencer logic is implemented.
Shift engine performs serialization and de-serialization according to the
control by the sequencer and according to the setup defined in the
configuration registers. Sequencer implements the main control logic and
FSM to handle data transmit and data receive control of the shift engine.

Signed-off-by: Chalapathi V <chalapathi.v@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.vnet.ibm.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agohw/ssi: Add SPI model
Chalapathi V [Wed, 26 Jun 2024 09:05:24 +0000 (04:05 -0500)]
hw/ssi: Add SPI model

SPI controller device model supports a connection to a single SPI responder.
This provide access to SPI seeproms, TPM, flash device and an ADC controller.

All SPI function control is mapped into the SPI register space to enable full
control by firmware. In this commit SPI configuration component is modelled
which contains all SPI configuration and status registers as well as the hold
registers for data to be sent or having been received.

An existing QEMU SSI framework is used and SSI_BUS is created.

Signed-off-by: Chalapathi V <chalapathi.v@linux.ibm.com>
Reviewed-by: Caleb Schlossin <calebs@linux.vnet.ibm.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
[np: Fix FDT macro compile for qtest]
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Remove ppc target dependency from pnv_xscom.h
Chalapathi V [Wed, 26 Jun 2024 09:05:23 +0000 (04:05 -0500)]
ppc/pnv: Remove ppc target dependency from pnv_xscom.h

In this commit target specific dependency from include/hw/ppc/pnv_xscom.h
has been removed so that pnv_xscom.h can be included outside hw/ppc.

Signed-off-by: Chalapathi V <chalapathi.v@linux.ibm.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Caleb Schlossin <calebs@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Add an LPAR per core machine option
Nicholas Piggin [Fri, 24 May 2024 05:02:46 +0000 (15:02 +1000)]
ppc/pnv: Add an LPAR per core machine option

Recent POWER CPUs can operate in "LPAR per core" or "LPAR per thread"
modes. In per-core mode, some SPRs and IPI doorbells are shared between
threads in a core. In per-thread mode, supervisor and user state is
not shared between threads.

OpenPOWER systems after POWER8 use LPAR per thread mode, and it is
required for KVM. Enterprise systems use LPAR per core mode, as they
partition the machine by core.

Implement a lpar-per-core machine option for powernv machines. This
is fixed true for POWER8 machines, and defaults off for P9 and P10.

With this change, powernv8 SMT now works sufficiently to run Linux,
with a single socket. Multi-threaded KVM guests still have problems,
as does multi-socket Linux boot.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Implement POWER10 PC xscom registers for direct controls
Nicholas Piggin [Thu, 16 May 2024 13:44:12 +0000 (23:44 +1000)]
ppc/pnv: Implement POWER10 PC xscom registers for direct controls

The PC unit in the processor core contains xscom registers that provide
low level status and control of the CPU.

This implements "direct controls", sufficient for skiboot firmware,
which uses it to send NMI IPIs between CPUs.

POWER10 is sufficiently different from POWER9 (particularly with respect
to QME and special wakeup) that it is not trivial to implement POWER9
support by reusing the code.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Add a CPU nmi and resume function
Nicholas Piggin [Fri, 12 Jul 2024 03:16:44 +0000 (13:16 +1000)]
ppc/pnv: Add a CPU nmi and resume function

Power CPUs have an execution control facility that can pause, resume,
and cause NMIs, among other things. Add a function that will nmi a CPU
and resume it if it was paused, in preparation for implementing the
control facility.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Add big-core machine property
Nicholas Piggin [Tue, 18 Jun 2024 02:45:34 +0000 (12:45 +1000)]
ppc/pnv: Add big-core machine property

Big-core implementation is complete, so expose it as a machine
property that may be set with big-core=on option on powernv9 and
powernv10 machines.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Add POWER10 ChipTOD quirk for big-core
Nicholas Piggin [Tue, 18 Jun 2024 03:09:54 +0000 (13:09 +1000)]
ppc/pnv: Add POWER10 ChipTOD quirk for big-core

POWER10 has a quirk in its ChipTOD addressing that requires the even
small-core to be selected even when programming the odd small-core.
This allows skiboot chiptod init to run in big-core mode.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Implement Power9 CPU core thread state indirect register
Nicholas Piggin [Thu, 11 Jul 2024 08:31:35 +0000 (18:31 +1000)]
ppc/pnv: Implement Power9 CPU core thread state indirect register

Power9 CPUs have a core thread state register accessible via SPRC/SPRD
indirect registers. This register includes a bit for big-core mode,
which skiboot requires.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Implement big-core PVR for Power9/10
Nicholas Piggin [Thu, 11 Jul 2024 08:37:25 +0000 (18:37 +1000)]
ppc/pnv: Implement big-core PVR for Power9/10

Power9/10 CPUs have PVR[51] set in small-core mode and clear in big-core
mode. This is used by skiboot firmware.

PVR is not hypervisor-privileged but it is not so important that spapr
to implement this because it's generally masked out of PVR matching code
in kernels, and only used by firmware.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Add allow for big-core differences in DT generation
Nicholas Piggin [Thu, 11 Jul 2024 09:06:14 +0000 (19:06 +1000)]
ppc/pnv: Add allow for big-core differences in DT generation

device-tree building needs to account for big-core mode, because it is
driven by qemu cores (small cores). Every second core should be skipped,
and every core should describe threads for both small-cores that make
up the big core.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Add a big-core mode that joins two regular cores
Nicholas Piggin [Thu, 16 May 2024 05:25:12 +0000 (15:25 +1000)]
ppc/pnv: Add a big-core mode that joins two regular cores

POWER9 and POWER10 machines come in two variants, big-core and
small-core. Big-core machines are SMT8 from software's point of view,
but the low level platform topology ("xscom registers and pervasive
addressing"), these look more like a pair of small cores ganged
together.

Presently the way this is modelled is to create one SMT8 PnvCore and add
special cases to xscom and pervasive for big-core mode that tries to
split this into two small cores, but this is becoming too complicated to
manage.

A better approach is to create 2 core structures and ganging them
together to look like an SMT8 core in TCG. Then the xscom and pervasive
models mostly do not need to differentiate big and small core modes.

This change adds initial mode bits and QEMU topology handling to
split SMT8 cores into 2xSMT4 cores.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc: Add has_smt_siblings property to CPUPPCState
Nicholas Piggin [Tue, 18 Jun 2024 02:56:53 +0000 (12:56 +1000)]
ppc: Add has_smt_siblings property to CPUPPCState

The decision to branch out to a slower SMT path in instruction
emulation will become a bit more complicated with the way that
"big-core" topology that will be implemented in subsequent changes.
Hide these details from the wider CPU emulation code with a bool
has_smt_siblings flag that can be set by machine initialisation.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Add helpers to check for SMT sibling threads
Nicholas Piggin [Fri, 24 May 2024 07:49:52 +0000 (17:49 +1000)]
target/ppc: Add helpers to check for SMT sibling threads

Add helpers for TCG code to determine if there are SMT siblings
sharing per-core and per-lpar registers. This simplifies the
callers and makes SMT register topology simpler to modify with
later changes.

Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc: Add a core_index to CPUPPCState for SMT vCPUs
Nicholas Piggin [Thu, 16 May 2024 05:25:12 +0000 (15:25 +1000)]
ppc: Add a core_index to CPUPPCState for SMT vCPUs

The way SMT thread siblings are matched is clunky, using hard-coded
logic that checks the PIR SPR.

Change that to use a new core_index variable in the CPUPPCState,
where all siblings have the same core_index. CPU realize routines have
flexibility in setting core/sibling topology.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Extend chip_pir class method to TIR as well
Nicholas Piggin [Fri, 24 May 2024 01:54:09 +0000 (11:54 +1000)]
ppc/pnv: Extend chip_pir class method to TIR as well

The chip_pir chip class method allows the platform to set the PIR
processor identification register. Extend this to a more general
ID function which also allows the TIR to be set. This is in
preparation for "big core", which is a more complicated topology
of cores and threads.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: use class attribute to limit SMT threads for different machines
Nicholas Piggin [Fri, 24 May 2024 05:52:04 +0000 (15:52 +1000)]
ppc/pnv: use class attribute to limit SMT threads for different machines

Use a class attribute to specify the number of SMT threads per core
permitted for different machines, 8 for powernv8 and 4 for powernv9/10.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Move SPR indirect registers into PnvCore
Nicholas Piggin [Sun, 26 May 2024 11:24:00 +0000 (21:24 +1000)]
target/ppc: Move SPR indirect registers into PnvCore

SPRC/SPRD were recently added to all BookS CPUs supported, but
they are only tested on POWER9 and POWER10, so restrict them to
those CPUs.

SPR indirect scratch registers presently replicated per-CPU like
SMT SPRs, but the PnvCore is a better place for them since they
are restricted to P9/P10.

Also add SPR indirect read access to core thread state for POWER9
since skiboot accesses that when booting to check for big-core
mode.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Move timebase state into PnvCore
Nicholas Piggin [Fri, 24 May 2024 11:58:18 +0000 (21:58 +1000)]
ppc/pnv: Move timebase state into PnvCore

The timebase state machine is per per-core state and can be driven
by any thread in the core. It is currently implemented as a hack
where the state is in a CPU structure and only thread 0's state is
accessed by the chiptod, which limits programming the timebase
side of the state machine to thread 0 of a core.

Move the state out into PnvCore and share it among all threads.

Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Add pointer from PnvCPUState to PnvCore
Nicholas Piggin [Sun, 26 May 2024 05:04:05 +0000 (15:04 +1000)]
ppc/pnv: Add pointer from PnvCPUState to PnvCore

This helps move core state from CPU to core structures.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agotarget/ppc: Fix msgsnd for POWER8
Nicholas Piggin [Sat, 6 Jul 2024 03:22:58 +0000 (13:22 +1000)]
target/ppc: Fix msgsnd for POWER8

POWER8 (ISA v2.07S) introduced the doorbell facility, the msgsnd
instruction behaved mostly like msgsndp, it was addressed by TIR
and could only send interrupts between threads on the core.

ISA v3.0 changed msgsnd to be addressed by PIR and can interrupt
any thread in the system.

msgsnd only implements the v3.0 semantics, which can make
multi-threaded POWER8 hang when booting Linux (due to IPIs
failing). This change adds v2.07 semantics.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Implement ADU access to LPC space
Nicholas Piggin [Wed, 17 Apr 2024 04:50:13 +0000 (14:50 +1000)]
ppc/pnv: Implement ADU access to LPC space

One of the functions of the ADU is indirect memory access engines that
send and receive data via ADU registers.

This implements the ADU LPC memory access functionality sufficiently
for IBM proprietary firmware to access the UART and print characters
to the serial port as it does on real hardware.

This requires a linkage between adu and lpc, which allows adu to
perform memory access in the lpc space.

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Begin a more complete ADU LPC model for POWER9/10
Nicholas Piggin [Fri, 23 Feb 2024 12:34:56 +0000 (22:34 +1000)]
ppc/pnv: Begin a more complete ADU LPC model for POWER9/10

This implements a framework for an ADU unit model.

The ADU unit actually implements XSCOM, which is the bridge between MMIO
and PIB. However it also includes control and status registers and other
functions that are exposed as PIB (xscom) registers.

To keep things simple, pnv_xscom.c remains the XSCOM bridge
implementation, and pnv_adu.c implements the ADU registers and other
functions.

So far, just the ADU no-op registers in the pnv_xscom.c default handler
are moved over to the adu model.

Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Implement POWER9 LPC PSI serirq outputs and auto-clear function
Nicholas Piggin [Fri, 10 May 2024 07:10:40 +0000 (17:10 +1000)]
ppc/pnv: Implement POWER9 LPC PSI serirq outputs and auto-clear function

The POWER8 LPC ISA device irqs all get combined and reported to the line
connected the PSI LPCHC irq. POWER9 changed this so only internal LPC
host controller irqs use that line, and the device irqs get routed to
4 new lines connected to PSI SERIRQ0-3.

POWER9 also introduced a new feature that automatically clears the irq
status in the LPC host controller when EOI'ed, so software does not have
to.

The powernv OPAL (skiboot) firmware managed to work because the LPCHC
irq handler scanned all LPC irqs and handled those including clearing
status even on POWER9 systems. So LPC irqs worked despite OPAL thinking
it was running in POWER9 mode. After this change, UART interrupts show
up on serirq1 which is where OPAL routes them to:

 cat /proc/interrupts
 ...
 20:          0  XIVE-IRQ 1048563 Level     opal-psi#0:lpchc
 ...
 25:         34  XIVE-IRQ 1048568 Level     opal-psi#0:lpc_serirq_mux1

Whereas they previously turn up on lpchc.

Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
8 months agoppc/pnv: Fix loss of LPC SERIRQ interrupts
Glenn Miles [Fri, 24 May 2024 18:24:14 +0000 (13:24 -0500)]
ppc/pnv: Fix loss of LPC SERIRQ interrupts

The LPC HC irq status register bits are set when an LPC IRQSER input is
asserted. These irq status bits drive the PSI irq to the CPU interrupt
controller. The LPC HC irq status bits are cleared by software writing
to the register with 1's for the bits to clear.

Existing register write was clearing the irq status bits even when the
input was asserted, this results in interrupts being lost.

This fix changes the behavior to keep track of the device IRQ status
in internal state that is separate from the irq status register, and
only allowing the irq status bits to be cleared if the associated
input is not asserted.

Signed-off-by: Glenn Miles <milesg@linux.ibm.com>
[np: rebased before P9 PSI SERIRQ patch, adjust changelog/comments]
Reviewed-by: Glenn Miles <milesg@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>