Commit Graph

1753 Commits

Author SHA1 Message Date
Qiushi Wu 83ea63708a firmware: Fix a reference count leak.
[ Upstream commit fe3c60684377d5ad9b0569b87ed3e26e12c8173b ]

kobject_init_and_add() takes reference even when it fails.
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object.
Callback function fw_cfg_sysfs_release_entry() in kobject_put()
can handle the pointer "entry" properly.

Signed-off-by: Qiushi Wu <wu000273@umn.edu>
Link: https://lore.kernel.org/r/20200613190533.15712-1-wu000273@umn.edu
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-08-11 15:33:38 +02:00
Gavin Shan 96002e7485 drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups()
[ Upstream commit c377e67c6271954969384f9be1b1b71de13eba30 ]

The CPU mask (@tmp) should be released on failing to allocate
@cpu_groups or any of its elements. Otherwise, it leads to memory
leakage because the CPU mask variable is dynamically allocated
when CONFIG_CPUMASK_OFFSTACK is enabled.

Signed-off-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Link: https://lore.kernel.org/r/20200630075227.199624-1-gshan@redhat.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-07-29 10:18:28 +02:00
Peter Jones 8ba1913cd6 efi: Make it possible to disable efivar_ssdt entirely
commit 435d1a471598752446a72ad1201b3c980526d869 upstream.

In most cases, such as CONFIG_ACPI_CUSTOM_DSDT and
CONFIG_ACPI_TABLE_UPGRADE, boot-time modifications to firmware tables
are tied to specific Kconfig options.  Currently this is not the case
for modifying the ACPI SSDT via the efivar_ssdt kernel command line
option and associated EFI variable.

This patch adds CONFIG_EFI_CUSTOM_SSDT_OVERLAYS, which defaults
disabled, in order to allow enabling or disabling that feature during
the build.

Cc: <stable@vger.kernel.org>
Signed-off-by: Peter Jones <pjones@redhat.com>
Link: https://lore.kernel.org/r/20200615202408.2242614-1-pjones@redhat.com
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-07-09 09:37:57 +02:00
Qiushi Wu 92444a57e3 efi/esrt: Fix reference count leak in esre_create_sysfs_entry.
[ Upstream commit 4ddf4739be6e375116c375f0a68bf3893ffcee21 ]

kobject_init_and_add() takes reference even when it fails.
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object. Previous
commit "b8eb718348b8" fixed a similar problem.

Fixes: 0bb549052d ("efi: Add esrt support")
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
Link: https://lore.kernel.org/r/20200528183804.4497-1-wu000273@umn.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-30 15:36:54 -04:00
Wei Yongjun ad7f78b7ce firmware: imx: scu: Fix possible memory leak in imx_scu_probe()
[ Upstream commit 89f12d6509bff004852c51cb713a439a86816b24 ]

'chan_name' is malloced in imx_scu_probe() and should be freed
before leaving from the error handling cases, otherwise it will
cause memory leak.

Fixes: edbee095fa ("firmware: imx: add SCU firmware driver support")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-24 17:50:30 +02:00
Christoph Hellwig 0c884f3236 firmware: qcom_scm: fix bogous abuse of dma-direct internals
[ Upstream commit 459b1f86f1cba7de813fbc335df476c111feec22 ]

As far as the device is concerned the dma address is the physical
address.  There is no need to convert it to a physical address,
especially not using dma-direct internals that are not available
to drivers and which will interact badly with IOMMUs.  Last but not
least the commit introducing it claimed to just fix a type issue,
but actually changed behavior.

Fixes: 6e37ccf78a ("firmware: qcom_scm: Use proper types for dma mappings")
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20200414123136.441454-1-hch@lst.de
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-24 17:50:21 +02:00
Ard Biesheuvel c573a13f72 efi/libstub/x86: Work around LLVM ELF quirk build regression
[ Upstream commit f77767ed5f4d398b29119563155e4ece2dfeee13 ]

When building the x86 EFI stub with Clang, the libstub Makefile rules
that manipulate the ELF object files may throw an error like:

    STUBCPY drivers/firmware/efi/libstub/efi-stub-helper.stub.o
  strip: drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10
  objcopy: drivers/firmware/efi/libstub/efi-stub-helper.stub.o: Failed to find link section for section 10

This is the result of a LLVM feature [0] where symbol references are
stored in a LLVM specific .llvm_addrsig section in a non-transparent way,
causing generic ELF tools such as strip or objcopy to choke on them.

So force the compiler not to emit these sections, by passing the
appropriate command line option.

[0] https://sourceware.org/bugzilla/show_bug.cgi?id=23817

Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Collingbourne <pcc@google.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Reported-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Fangrui Song <maskray@google.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-22 09:30:52 +02:00
Jason Liu 5691e22711 Merge tag 'v5.4.47' into imx_5.4.y
* tag 'v5.4.47': (2193 commits)
  Linux 5.4.47
  KVM: arm64: Save the host's PtrAuth keys in non-preemptible context
  KVM: arm64: Synchronize sysreg state on injecting an AArch32 exception
  ...

 Conflicts:
	arch/arm/boot/dts/imx6qdl.dtsi
	arch/arm/mach-imx/Kconfig
	arch/arm/mach-imx/common.h
	arch/arm/mach-imx/suspend-imx6.S
	arch/arm64/boot/dts/freescale/imx8qxp-mek.dts
	arch/powerpc/include/asm/cacheflush.h
	drivers/cpufreq/imx6q-cpufreq.c
	drivers/dma/imx-sdma.c
	drivers/edac/synopsys_edac.c
	drivers/firmware/imx/imx-scu.c
	drivers/net/ethernet/freescale/fec.h
	drivers/net/ethernet/freescale/fec_main.c
	drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
	drivers/net/phy/phy_device.c
	drivers/perf/fsl_imx8_ddr_perf.c
	drivers/usb/cdns3/gadget.c
	drivers/usb/dwc3/gadget.c
	include/uapi/linux/dma-buf.h

Signed-off-by: Jason Liu <jason.hui.liu@nxp.com>
2020-06-19 17:32:49 +08:00
Franck LENORMAND 0070e73c9e firmware: imx: scu: Fix corruption of header
[ Upstream commit f5f27b79eab80de0287c243a22169e4876b08d5e ]

The header of the message to send can be changed if the
response is longer than the request:
 - 1st word, the header is sent
 - the remaining words of the message are sent
 - the response is received asynchronously during the
   execution of the loop, changing the size field in
   the header
 - the for loop test the termination condition using
   the corrupted header

It is the case for the API build_info which has just a
header as request but 3 words in response.

This issue is fixed storing the header locally instead of
using a pointer on it.

Fixes: edbee095fa (firmware: imx: add SCU firmware driver support)

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Cc: stable@vger.kernel.org
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-17 16:40:31 +02:00
Peng Fan a1fd068c89 firmware: imx-scu: Support one TX and one RX
[ Upstream commit f25a066d1a07affb7bea4e5d9c179c3338338e23 ]

Current imx-scu requires four TX and four RX to communicate with
SCU. This is low efficient and causes lots of mailbox interrupts.

