blob: 7b5cedf2132cf4f5202c0fd42c96d04b6d7b7d3d [file] [log] [blame]
Gabe Black19e7e7d2011-10-01 04:27:32 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
18 */
19
20#ifndef CPU_X86_CAR_H
21#define CPU_X86_CAR_H
22
23#ifdef __PRE_RAM__
24#define CAR_GLOBAL __attribute__((section(".car.global_data,\"w\",@nobits#")))
25#define CAR_CBMEM __attribute__((section(".car.cbmem_console,\"w\",@nobits#")))
26#else
27#define CAR_GLOBAL
28#define CAR_CBMEM
29#endif
30
Aaron Durbin716738a2013-05-10 00:33:32 -050031#if CONFIG_CAR_MIGRATION && defined(__PRE_RAM__)
32#define CAR_MIGRATE_ATTR __attribute__ ((used,section (".car.migrate")))
33
34/* Call migrate_fn_() when CAR globals are migrated. */
35#define CAR_MIGRATE(migrate_fn_) \
36 static void (* const migrate_fn_ ## _ptr)(void) CAR_MIGRATE_ATTR = \
37 migrate_fn_;
38
39/* Get the correct pointer for the CAR global variable. */
40void *car_get_var_ptr(void *var);
41
42/* Get and set a primitive type global variable. */
43#define car_get_var(var) \
44 *(typeof(var) *)car_get_var_ptr(&(var))
45#define car_set_var(var, val) \
46 do { car_get_var(var) = (val); } while(0)
47
48/* Migrate the CAR variables to memory. */
49void car_migrate_variables(void);
50
51#else
52#define CAR_MIGRATE(migrate_fn_)
53static inline void *car_get_var_ptr(void *var) { return var; }
54#define car_get_var(var) (var)
55#define car_set_var(var, val) do { (var) = (val); } while (0)
56static inline void car_migrate_variables(void) { }
57#endif
58
59
Gabe Black19e7e7d2011-10-01 04:27:32 -070060#endif