Skip to content

Commit

Permalink
powerpc/rtas: improve function information lookups
Browse files Browse the repository at this point in the history
The core RTAS support code and its clients perform two types of lookup
for RTAS firmware function information.

First, mapping a known function name to a token. The typical use case
invokes rtas_token() to retrieve the token value to pass to
rtas_call(). rtas_token() relies on of_get_property(), which performs
a linear search of the /rtas node's property list under a lock with
IRQs disabled.

Second, and less common: given a token value, looking up some
information about the function. The primary example is the sys_rtas
filter path, which linearly scans a small table to match the token to
a rtas_filter struct. Another use case to come is RTAS entry/exit
tracepoints, which will require efficient lookup of function names
from token values. Currently there is no general API for this.

We need something much like the existing rtas_filters table, but more
general and organized to facilitate efficient lookups.

Introduce:

* A new rtas_function type, aggregating function name, token,
  and filter. Other function characteristics could be added in the
  future.

* An array of rtas_function, where each element corresponds to a known
  RTAS function. All information in the table is static save the token
  values, which are derived from the device tree at boot. The array is
  sorted by function name to allow binary search.

* A named constant for each known RTAS function, used to index the
  function array. These also will be used in a client-facing API to be
  added later.

* An xarray that maps valid tokens to rtas_function objects.