With imx-mailbox driver could support one TX to use all four transmit
registers and one RX to use all four receive registers, imx-scu
could use one TX and one RX.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-17 16:40:31 +02:00
Leonard Crestez da24a76bdc firmware: imx: warn on unexpected RX
[ Upstream commit cf0fd404455ce13850cc15423a3c2958933de384 ]

The imx_scu_call_rpc function returns the result inside the
same "msg" struct containing the transmitted message. This is
implemented by holding a pointer to msg (which is usually on the stack)
in sc_imx_rpc and writing to it from imx_scu_rx_callback.

This means that if the have_resp parameter is incorrect or SCU sends an
unexpected response for any reason the most likely result is kernel stack
corruption.

Fix this by only setting sc_imx_rpc.msg for the duration of the
imx_scu_call_rpc call and warning in imx_scu_rx_callback if unset.

Print the unexpected response data to help debugging.

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Acked-by: Anson Huang <Anson.Huang@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-17 16:40:31 +02:00
Ard Biesheuvel e1437d181d efi/efivars: Add missing kobject_put() in sysfs entry creation error path
commit d8bd8c6e2cfab8b78b537715255be8d7557791c0 upstream.

The documentation provided by kobject_init_and_add() clearly spells out
the need to call kobject_put() on the kobject if an error is returned.
Add this missing call to the error path.

Cc: <stable@vger.kernel.org>
Reported-by: 亿一 <teroincn@gmail.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-06-17 16:40:26 +02:00
Daniel Baluta 798bd66a9c MLK-24263-3 firmware: imx-dsp: Export functions to request/free channels
In order to save power, we only need to request a channel
when the communication with the DSP active.

For this we export the following functions:
	- imx_dsp_request_channel, gets a channel with a given index
	- imx_dsp_free_channel, frees a channel with a given index

Notice that we still request channels at probe to support devices
that do not have PM callbacks implemented yet.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
2020-06-11 16:50:22 +03:00
Daniel Baluta 02e7ef1deb MLK-24263-2 firmware: imx: Save channel name for further use
We want to request / free channels on demand later in order
to save power.

For this for each channel we save the name and use it to
reference the channel later.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
2020-06-11 16:50:22 +03:00
Daniel Baluta 475354ab84 MLK-24263-1 firmware: imx: Introduce imx_dsp_setup_channels
This will factor out the code that sets up the mailbox channels
so that we can use it later.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
2020-06-11 16:50:22 +03:00
Hugo Dupras 80438c2b52 HSM-292 firmware: imx: seco_mu: Increase MAX_DATA_SIZE_PER_USER
For AES CMAC, the max supported message length is (2^16)-1. In order to
support this type of message the MAX_DATA_SIZE_PER_USER must be
increased to bigger value, in order to contains the message header and
the entire message data

Signed-off-by: Hugo Dupras <hugo.dupras@nxp.com>
Reviewed-by: Stéphane Dion <stephane.dion_1@nxp.com>
2020-05-30 03:43:21 +02:00
Loïc Yhuel f4520daa3c tpm: check event log version before reading final events
[ Upstream commit b4f1874c62168159fdb419ced4afc77c1b51c475 ]

This fixes the boot issues since 5.3 on several Dell models when the TPM
is enabled. Depending on the exact grub binary, booting the kernel would
freeze early, or just report an error parsing the final events log.

We get an event log in the SHA-1 format, which doesn't have a
tcg_efi_specid_event_head in the first event, and there is a final events
table which doesn't match the crypto agile format.
__calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", and
either fails, or loops long enough for the machine to be appear frozen.

So we now only parse the final events table, which is per the spec always
supposed to be in the crypto agile format, when we got a event log in this
format.

Fixes: c46f340569 ("tpm: Reserve the TPM final events table")
Fixes: 166a2809d6 ("tpm: Don't duplicate events from the final event log in the TCG2 log")
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1779611
Signed-off-by: Loïc Yhuel <loic.yhuel@gmail.com>
Link: https://lore.kernel.org/r/20200512040113.277768-1-loic.yhuel@gmail.com
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: Matthew Garrett <mjg59@google.com>
[ardb: warn when final events table is missing or in the wrong format]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-05-27 17:46:52 +02:00
Robert Chiras 57c96ce6a7 LF-811-3: firmware: imx: add lcd-pll power domain
Add te missing IMX_SC_R_ELCDIF_PLL id to power domain ranges.

Signed-off-by: Robert Chiras <robert.chiras@nxp.com>
2020-05-22 11:10:40 +03:00
Alice Guo 704b9cbd87 MLK-24064-1: firmware: imx: scu-pd: add power domains for lpuart
Add power domains for lpuart in ARM Cortex-M4 (CM4) Subsystem.

Signed-off-by: Alice Guo <alice.guo@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
2020-05-22 01:29:03 +08:00
Linus Torvalds 6cbb91bdd3 gcc-10: mark more functions __init to avoid section mismatch warnings
commit e99332e7b4cda6e60f5b5916cf9943a79dbef902 upstream.

It seems that for whatever reason, gcc-10 ends up not inlining a couple
of functions that used to be inlined before.  Even if they only have one
single callsite - it looks like gcc may have decided that the code was
unlikely, and not worth inlining.

The code generation difference is harmless, but caused a few new section
mismatch errors, since the (now no longer inlined) function wasn't in
the __init section, but called other init functions:

   Section mismatch in reference from the function kexec_free_initrd() to the function .init.text:free_initrd_mem()
   Section mismatch in reference from the function tpm2_calc_event_log_size() to the function .init.text:early_memremap()
   Section mismatch in reference from the function tpm2_calc_event_log_size() to the function .init.text:early_memunmap()

So add the appropriate __init annotation to make modpost not complain.
In both cases there were trivially just a single callsite from another
__init function.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-05-20 08:20:29 +02:00
Franck LENORMAND 5258913894 HSM-267-1: fw: imx: seco_mu: Handle error code in mailbox rx callback
It is possible the mailbox framework returns an error code
if there was an issue when receiving a message.

This patch adds the handling of such exception.

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
2020-04-24 11:46:09 +02:00
Franck LENORMAND 87bcafe692 MLK-23635: fw: imx: seco_mu: Fix messages at boot
At boot, the driver can print error messages because it has been
deferred so they should not be printed.
The driver also prints the version of the SECO which is not useful.

This patch fixes the print of messages due to defer and remove the
print of the SECO version.

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
2020-04-23 16:19:02 +02:00
Stéphane Dion 56d318d214 MLK-23674-3 fw: imx: seco_mu: get message header tags from dt
In order for a message sent to a V2X MU, the value indication the
type of the message chagne for each MU addressed.

This patch adds the read of the values from the device tree or
uses the default values which works with SECO MU.

Signed-off-by: Stéphane Dion <stephane.dion_1@nxp.com>
2020-04-22 15:56:40 +02:00
Stéphane Dion 0f8db28dee MLK-23674-1 imx: scu-pd: add V2X MU resources
Add the ID of the resources for the V2X MUs in order
for the MU to be powered up.

Signed-off-by: Stéphane Dion <stephane.dion_1@nxp.com>
2020-04-22 15:56:40 +02:00
Ard Biesheuvel bceda1dd47 efi/x86: Ignore the memory attributes table on i386
[ Upstream commit dd09fad9d2caad2325a39b766ce9e79cfc690184 ]

