arch/powerpc/platforms/powernv/opal-call.c

Source file repositories/reference/linux-study-clean/arch/powerpc/platforms/powernv/opal-call.c

File Facts

System
Linux kernel
Corpus path
arch/powerpc/platforms/powernv/opal-call.c
Extension
.c
Size
12026 bytes
Lines
296
Domain
Architecture Layer
Bucket
arch/powerpc
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
#include <linux/percpu.h>
#include <linux/jump_label.h>
#include <asm/interrupt.h>
#include <asm/opal-api.h>
#include <asm/trace.h>
#include <asm/asm-prototypes.h>

#ifdef CONFIG_TRACEPOINTS
/*
 * Since the tracing code might execute OPAL calls we need to guard against
 * recursion.
 */
static DEFINE_PER_CPU(unsigned int, opal_trace_depth);

static void __trace_opal_entry(s64 a0, s64 a1, s64 a2, s64 a3,
			       s64 a4, s64 a5, s64 a6, s64 a7,
			       unsigned long opcode)
{
	unsigned int *depth;
	unsigned long args[8];

	depth = this_cpu_ptr(&opal_trace_depth);

	if (*depth)
		return;

	args[0] = a0;
	args[1] = a1;
	args[2] = a2;
	args[3] = a3;
	args[4] = a4;
	args[5] = a5;
	args[6] = a6;
	args[7] = a7;

	(*depth)++;
	trace_opal_entry(opcode, &args[0]);
	(*depth)--;
}

static void __trace_opal_exit(unsigned long opcode, unsigned long retval)
{
	unsigned int *depth;

	depth = this_cpu_ptr(&opal_trace_depth);

	if (*depth)
		return;

	(*depth)++;
	trace_opal_exit(opcode, retval);
	(*depth)--;
}

static DEFINE_STATIC_KEY_FALSE(opal_tracepoint_key);

int opal_tracepoint_regfunc(void)
{
	static_branch_inc(&opal_tracepoint_key);
	return 0;
}

void opal_tracepoint_unregfunc(void)
{
	static_branch_dec(&opal_tracepoint_key);
}

static s64 __opal_call_trace(s64 a0, s64 a1, s64 a2, s64 a3,
			     s64 a4, s64 a5, s64 a6, s64 a7,
			      unsigned long opcode, unsigned long msr)
{
	s64 ret;

	__trace_opal_entry(a0, a1, a2, a3, a4, a5, a6, a7, opcode);
	ret = __opal_call(a0, a1, a2, a3, a4, a5, a6, a7, opcode, msr);
	__trace_opal_exit(opcode, ret);

	return ret;
}

#define DO_TRACE (static_branch_unlikely(&opal_tracepoint_key))

#else /* CONFIG_TRACEPOINTS */

static s64 __opal_call_trace(s64 a0, s64 a1, s64 a2, s64 a3,
			     s64 a4, s64 a5, s64 a6, s64 a7,
			      unsigned long opcode, unsigned long msr)
{
	return 0;

Annotation

Implementation Notes