blob: 41b1575f4bef81809c27bb47457dfdc10c633ff6 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Simon Glass45b5a372015-04-29 22:25:59 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 *
Simon Glass45b5a372015-04-29 22:25:59 -06005 * Taken from coreboot file of the same name
6 */
7
8#ifndef _X86_MP_H_
9#define _X86_MP_H_
10
11#include <asm/atomic.h>
Simon Glass90526e92020-05-10 11:39:56 -060012#include <asm/cache.h>
Simon Glass45b5a372015-04-29 22:25:59 -060013
Simon Glassc33aa352020-07-17 08:48:16 -060014enum {
15 /* Indicates that the function should run on all CPUs */
16 MP_SELECT_ALL = -1,
17
18 /* Run on boot CPUs */
19 MP_SELECT_BSP = -2,
20
21 /* Run on non-boot CPUs */
22 MP_SELECT_APS = -3,
23};
24
Simon Glass45b5a372015-04-29 22:25:59 -060025typedef int (*mp_callback_t)(struct udevice *cpu, void *arg);
26
27/*
28 * A mp_flight_record details a sequence of calls for the APs to perform
29 * along with the BSP to coordinate sequencing. Each flight record either
30 * provides a barrier for each AP before calling the callback or the APs
31 * are allowed to perform the callback without waiting. Regardless, each
32 * record has the cpus_entered field incremented for each record. When
33 * the BSP observes that the cpus_entered matches the number of APs
34 * the bsp_call is called with bsp_arg and upon returning releases the
35 * barrier allowing the APs to make further progress.
36 *
37 * Note that ap_call() and bsp_call() can be NULL. In the NULL case the
38 * callback will just not be called.
39 */
40struct mp_flight_record {
41 atomic_t barrier;
42 atomic_t cpus_entered;
43 mp_callback_t ap_call;
44 void *ap_arg;
45 mp_callback_t bsp_call;
46 void *bsp_arg;
47} __attribute__((aligned(ARCH_DMA_MINALIGN)));
48
49#define MP_FLIGHT_RECORD(barrier_, ap_func_, ap_arg_, bsp_func_, bsp_arg_) \
50 { \
51 .barrier = ATOMIC_INIT(barrier_), \
52 .cpus_entered = ATOMIC_INIT(0), \
53 .ap_call = ap_func_, \
54 .ap_arg = ap_arg_, \
55 .bsp_call = bsp_func_, \
56 .bsp_arg = bsp_arg_, \
57 }
58
59#define MP_FR_BLOCK_APS(ap_func, ap_arg, bsp_func, bsp_arg) \
60 MP_FLIGHT_RECORD(0, ap_func, ap_arg, bsp_func, bsp_arg)
61
62#define MP_FR_NOBLOCK_APS(ap_func, ap_arg, bsp_func, bsp_arg) \
63 MP_FLIGHT_RECORD(1, ap_func, ap_arg, bsp_func, bsp_arg)
64
65/*
Simon Glass45b5a372015-04-29 22:25:59 -060066 * mp_init() will set up the SIPI vector and bring up the APs according to
67 * mp_params. Each flight record will be executed according to the plan. Note
68 * that the MP infrastructure uses SMM default area without saving it. It's
69 * up to the chipset or mainboard to either e820 reserve this area or save this
70 * region prior to calling mp_init() and restoring it after mp_init returns.
71 *
72 * At the time mp_init() is called the MTRR MSRs are mirrored into APs then
73 * caching is enabled before running the flight plan.
74 *
75 * The MP init has the following properties:
76 * 1. APs are brought up in parallel.
77 * 2. The ordering of cpu number and APIC ids is not deterministic.
78 * Therefore, one cannot rely on this property or the order of devices in
79 * the device tree unless the chipset or mainboard know the APIC ids
80 * a priori.
81 *
82 * mp_init() returns < 0 on error, 0 on success.
83 */
Simon Glass78d57d62020-07-17 08:48:08 -060084int mp_init(void);
Simon Glass45b5a372015-04-29 22:25:59 -060085
Simon Glassbe059e82017-01-16 07:03:57 -070086/* Set up additional CPUs */
87int x86_mp_init(void);
88
Simon Glass45b5a372015-04-29 22:25:59 -060089#endif /* _X86_MP_H_ */