Commit:

  3a6b6c6fb2 ("efi: Make EFI_MEMORY_ATTRIBUTES_TABLE initialization common across all architectures")

moved the call to efi_memattr_init() from ARM specific to the generic
EFI init code, in order to be able to apply the restricted permissions
described in that table on x86 as well.

We never enabled this feature fully on i386, and so mapping and
reserving this table is pointless. However, due to the early call to
memblock_reserve(), the memory bookkeeping gets confused to the point
where it produces the splat below when we try to map the memory later
on:

  ------------[ cut here ]------------
  ioremap on RAM at 0x3f251000 - 0x3fa1afff
  WARNING: CPU: 0 PID: 0 at arch/x86/mm/ioremap.c:166 __ioremap_caller ...
  Modules linked in:
  CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.20.0 #48
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015
  EIP: __ioremap_caller.constprop.0+0x249/0x260
  Code: 90 0f b7 05 4e 38 40 de 09 45 e0 e9 09 ff ff ff 90 8d 45 ec c6 05 ...
  EAX: 00000029 EBX: 00000000 ECX: de59c228 EDX: 00000001
  ESI: 3f250fff EDI: 00000000 EBP: de3edf20 ESP: de3edee0
  DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068 EFLAGS: 00200296
  CR0: 80050033 CR2: ffd17000 CR3: 1e58c000 CR4: 00040690
  Call Trace:
   ioremap_cache+0xd/0x10
   ? old_map_region+0x72/0x9d
   old_map_region+0x72/0x9d
   efi_map_region+0x8/0xa
   efi_enter_virtual_mode+0x260/0x43b
   start_kernel+0x329/0x3aa
   i386_start_kernel+0xa7/0xab
   startup_32_smp+0x164/0x168
  ---[ end trace e15ccf6b9f356833 ]---

Let's work around this by disregarding the memory attributes table
altogether on i386, which does not result in a loss of functionality
or protection, given that we never consumed the contents.

Fixes: 3a6b6c6fb2 ("efi: Make EFI_MEMORY_ATTRIBUTES_TABLE ... ")
Tested-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20200304165917.5893-1-ardb@kernel.org
Link: https://lore.kernel.org/r/20200308080859.21568-21-ardb@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-04-17 10:50:03 +02:00
James Morse f9ee512dd9 firmware: arm_sdei: fix double-lock on hibernate with shared events
[ Upstream commit 6ded0b61cf638bf9f8efe60ab8ba23db60ea9763 ]

SDEI has private events that must be registered on each CPU. When
CPUs come and go they must re-register and re-enable their private
events. Each event has flags to indicate whether this should happen
to protect against an event being registered on a CPU coming online,
while all the others are unregistering the event.

These flags are protected by the sdei_list_lock spinlock, because
the cpuhp callbacks can't take the mutex.

Hibernate needs to unregister all events, but keep the in-memory
re-register and re-enable as they are. sdei_unregister_shared()
takes the spinlock to walk the list, then calls _sdei_event_unregister()
on each shared event. _sdei_event_unregister() tries to take the
same spinlock to update re-register and re-enable. This doesn't go
so well.

Push the re-register and re-enable updates out to their callers.
sdei_unregister_shared() doesn't want these values updated, so
doesn't need to do anything.

This also fixes shared events getting lost over hibernate as this
path made them look unregistered.

Fixes: da35182724 ("firmware: arm_sdei: Add support for CPU and system power states")
Reported-by: Liguang Zhang <zhangliguang@linux.alibaba.com>
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-04-17 10:50:00 +02:00
Peng Fan 0c83261a17 MLK-23754-20 firmware: imx: scu-pd: add cm4 power domains
Add CM4 core and MU_1A power domains entry.

Reviewed-by: Richard Zhu <hongxing.zhu@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
2020-04-09 10:35:41 +08:00
Franck LENORMAND 16338e4fe9 SSI-87: firmware: imx: scu: Support reception of message of any size
The word of a message can arrive in any order and the current driver
cannot receive more than 4-word message.

As the message can arrive in any order, the position where they
should be stored is stored in the sc_chan struct:
 - initialized at the index of the MU slot
 - incremented each time after a new word is stored

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
2020-03-30 15:52:49 +02:00
Vladis Dronov 849233b742 efi: Add a sanity check to efivar_store_raw()
commit d6c066fda90d578aacdf19771a027ed484a79825 upstream.

Add a sanity check to efivar_store_raw() the same way
efivar_{attr,size,data}_read() and efivar_show_raw() have it.

Signed-off-by: Vladis Dronov <vdronov@redhat.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200305084041.24053-3-vdronov@redhat.com
Link: https://lore.kernel.org/r/20200308080859.21568-25-ardb@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-18 07:17:53 +01:00
Vladis Dronov 594b38226f efi: Fix a race and a buffer overflow while reading efivars via sysfs
commit 286d3250c9d6437340203fb64938bea344729a0e upstream.

There is a race and a buffer overflow corrupting a kernel memory while
reading an EFI variable with a size more than 1024 bytes via the older
sysfs method. This happens because accessing struct efi_variable in
efivar_{attr,size,data}_read() and friends is not protected from
a concurrent access leading to a kernel memory corruption and, at best,
to a crash. The race scenario is the following:

CPU0:                                CPU1:
efivar_attr_read()
  var->DataSize = 1024;
  efivar_entry_get(... &var->DataSize)
    down_interruptible(&efivars_lock)
                                     efivar_attr_read() // same EFI var
                                       var->DataSize = 1024;
                                       efivar_entry_get(... &var->DataSize)
                                         down_interruptible(&efivars_lock)
    virt_efi_get_variable()
    // returns EFI_BUFFER_TOO_SMALL but
    // var->DataSize is set to a real
    // var size more than 1024 bytes
    up(&efivars_lock)
                                         virt_efi_get_variable()
                                         // called with var->DataSize set
                                         // to a real var size, returns
                                         // successfully and overwrites
                                         // a 1024-bytes kernel buffer
                                         up(&efivars_lock)

This can be reproduced by concurrent reading of an EFI variable which size
is more than 1024 bytes:

  ts# for cpu in $(seq 0 $(nproc --ignore=1)); do ( taskset -c $cpu \
  cat /sys/firmware/efi/vars/KEKDefault*/size & ) ; done

Fix this by using a local variable for a var's data buffer size so it
does not get overwritten.

Fixes: e14ab23dde ("efivars: efivar_entry API")
Reported-by: Bob Sanders <bob.sanders@hpe.com> and the LTP testsuite
Signed-off-by: Vladis Dronov <vdronov@redhat.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200305084041.24053-2-vdronov@redhat.com
Link: https://lore.kernel.org/r/20200308080859.21568-24-ardb@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-18 07:17:53 +01:00
Franck LENORMAND 2ccb9a596a SSI-87: firmware: imx: Add APIs required for secvio
The Security Violation module requires SC API for the SECO, RM, MISC
and IRQ.