Fold the existing rtas_filter table into the new rtas_function array,
with the appropriate adjustments to block_rtas_call(). Remove
now-redundant fields from struct rtas_filter. Preserve the function of
the CONFIG_CPU_BIG_ENDIAN guard in the current filter table by
introducing a per-function flag that is set for the function entries
related to pseries LPAR migration. These have never had working users
via sys_rtas on ppc64le; see commit de0f734 ("powerpc/rtas:
prevent suspend-related sys_rtas use on LE").

Convert rtas_token() to use a lockless binary search on the function
table. Fall back to the old behavior for lookups against names that
are not known to be RTAS functions, but issue a warning. rtas_token()
is for function names; it is not a general facility for accessing
arbitrary properties of the /rtas node. All known misuses of
rtas_token() have been converted to more appropriate of_ APIs in
preceding changes.

Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230125-b4-powerpc-rtas-queue-v3-8-26929c8cce78@linux.ibm.com
  • Loading branch information
nathanlynch authored and mpe committed Feb 13, 2023
1 parent d6f7fe3 commit 8252b88
Show file tree
Hide file tree
Showing 2 changed files with 700 additions and 106 deletions.
85 changes: 85 additions & 0 deletions arch/powerpc/include/asm/rtas.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,91 @@
* Copyright (C) 2001 PPC 64 Team, IBM Corp
*/

enum rtas_function_index {
RTAS_FNIDX__CHECK_EXCEPTION,
RTAS_FNIDX__DISPLAY_CHARACTER,
RTAS_FNIDX__EVENT_SCAN,
RTAS_FNIDX__FREEZE_TIME_BASE,
RTAS_FNIDX__GET_POWER_LEVEL,
RTAS_FNIDX__GET_SENSOR_STATE,
RTAS_FNIDX__GET_TERM_CHAR,
RTAS_FNIDX__GET_TIME_OF_DAY,
RTAS_FNIDX__IBM_ACTIVATE_FIRMWARE,
RTAS_FNIDX__IBM_CBE_START_PTCAL,
RTAS_FNIDX__IBM_CBE_STOP_PTCAL,
RTAS_FNIDX__IBM_CHANGE_MSI,
RTAS_FNIDX__IBM_CLOSE_ERRINJCT,
RTAS_FNIDX__IBM_CONFIGURE_BRIDGE,
RTAS_FNIDX__IBM_CONFIGURE_CONNECTOR,
RTAS_FNIDX__IBM_CONFIGURE_KERNEL_DUMP,
RTAS_FNIDX__IBM_CONFIGURE_PE,
RTAS_FNIDX__IBM_CREATE_PE_DMA_WINDOW,
RTAS_FNIDX__IBM_DISPLAY_MESSAGE,
RTAS_FNIDX__IBM_ERRINJCT,
RTAS_FNIDX__IBM_EXTI2C,
RTAS_FNIDX__IBM_GET_CONFIG_ADDR_INFO,
RTAS_FNIDX__IBM_GET_CONFIG_ADDR_INFO2,
RTAS_FNIDX__IBM_GET_DYNAMIC_SENSOR_STATE,
RTAS_FNIDX__IBM_GET_INDICES,
RTAS_FNIDX__IBM_GET_RIO_TOPOLOGY,
RTAS_FNIDX__IBM_GET_SYSTEM_PARAMETER,
RTAS_FNIDX__IBM_GET_VPD,
RTAS_FNIDX__IBM_GET_XIVE,
RTAS_FNIDX__IBM_INT_OFF,
RTAS_FNIDX__IBM_INT_ON,
RTAS_FNIDX__IBM_IO_QUIESCE_ACK,
RTAS_FNIDX__IBM_LPAR_PERFTOOLS,
RTAS_FNIDX__IBM_MANAGE_FLASH_IMAGE,
RTAS_FNIDX__IBM_MANAGE_STORAGE_PRESERVATION,
RTAS_FNIDX__IBM_NMI_INTERLOCK,
RTAS_FNIDX__IBM_NMI_REGISTER,
RTAS_FNIDX__IBM_OPEN_ERRINJCT,
RTAS_FNIDX__IBM_OPEN_SRIOV_ALLOW_UNFREEZE,
RTAS_FNIDX__IBM_OPEN_SRIOV_MAP_PE_NUMBER,
RTAS_FNIDX__IBM_OS_TERM,
RTAS_FNIDX__IBM_PARTNER_CONTROL,
RTAS_FNIDX__IBM_PHYSICAL_ATTESTATION,
RTAS_FNIDX__IBM_PLATFORM_DUMP,
RTAS_FNIDX__IBM_POWER_OFF_UPS,
RTAS_FNIDX__IBM_QUERY_INTERRUPT_SOURCE_NUMBER,
RTAS_FNIDX__IBM_QUERY_PE_DMA_WINDOW,
RTAS_FNIDX__IBM_READ_PCI_CONFIG,
RTAS_FNIDX__IBM_READ_SLOT_RESET_STATE,
RTAS_FNIDX__IBM_READ_SLOT_RESET_STATE2,
RTAS_FNIDX__IBM_REMOVE_PE_DMA_WINDOW,
RTAS_FNIDX__IBM_RESET_PE_DMA_WINDOWS,
RTAS_FNIDX__IBM_SCAN_LOG_DUMP,
RTAS_FNIDX__IBM_SET_DYNAMIC_INDICATOR,
RTAS_FNIDX__IBM_SET_EEH_OPTION,
RTAS_FNIDX__IBM_SET_SLOT_RESET,
RTAS_FNIDX__IBM_SET_SYSTEM_PARAMETER,
RTAS_FNIDX__IBM_SET_XIVE,
RTAS_FNIDX__IBM_SLOT_ERROR_DETAIL,
RTAS_FNIDX__IBM_SUSPEND_ME,
RTAS_FNIDX__IBM_TUNE_DMA_PARMS,
RTAS_FNIDX__IBM_UPDATE_FLASH_64_AND_REBOOT,
RTAS_FNIDX__IBM_UPDATE_NODES,
RTAS_FNIDX__IBM_UPDATE_PROPERTIES,
RTAS_FNIDX__IBM_VALIDATE_FLASH_IMAGE,
RTAS_FNIDX__IBM_WRITE_PCI_CONFIG,
RTAS_FNIDX__NVRAM_FETCH,
RTAS_FNIDX__NVRAM_STORE,
RTAS_FNIDX__POWER_OFF,
RTAS_FNIDX__PUT_TERM_CHAR,
RTAS_FNIDX__QUERY_CPU_STOPPED_STATE,
RTAS_FNIDX__READ_PCI_CONFIG,
RTAS_FNIDX__RTAS_LAST_ERROR,
RTAS_FNIDX__SET_INDICATOR,
RTAS_FNIDX__SET_POWER_LEVEL,
RTAS_FNIDX__SET_TIME_FOR_POWER_ON,
RTAS_FNIDX__SET_TIME_OF_DAY,
RTAS_FNIDX__START_CPU,
RTAS_FNIDX__STOP_SELF,
RTAS_FNIDX__SYSTEM_REBOOT,
RTAS_FNIDX__THAW_TIME_BASE,
RTAS_FNIDX__WRITE_PCI_CONFIG,
};

#define RTAS_UNKNOWN_SERVICE (-1)
#define RTAS_INSTANTIATE_MAX (1ULL<<30) /* Don't instantiate rtas at/above this value */

Expand Down
Loading

0 comments on commit 8252b88

Please sign in to comment.