This patch does:
 - imx-scu-irq: Allow reuse of imx_scu_irq_get_status
 - seco:
    - Add imx_sc_seco_secvio_enable
    - Add imx_sc_seco_secvio_config
    - Add imx_sc_seco_secvio_dgo_config

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
2020-03-13 17:11:58 +01:00
Franck LENORMAND ccf07c0822 SSI-87: firmware: imx: scu: Support reception of any size message
The implementation was limiting the size of a message which can be
received to 4 but soem response can be bigger. For example the
response of the 'sc_seco_secvio_config' API is 6 words.

This patch removes this limitation relying on the count of word
received instead of the index of the chan.
It does so by duplicating imx_scu_call_rpc as imx_scu_call_big_rpc
in order to cahnge the RX method using imx_scu_big_rx_callback
instead of imx_scu_rx_callback.

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
2020-03-13 17:11:58 +01:00
Jason A. Donenfeld e657b1f6b9 efi: READ_ONCE rng seed size before munmap
commit be36f9e7517e17810ec369626a128d7948942259 upstream.

This function is consistent with using size instead of seed->size
(except for one place that this patch fixes), but it reads seed->size
without using READ_ONCE, which means the compiler might still do
something unwanted. So, this commit simply adds the READ_ONCE
wrapper.

Fixes: 636259880a ("efi: Add support for seeding the RNG from a UEFI ...")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: linux-efi@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20200217123354.21140-1-Jason@zx2c4.com
Link: https://lore.kernel.org/r/20200221084849.26878-5-ardb@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-12 13:00:31 +01:00
Leonard Crestez 30eb1ea78a firmware: imx: Align imx_sc_msg_req_cpu_start to 4
commit f5bfeff44612d304deb100065a9f712309dc2783 upstream.

The imx SC api strongly assumes that messages are composed out of
4-bytes words but some of our message structs have odd sizeofs.

This produces many oopses with CONFIG_KASAN=y.

Fix by marking with __aligned(4).

Fixes: d90bf296ae ("firmware: imx: Add support to start/stop a CPU")
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-12 13:00:28 +01:00
Leonard Crestez a3bede27ca firmware: imx: scu-pd: Align imx sc msg structs to 4
commit 7c1a1c814ccc858633c761951c2546041202b24e upstream.

The imx SC api strongly assumes that messages are composed out of
4-bytes words but some of our message structs have odd sizeofs.

This produces many oopses with CONFIG_KASAN=y.

Fix by marking with __aligned(4).

Fixes: c800cd7824 ("firmware: imx: add SCU power domain driver")
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-12 13:00:28 +01:00
Leonard Crestez 1bebf41fb8 firmware: imx: misc: Align imx sc msg structs to 4
commit 1e6a4eba693ac72e6f91b4252458c933110e5f4c upstream.

The imx SC api strongly assumes that messages are composed out of
4-bytes words but some of our message structs have odd sizeofs.

This produces many oopses with CONFIG_KASAN=y:

    BUG: KASAN: stack-out-of-bounds in imx_mu_send_data+0x108/0x1f0

It shouldn't cause an issues in normal use because these structs are
always allocated on the stack.

Fixes: 15e1f2bc8b ("firmware: imx: add misc svc support")
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-12 13:00:28 +01:00
Leonard Crestez 3227ecd0ef firmware: imx: scu: Ensure sequential TX
commit 26d0fba29c96241de8a9d16f045b1de49875884c upstream.

SCU requires that all messages words are written sequentially but linux MU
driver implements multiple independent channels for each register so ordering
between different channels must be ensured by SCU API interface.

Wait for tx_done before every send to ensure that no queueing happens at the
mailbox channel level.

Fixes: edbee095fa ("firmware: imx: add SCU firmware driver support")
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Cc: <stable@vger.kernel.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by:: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-12 13:00:17 +01:00
Franck LENORMAND da897c095b MLK-23421: fw: imx: seco_mu: Use fast IPC
Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
2020-03-12 09:29:51 +01:00
Jason Liu 335d2828a9 This is the 5.4.24 stable release
-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAl5hHjgACgkQONu9yGCS
 aT6CSBAA0c16mnDb59jgmW/sBj/p/MrlD/WJzLriqiKN5BUsPt9++I5mNj8mG+d2
 Glm4086e8L826zv8oKiZm23xk93on+78ExhVFVZvZNaEUpiRNYCGSuDq2NrHW0z+
 kpagkAFLfCUZFoKtmWo+bpl0YtF4dd/fg7+EjyL6qT1DBs8NVMwZx7i/v0xXv7Wc
 0vsGCLYoBLzcW1FB2d9cfAUPCBuGEzL/7TdifNOXRgI9owGsZndFJgXgIzoBUt/P
 tqB8RLjIupCiMEPtsEAZ/rgEQLPFkb3yrBvgjd1wDI8bHUIQU0clqThKVNvmNSmv
 UTBSNgPAhkP8nZG7X9xCkyfEsUefejBJy66da9n4XTGGrXf9ga0BL0nNrOGwOesr
 m+tNnBSFsbFCMqFopQnt4zZSnaf67AOk2mzxbEu4E+sStyW943aDO9MoRRFgaYGH
 pfie3qOKtKta2MuNTJA+q6F0W9H+V5MtMpwbyuy1/dp2eVln2wewBBMvXYdL1YOy
 E/Z87nsQgalsDynz9m/niv32J4JAxHptyOyROkktDLBSzL5RawNn+Op8X5EtmZOe
 sPkiYicqp9CLmMj13qWXJhtuyNdD4wk6FyyAy6cX9mF44+EZGOBkyNP+n8g789Kn
 sqFJ7sfTfOnwLBFciMA5PaMTGNWROyWXNkvvUzO+9t0CyFAnT2U=
 =abGA
 -----END PGP SIGNATURE-----

Merge tag 'v5.4.24' into imx_5.4.y

Merge Linux stable release v5.4.24 into imx_5.4.y

* tag 'v5.4.24': (3306 commits)
  Linux 5.4.24
  blktrace: Protect q->blk_trace with RCU
  kvm: nVMX: VMWRITE checks unsupported field before read-only field
  ...

Signed-off-by: Jason Liu <jason.hui.liu@nxp.com>

 Conflicts:
	arch/arm/boot/dts/imx6sll-evk.dts
	arch/arm/boot/dts/imx7ulp.dtsi
	arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
	drivers/clk/imx/clk-composite-8m.c
	drivers/gpio/gpio-mxc.c
	drivers/irqchip/Kconfig
	drivers/mmc/host/sdhci-of-esdhc.c
	drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
	drivers/net/can/flexcan.c
	drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
	drivers/net/ethernet/mscc/ocelot.c
	drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
	drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
	drivers/net/phy/realtek.c
	drivers/pci/controller/mobiveil/pcie-mobiveil-host.c
	drivers/perf/fsl_imx8_ddr_perf.c
	drivers/tee/optee/shm_pool.c
	drivers/usb/cdns3/gadget.c
	kernel/sched/cpufreq.c
	net/core/xdp.c
	sound/soc/fsl/fsl_esai.c
	sound/soc/fsl/fsl_sai.c
	sound/soc/sof/core.c
	sound/soc/sof/imx/Kconfig
	sound/soc/sof/loader.c
2020-03-08 18:57:18 +08:00
Bing Song cfec9f5224 MLK-23394-4: pd: Add XUVI for i.MX8QM.
Add XUVI for i.MX8QM.

Signed-off-by: Bing Song <bing.song@nxp.com>
Reviewed-by: Jian Li <jian.li@nxp.com>
Reviewed-by: Zhou Peng <eagle.zhou@nxp.com>
2020-03-05 08:16:44 +08:00
Joakim Zhang 5604fcd429 MLK-23418-5 firmware: imx: scu-pd: add Perf power domain in DB
Add Perf power domain in DB SS.

Reviewed-by: Fugang Duan <fugang.duan@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
2020-03-04 09:06:05 +08:00
Leonard Crestez 42c2753d88 LF-976 firmware: imx: scu: Ensure sequential TX
SCU requires that all messages words are written sequentially but linux MU
driver implements multiple independent channels for each register so ordering
between different channels must be ensured by SCU API interface.

Wait for tx_done before every send to ensure that no queueing happens at the
mailbox channel level.

Reported-by: Franck LENORMAND <franck.lenormand@nxp.com>
Acked-by: Ye Li <ye.li@nxp.com>
[ Based on initial work from Franck LENORMAND <franck.lenormand@nxp.com> ]
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>

(cherry picked from commit f7021eaa04)
2020-02-26 04:17:47 +08:00
Franck LENORMAND 949e4a1475 LF-950 firmware: imx: scu: Fix corruption of header
The header of the message to send can be changed if the
response is longer than the request:
 - 1st word, the header is sent
 - the remaining words of the message are sent
 - the response is received asynchronously during the
   execution of the loop, changing the size field in
   the header
 - the for loop test the termination condition using
   the corrupted header

It is the case for the API build_info which has just a
header as request but 3 words in response.

This issue is fixed storing the header locally instead of
using a pointer on it.

Fixes: edbee095fa (firmware: imx: add SCU firmware driver support)

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
(cherry picked from commit fb0ad9322e)
2020-02-26 04:17:47 +08:00
Leonard Crestez e57cffefac LF-903 firmware: imx: Align imx SC msg structs to 4
The imx SC api strongly assumes that messages are composed out of
4-bytes words but some of our message structs have sizeof "6" and "7".

This produces many oopses with CONFIG_KASAN=y:

	BUG: KASAN: stack-out-of-bounds in imx_mu_send_data+0x108/0x1f0

It shouldn't cause an issues in normal use because these structs are
always allocated on the stack.

Also upstream: https://patchwork.kernel.org/patch/11376909/

Reported-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Reviewed-by: Jason Liu <jason.hui.liu@nxp.com>
Reviewed-by: Aisheng Dong <aisheng.dong@nxp.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
(cherry picked from commit 8ca6d9eb27)
2020-02-26 04:17:47 +08:00
Frank Li 87cbc83370 MLK-23346-1: DXL Add second USB PHY power domain
Add second USB PHY power domain

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
2020-02-21 13:58:06 -06:00
Daniel Baluta 9194cb7c75 firmware: imx: Remove call to devm_of_platform_populate
IMX DSP device is created by SOF layer. The current call to
devm_of_platform_populate is not needed and it doesn't produce
any effects.

Fixes: ffbf23d503 ("firmware: imx: Add DSP IPC protocol interface)
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
2020-02-21 17:22:09 +02:00
Silvano di Ninno c334337d16 LF-824: fw: imx: seco_mu: Add driver for SECO
This patch adds the driver to interact with the different
APIs exposed by the SECO using a shared Messaging Unit.

The driver exposes some char devices in user space allowing
a user to send message to the SECO and read its response.

The driver uses the mailbox framework instead of directly
configuring the MU.

Signed-off-by: Stephane Dion <stephane.dion_1@nxp.com>
Signed-off-by: Silvano di Ninno <silvano.dininno@nxp.com>
Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>

(cherry picked from commit 4985109d60164c842ee5d189621455db349b5212)
(cherry picked from commit eb721810fdc309b6a32a7a64c7686eaa6052cdc7)
(cherry picked from commit 4956bbf43349ab40a6a60765752a904d11bfcd18)
2020-02-21 14:44:02 +01:00
Franck LENORMAND 7d01320dfc LF-824: fw: imx: Add power domain for MU of the SECO
Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
2020-02-21 14:44:02 +01:00
Franck LENORMAND 9edf1255f8 LF-824: fw: imx: scu: Add SECO API
Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
2020-02-21 14:44:02 +01:00
Franck LENORMAND 10237c7bcb LF-824: fw: imx: scu: Add missing APIs
APIs added:
 - IMX_SC_RM_FUNC_FIND_MEMREG
 - IMX_SC_RM_FUNC_GET_RESOURCE_OWNER
 - IMX_SC_RM_FUNC_SET_MEMREG_PERMISSIONS
 - IMX_SC_RM_FUNC_GET_DID

Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
2020-02-21 14:44:02 +01:00
Abel Vesa 228395b5e5 LF-794 firmware: imx: scu-pd: Remove the HDMI TX always on workaround
Now that the firmware reloading is implemented, we can let the HDMI
power off.

Signed-off-by: Abel Vesa <abel.vesa@nxp.com>
Reviewed-by: Sandor Yu <sandor.yu@nxp.com>
2020-02-13 13:42:54 +02:00
Sudeep Holla 8b8b5f9a7b firmware: arm_scmi: Fix doorbell ring logic for !CONFIG_64BIT
[ Upstream commit 7bd39bc6bfdf96f5df0f92199bbc1a3ee2f2adb8 ]

The logic to ring the scmi performance fastchannel ignores the
value read from the doorbell register in case of !CONFIG_64BIT.
This bug also shows up as warning with '-Wunused-but-set-variable' gcc
flag:

drivers/firmware/arm_scmi/perf.c: In function scmi_perf_fc_ring_db:
drivers/firmware/arm_scmi/perf.c:323:7: warning: variable val set but
			not used [-Wunused-but-set-variable]

Fix the same by aligning the logic with CONFIG_64BIT as used in the
macro SCMI_PERF_FC_RING_DB().

Fixes: 823839571d ("firmware: arm_scmi: Make use SCMI v2.0 fastchannel for performance protocol")
Reported-by: Hulk Robot <hulkci@huawei.com>
Reported-by: Zheng Yongjun <zhengyongjun3@huawei.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-26 10:01:07 +01:00
Daniel Baluta bd9d813ca8 firmware: imx: Remove call to devm_of_platform_populate
[ Upstream commit 0e4e8cc30a2940c57448af1376e40d3c0996fb29 ]

IMX DSP device is created by SOF layer. The current call to
devm_of_platform_populate is not needed and it doesn't produce
any effects.

Fixes: ffbf23d503 ("firmware: imx: Add DSP IPC protocol interface)
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-26 10:01:05 +01:00
Arvind Sankar 2c490a4730 efi/earlycon: Fix write-combine mapping on x86
commit d92b54570d24d017d2630e314b525ed792f5aa6c upstream.

On x86, until PAT is initialized, WC translates into UC-. Since we
calculate and store pgprot_writecombine(PAGE_KERNEL) when earlycon is
initialized, this means we actually use UC- mappings instead of WC
mappings, which makes scrolling very slow.

Instead store a boolean flag to indicate whether we want to use
writeback or write-combine mappings, and recalculate the actual pgprot_t
we need on every mapping. Once PAT is initialized, we will start using
write-combine mappings, which speeds up the scrolling considerably.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Fixes: 69c1f396f2 ("efi/x86: Convert x86 EFI earlyprintk into generic earlycon implementation")
Link: https://lkml.kernel.org/r/20191224132909.102540-2-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-01-23 08:22:38 +01:00
Andy Shevchenko 6ddac305e0 efi/earlycon: Remap entire framebuffer after page initialization
[ Upstream commit b418d660bb9798d2249ac6a46c844389ef50b6a5 ]

When commit:

  69c1f396f2 ("efi/x86: Convert x86 EFI earlyprintk into generic earlycon implementation")

moved the x86 specific EFI earlyprintk implementation to a shared location,
it also tweaked the behaviour. In particular, it dropped a trick with full
framebuffer remapping after page initialization, leading to two regressions:

  1) very slow scrolling after page initialization,
  2) kernel hang when the 'keep_bootcon' command line argument is passed.

Putting the tweak back fixes #2 and mitigates #1, i.e., it limits the slow
behavior to the early boot stages, presumably due to eliminating heavy
map()/unmap() operations per each pixel line on the screen.

 [ ardb: ensure efifb is unmapped again unless keep_bootcon is in effect. ]
 [ mingo: speling fixes. ]

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Bhupesh Sharma <bhsharma@redhat.com>
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Cc: linux-efi@vger.kernel.org
Fixes: 69c1f396f2 ("efi/x86: Convert x86 EFI earlyprintk into generic earlycon implementation")
Link: https://lkml.kernel.org/r/20191206165542.31469-7-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-12 12:21:16 +01:00
Arvind Sankar a431b8d768 efi/gop: Fix memory leak in __gop_query32/64()
[ Upstream commit ff397be685e410a59c34b21ce0c55d4daa466bb7 ]

efi_graphics_output_protocol::query_mode() returns info in
callee-allocated memory which must be freed by the caller, which
we aren't doing.

We don't actually need to call query_mode() in order to obtain the
info for the current graphics mode, which is already there in
gop->mode->info, so just access it directly in the setup_gop32/64()
functions.

Also nothing uses the size of the info structure, so don't update the
passed-in size (which is the size of the gop_handle table in bytes)
unnecessarily.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Bhupesh Sharma <bhsharma@redhat.com>
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191206165542.31469-5-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-12 12:21:16 +01:00
Arvind Sankar 60bb249c73 efi/gop: Return EFI_SUCCESS if a usable GOP was found
[ Upstream commit dbd89c303b4420f6cdb689fd398349fc83b059dd ]

If we've found a usable instance of the Graphics Output Protocol
(GOP) with a framebuffer, it is possible that one of the later EFI
calls fails while checking if any support console output. In this
case status may be an EFI error code even though we found a usable
GOP.

Fix this by explicitly return EFI_SUCCESS if a usable GOP has been
located.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Bhupesh Sharma <bhsharma@redhat.com>
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191206165542.31469-4-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-12 12:21:16 +01:00
Arvind Sankar 8c73e052ae efi/gop: Return EFI_NOT_FOUND if there are no usable GOPs
[ Upstream commit 6fc3cec30dfeee7d3c5db8154016aff9d65503c5 ]

If we don't find a usable instance of the Graphics Output Protocol
(GOP) because none of them have a framebuffer (i.e. they were all
PIXEL_BLT_ONLY), but all the EFI calls succeeded, we will return
EFI_SUCCESS even though we didn't find a usable GOP.

Fix this by explicitly returning EFI_NOT_FOUND if no usable GOPs are
found, allowing the caller to probe for UGA instead.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Bhupesh Sharma <bhsharma@redhat.com>
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191206165542.31469-3-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-12 12:21:15 +01:00
Ard Biesheuvel 618ab2e3c1 efi: Don't attempt to map RCI2 config table if it doesn't exist
[ Upstream commit a470552ee8965da0fe6fd4df0aa39c4cda652c7c ]

Commit:

  1c5fecb612 ("efi: Export Runtime Configuration Interface table to sysfs")

... added support for a Dell specific UEFI configuration table, but
failed to take into account that mapping the table should not be
attempted unless the table actually exists. If it doesn't exist,
the code usually fails silently unless pr_debug() prints are
enabled. However, on 32-bit PAE x86, the splat below is produced due
to the attempt to map the placeholder value EFI_INVALID_TABLE_ADDR
which we use for non-existing UEFI configuration tables, and which
equals ULONG_MAX.

   memremap attempted on mixed range 0x00000000ffffffff size: 0x1e
   WARNING: CPU: 1 PID: 1 at kernel/iomem.c:81 memremap+0x1a3/0x1c0
   Modules linked in:
   CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.4.2-smp-mine #1
   Hardware name: Hewlett-Packard HP Z400 Workstation/0B4Ch, BIOS 786G3 v03.61 03/05/2018
   EIP: memremap+0x1a3/0x1c0
  ...
   Call Trace:
    ? map_properties+0x473/0x473
    ? efi_rci2_sysfs_init+0x2c/0x154
    ? map_properties+0x473/0x473
    ? do_one_initcall+0x49/0x1d4
    ? parse_args+0x1e8/0x2a0
    ? do_early_param+0x7a/0x7a
    ? kernel_init_freeable+0x139/0x1c2
    ? rest_init+0x8e/0x8e
    ? kernel_init+0xd/0xf2
    ? ret_from_fork+0x2e/0x38

Fix this by checking whether the table exists before attempting to map it.

Reported-by: Richard Narron <comet.berkeley@gmail.com>
Tested-by: Richard Narron <comet.berkeley@gmail.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-efi@vger.kernel.org
Fixes: 1c5fecb612 ("efi: Export Runtime Configuration Interface table to sysfs")
Link: https://lkml.kernel.org/r/20191210090945.11501-2-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-09 10:20:07 +01:00
Wen Yang 7da501c21a firmware: arm_scmi: Avoid double free in error flow
commit 8305e90a894f82c278c17e51a28459deee78b263 upstream.

If device_register() fails, both put_device() and kfree() are called,
ending with a double free of the scmi_dev.

Calling kfree() is needed only when a failure happens between the
allocation of the scmi_dev and its registration, so move it to there
and remove it from the error flow.

Fixes: 46edb8d132 ("firmware: arm_scmi: provide the mandatory device release callback")
Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-01-09 10:20:03 +01:00
Ard Biesheuvel 5049468ba1 efi/memreserve: Register reservations as 'reserved' in /proc/iomem
commit ab0eb16205b43ece4c78e2259e681ff3d645ea66 upstream.

Memory regions that are reserved using efi_mem_reserve_persistent()
are recorded in a special EFI config table which survives kexec,
allowing the incoming kernel to honour them as well. However,
such reservations are not visible in /proc/iomem, and so the kexec
tools that load the incoming kernel and its initrd into memory may
overwrite these reserved regions before the incoming kernel has a
chance to reserve them from further use.

Address this problem by adding these reservations to /proc/iomem as
they are created. Note that reservations that are inherited from a
previous kernel are memblock_reserve()'d early on, so they are already
visible in /proc/iomem.

Tested-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Tested-by: Bhupesh Sharma <bhsharma@redhat.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Bhupesh Sharma <bhsharma@redhat.com>
Cc: <stable@vger.kernel.org> # v5.4+
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191206165542.31469-2-ardb@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-12-31 16:46:06 +01:00
Will Deacon 2f04249b33 firmware: qcom: scm: Ensure 'a0' status code is treated as signed
commit ff34f3cce278a0982a7b66b1afaed6295141b1fc upstream.

The 'a0' member of 'struct arm_smccc_res' is declared as 'unsigned long',
however the Qualcomm SCM firmware interface driver expects to receive
negative error codes via this field, so ensure that it's cast to 'long'
before comparing to see if it is less than 0.

Cc: <stable@vger.kernel.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-12-17 19:56:50 +01:00
Dong Aisheng 08dcfadc9a Merge branch 'pm/next' into next
* pm/next: (54 commits)
  drivers/soc/fsl: add EPU FSM configuration for deep sleep
  fsl_pmc: update device bindings
  soc: fsl: add RCPM driver
  Documentation: dt: binding: fsl: Add 'little-endian' and update Chassis define
  MLK-22992 firmware: imx: scu-pd: fix wu_num
  ...
2019-12-02 18:05:21 +08:00
Daniel Baluta 98885524c4 firmware: imx: Allow imx dsp to be selected as module
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
2019-11-28 23:33:17 +02:00
Peng Fan b32c7c3b6a LF-202-4 firmware: imx: scu-pd: ignore power domain not owned
Should not register power domain that not owned by current
partition.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
2019-11-28 10:25:13 +08:00
Peng Fan 5a5785a7c4 LF-202-2 firmware: imx: add resource management api
Add resource management API, when we have multiple
partition running together, resources not owned to current
partition should not be used.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
2019-11-28 10:17:47 +08:00
Peng Fan 240ff35098 LF-202-1 firmware: imx: scu: use hvc for dom0
We use hvc to let xen handle the scfw api call for dom0.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
2019-11-28 10:17:36 +08:00
Peng Fan c6ec2917a6 MLK-22992 firmware: imx: scu-pd: fix wu_num
wu_num needs to be int type, u32 is not correct.

When "wakeup-irq" not included, of_property_count_u32_elems
will return a negative value. So use int.

And directly return when "wakeup-irq" not exists.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
2019-11-25 16:29:51 +08:00
Robin Gong 6b9ef3ceeb firmware: imx: scu-pd: correct edma0 channel number
32 channels are used for edma0 on i.mx8qxp/8qm. Correct it.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
2019-11-25 16:29:50 +08:00
Shijie Qin a1f3b5741c imx: scu-pd: add vpu-enc1 power domains for imx8qm
Add power domains for 'IMX_SC_R_VPU_ENC_1'

Signed-off-by: Shijie Qin <shijie.qin@nxp.com>
2019-11-25 16:29:50 +08:00
Joakim Zhang 7c03849625 firmware: imx: pd: add board level power domain
Add power domain for board level on imx8qm mek.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
2019-11-25 16:29:49 +08:00
Joakim Zhang 29aec5cb8b firmware: imx: pd: add power domain for emvsim
Add power domain for emvsim on imx8qm mek.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
2019-11-25 16:29:49 +08:00
Mirela Rabulea aaaf06b9e9 imx: scu-pd: Add power domains for mxc-jpeg
Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
2019-11-25 16:29:46 +08:00
Horia Geantă 261386810a MLKU-62 imx: scu-pd: add power domain for caam job rings
On i.MX8 QM and QXP, caam crypto accelerator has 4 job rings,
however only the last two (JR2 and JR3) are accesible from the kernel.

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
2019-11-25 16:29:46 +08:00
Minjie Zhuang ea8c1df2ee imx: scu-pd: add power domains for gpu1-pid
add power domains for gpu1-pid

Signed-off-by: Minjie Zhuang <minjie.zhuang@nxp.com>
2019-11-25 16:29:45 +08:00
Zhou Peng 387da9b7c4 imx: scu-pd: add vpu mu2 power domains for imx8qm
Add power domain for 'IMX_SC_R_VPU_MU_2'

Signed-off-by: Zhou Peng <eagle.zhou@nxp.com>
2019-11-25 16:29:44 +08:00
Shengjiu Wang c18ddfb8a0 imx: scu-pd: add audio power domains for imx8qm
add audio power domains

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
2019-11-25 16:29:43 +08:00
r01008 a1a5236525 firmware: imx: scu-pd: add the hdmi tx power domains
Add the HDMI TX power domains.

Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
2019-11-25 16:29:43 +08:00
Richard Zhu 7a072a816e firmware: imx: scu-pd: add the hsio pds
Add the HSIO PDs, mandatory required by PCIe/SATA.

Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
2019-11-25 16:29:41 +08:00
Dong Aisheng 2ec28b6d49 firmware: imx: scu-pd: change init level to subsys_initcall
Change power domain init level to subsys_initcall to ensure it's probed
before most devices to avoid unneccesary defer probe.

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 16:29:40 +08:00
Dong Aisheng 94db85b0ea firmware: imx: scu-pd: add dc1 power domains
Add dc1 power domains

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 16:29:39 +08:00
Dong Aisheng 5090ffced3 firmware: imx: scu-pd: add lvds power domains
Add lvds power domains

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 16:29:38 +08:00
Anson Huang c380248180 firmware: imx: scu-pd: Add IRQSTEER wakeup support
To support different wakeup source, Linux kernel needs to call
SCU firmware to assign different wakeup controllers, for those
SCU resources like RTC alarm, ON/OFF button, MU etc., it should
use SCU wakeup controller, for other peripheral resources like
LPUART, CAN, etc., it should use IRQSTERR wakeup controller.

To support this feasure, all devices supporting wakeup should
add its hwirq number to pd node's wakeup-irq property. Below
is the example of adding LPUART0~3 as wakeup source, SCU PD
driver will determine whether IRQSTEER or SCU should be selected
as wakeup controller, this is done by reading GIC distributor's
register and wakeup-irq array to check whether a wakeup source
is enabled in GIC in order to support wakeup.

pd: imx8qx-pd {
        compatible = "fsl,imx8qm-scu-pd", "fsl,scu-pd";
        #power-domain-cells = <1>;
        wakeup-irq = <345 346 347 348>;
};

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
2019-11-25 16:29:38 +08:00
Joakim Zhang 1da4c73628 firmware: scu-pd: add pd for CM41 SS
Add pd for CM41 SS on imx8QM.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
2019-11-25 16:29:38 +08:00
Dong Aisheng e80c8c6bf4 firmware: imx: scu-pd: add multi states support
add multi states support

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 16:29:37 +08:00
Dong Aisheng c2e74728f9 firmware: imx: scu-pd: do not power off console if no_console_suspend
Do not power off console if no_console_suspend

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 16:29:35 +08:00
Dong Aisheng 819cd1e261 firmware: imx: scu-pd: do not power off console domain
Do not power off console domain in runtime pm.

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 16:29:35 +08:00
Dong Aisheng dced470837 firmware: imx: scu-pd: add dc video pd
add dc video pd

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 16:29:34 +08:00
Dong Aisheng 0828343304 firmware: imx: scu-pd: add mipi lvds1 power domains
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 16:29:31 +08:00
Shengjiu Wang 58a92295d5 imx: scu-pd: add audio power domains
add audio power domains

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
2019-11-25 16:29:31 +08:00
Andy Duan 767da37e89 firmware: imx: scu-pd: add power domain for edma2
Add power domain for edma2.

Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
2019-11-25 16:29:31 +08:00
Guoniu.zhou 9fdcde38bd firmware: imx: scu-pd: add SCU power domain for image subsystem
Add SCU power domains for image subsystem. The subsystem include
ISI, CSI, PARALLEL, I2C, PWM and DPLL modules

Signed-off-by: Guoniu.zhou <guoniu.zhou@nxp.com>
2019-11-25 16:29:30 +08:00
Joakim Zhang 5767ff0586 firmware: imx: scu-pd: add power domian for i2c and intmux in cm40
Add power domian for i2c and intmux which are in cm40 subsystem.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
2019-11-25 16:29:30 +08:00
Zhou Peng 81713457b9 firmware: imx: scu-pd: add VPU MU powe domains
Signed-off-by: Zhou Peng <eagle.zhou@nxp.com>
2019-11-25 16:29:29 +08:00
Robin Gong 936c74516d MLK-22984 firmware: imx: imx-scu-irq: fix RCU complains after M4 partition reset
Use blocking_notifier_chain instead of atomic_notifier_chain, otherwise
below RCU complains would come out since unregister/register_virtio_device
()will issue mbox message (mbox_send_message() is blocking) again after
received M4 partition reset. Actually, no need atomic for notifier which
is so tough for user since this notifier is called in worker instead of
interrupt handler directly.

[  389.706645] i2c-rpmsg virtio0.rpmsg-i2c-channel.-1.2: i2c rpmsg driver is removed
[  389.767362] Wait for remote ready timeout, use first_notify.
[  389.774084] ------------[ cut here ]------------
[  389.778729] WARNING: CPU: 0 PID: 397 at kernel/rcu/tree_plugin.h:293 rcu_note_context_switch+0x34/0x338
[  389.788131] Modules linked in:
[  389.791195] CPU: 0 PID: 397 Comm: kworker/0:13 Not tainted 5.4.0-rc5-02977-g08f78722f07b #26
[  389.799633] Hardware name: Freescale i.MX8DXL Phantom MEK (DT)
[  389.805481] Workqueue: events imx_scu_irq_work_handler
[  389.810626] pstate: 20000085 (nzCv daIf -PAN -UAO)
[  389.815422] pc : rcu_note_context_switch+0x34/0x338
[  389.820307] lr : __schedule+0x98/0x548
[  389.824054] sp : ffff800013e7b770
[  389.827362] x29: ffff800013e7b770 x28: 0000000000000000
[  389.832679] x27: 0000000000000000 x26: 0000000000000100
[  389.837997] x25: ffff0000299f6e00 x24: ffff80001112fdc8
[  389.843312] x23: ffff800011f298c8 x22: ffff800011af4018
[  389.848628] x21: 0000000000000000 x20: ffff0000299f6e00
[  389.853945] x19: ffff00002afdd840 x18: ffff80001188ca18
[  389.859262] x17: 0000000000000000 x16: 0000000000000000
[  389.864579] x15: 0000000090008000 x14: ffff800012473000
[  389.869896] x13: ffff800012470000 x12: 0000000000000100
[  389.875212] x11: ffff0000297b9980 x10: 0000000000000001
[  389.880529] x9 : 0000000000000228 x8 : 0000000000000220
[  389.885846] x7 : 0000000000000035 x6 : ffff00002afd6418
[  389.891162] x5 : 0000000000002000 x4 : 0000000000002000
[  389.896479] x3 : 0000000000000000 x2 : ffff8000194dc000
[  389.901798] x1 : 0000000000000001 x0 : 0000000000000001
[  389.907115] Call trace:
[  389.909561]  rcu_note_context_switch+0x34/0x338
[  389.914094]  __schedule+0x98/0x548
[  389.917499]  schedule+0x40/0xe0
[  389.920643]  schedule_timeout+0x144/0x268
[  389.924659]  wait_for_completion_timeout+0x94/0x128
[  389.929543]  mbox_send_message+0x9c/0x120
[  389.933554]  imx_rpmsg_notify+0x5c/0x68
[  389.937397]  virtqueue_notify+0x20/0x50
[  389.941233]  rpmsg_probe+0x274/0x318
[  389.944811]  virtio_dev_probe+0x16c/0x228
[  389.948830]  really_probe+0xd4/0x308
[  389.952404]  driver_probe_device+0x54/0xe8
[  389.956507]  __device_attach_driver+0x80/0xb8
[  389.960868]  bus_for_each_drv+0x78/0xc8
[  389.964705]  __device_attach+0xd4/0x130
[  389.968549]  device_initial_probe+0x10/0x18
[  389.972735]  bus_probe_device+0x90/0x98
[  389.976574]  device_add+0x3f0/0x638
[  389.980067]  register_virtio_device+0xb0/0x108
[  389.984514]  imx_rpmsg_restore+0x120/0x170
[  389.988615]  imx_rpmsg_partition_notify+0x3c/0x60
[  389.993325]  notifier_call_chain+0x54/0x90
[  389.997424]  atomic_notifier_call_chain+0x38/0x58
[  390.002133]  imx_scu_irq_work_handler+0x80/0xd8
[  390.006669]  process_one_work+0x1e0/0x358
[  390.010681]  worker_thread+0x40/0x488
[  390.014349]  kthread+0x118/0x120
[  390.017580]  ret_from_fork+0x10/0x18
[  390.021157] ---[ end trace 7205c5eaadacce06 ]---
[  390.025926] virtio_rpmsg_bus virtio0: rpmsg host is online

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 15:46:50 +08:00
Sandor Yu 7472da7424 firmware: imx: keep HDMI power domains always on
firmware running in hdmi subsystem,
the power domains of hdmi should be always on.

Signed-off-by: Sandor Yu <Sandor.yu@nxp.com>
2019-11-25 15:46:50 +08:00
Anson Huang faa4898632 firmware: imx: make sure MU irq can wake up system from suspend mode
IRQF_NO_SUSPEND flag is set for MU IRQ of IPC work, but with this
flag set, IRQD_WAKEUP_ARMED flag will NOT be set during
suspend_device_irq() phase, then when MU IRQ arrives, it will NOT
wake up system from suspend.

To fix this issue, pm_system_wakeup() is called in general MU IRQ
handler to make sure system can be waked up when MU IRQ arrives.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
2019-11-25 15:46:49 +08:00
Dong Aisheng 255d962ee5 firmware: imx: scu: change init level to subsys_initcall_sync
Change firmware init level to subsys_initcall_sync to ensure it's
probed before most devices to avoid unneccesary defer probe.

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 15:46:49 +08:00
Dong Aisheng 60175674c8 firmware: imx: scu: intialization rx_size before sending cmd
intialization rx_size before sending cmd

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 15:46:49 +08:00
Dong Aisheng 7d1c3295eb firmware: imx: remove unused types.h
types.h has been moved into rsrc.h

Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
2019-11-25 15:46:49 +08:00