From 03784fa97a764be81ca9bcf79222e7b37e2e7692 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Mon, 9 Dec 2013 17:46:22 -0800 Subject: Add check_member macro to allow clean and easy struct offset checking This patch adds a new static assertion macro that can be used to check the offsets in structures that overlay register sets at compile time. It uses the _Static_assert() declaration from the new ISO C11 standard, which is supported (even without -std=c11) by GCC after version 4.6. (There is supposedly also support in clang, although I haven't tried it... let's deal with compiler issues when/if they turn up.) I've added it to all structures for our current ARM SoCs for now, and I think every new register overlay we add going forward should use them (at least for the last member, but feel free to add more if you think it's useful). Change-Id: If32510e7049739ad05618d363a854dc372d64386 Signed-off-by: Julius Werner Reviewed-on: https://chromium-review.googlesource.com/179412 Reviewed-by: David Hendricks Reviewed-by: Stefan Reinauer (cherry picked from commit cef5fa13c31375a316ca4556c0039b17c8ea7900) Signed-off-by: Isaac Christensen Reviewed-on: http://review.coreboot.org/6905 Tested-by: build bot (Jenkins) --- src/soc/samsung/exynos5250/clk.h | 4 +++- src/soc/samsung/exynos5250/dmc.h | 4 +++- src/soc/samsung/exynos5250/dp.h | 1 + src/soc/samsung/exynos5250/dsim.h | 1 + src/soc/samsung/exynos5250/fimd.h | 2 ++ src/soc/samsung/exynos5250/power.h | 1 + src/soc/samsung/exynos5250/spi.h | 1 + src/soc/samsung/exynos5250/sysreg.h | 1 + src/soc/samsung/exynos5250/tmu.h | 1 + src/soc/samsung/exynos5250/trustzone.h | 1 + src/soc/samsung/exynos5250/uart.h | 8 +------- src/soc/samsung/exynos5250/usb.h | 3 +++ 12 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src/soc/samsung/exynos5250') diff --git a/src/soc/samsung/exynos5250/clk.h b/src/soc/samsung/exynos5250/clk.h index f09ac41643..9d27e679ca 100644 --- a/src/soc/samsung/exynos5250/clk.h +++ b/src/soc/samsung/exynos5250/clk.h @@ -431,7 +431,7 @@ struct exynos5_clock { unsigned int clkout_cmu_r1x_div_stat; unsigned char res98[0x3608]; - unsigned int bpll_lock; /* base + 0x2000c */ + unsigned int bpll_lock; /* base + 0x20010 */ unsigned char res99[0xfc]; unsigned int bpll_con0; unsigned int bpll_con1; @@ -461,6 +461,7 @@ struct exynos5_clock { unsigned int pll_div2_sel; unsigned char res109b[0xf5e4]; }; +check_member(exynos5_clock, pll_div2_sel, 0x20a24); static struct exynos5_clock * const exynos_clock = (void *)EXYNOS5_CLOCK_BASE; @@ -521,6 +522,7 @@ struct exynos5_mct { uint8_t reserved14[0x8]; uint32_t l1_wstat; }; +check_member(exynos5_mct, l1_wstat, 0x440); static struct exynos5_mct * const exynos_mct = (void *)EXYNOS5_MULTI_CORE_TIMER_BASE; diff --git a/src/soc/samsung/exynos5250/dmc.h b/src/soc/samsung/exynos5250/dmc.h index 6388316c5e..acd9850a04 100644 --- a/src/soc/samsung/exynos5250/dmc.h +++ b/src/soc/samsung/exynos5250/dmc.h @@ -115,6 +115,7 @@ struct exynos5_dmc { unsigned char res34[0xc]; unsigned int pmcnt3_ppc_a; }; +check_member(exynos5_dmc, pmcnt3_ppc_a, 0xe140); static struct exynos5_dmc * const exynos_dmc = (void *)EXYNOS5_DMC_CTRL_BASE; @@ -136,7 +137,7 @@ struct exynos5_phy_control { unsigned int phy_con14; unsigned int phy_con15; unsigned int phy_con16; - unsigned char res4[4]; + unsigned char res4[4]; /* NOT a mistake. Yes, it doesn't make sense. */ unsigned int phy_con17; unsigned int phy_con18; unsigned int phy_con19; @@ -164,6 +165,7 @@ struct exynos5_phy_control { unsigned int phy_con41; unsigned int phy_con42; }; +check_member(exynos5_phy_control, phy_con42, 0xac); static struct exynos5_phy_control * const exynos_phy0_control = (void *)EXYNOS5_DMC_PHY0_BASE; diff --git a/src/soc/samsung/exynos5250/dp.h b/src/soc/samsung/exynos5250/dp.h index b1533c74f7..d031929ef6 100644 --- a/src/soc/samsung/exynos5250/dp.h +++ b/src/soc/samsung/exynos5250/dp.h @@ -163,6 +163,7 @@ struct exynos5_dp { u8 res21[0x3c]; u32 soc_general_ctl; }; +check_member(exynos5_dp, soc_general_ctl, 0x800); static struct exynos5_dp * const exynos_dp0 = (void *)EXYNOS5_DP0_BASE; static struct exynos5_dp * const exynos_dp1 = (void *)EXYNOS5_DP1_BASE; diff --git a/src/soc/samsung/exynos5250/dsim.h b/src/soc/samsung/exynos5250/dsim.h index b9245d31e6..b975a106a8 100644 --- a/src/soc/samsung/exynos5250/dsim.h +++ b/src/soc/samsung/exynos5250/dsim.h @@ -48,6 +48,7 @@ struct exynos5_dsim { unsigned int phyacchr; unsigned int phyacchr1; }; +check_member(exynos5_dsim, phyacchr1, 0x54); #define ENABLE 1 #define DISABLE 0 diff --git a/src/soc/samsung/exynos5250/fimd.h b/src/soc/samsung/exynos5250/fimd.h index 178fb73d08..751e71b05c 100644 --- a/src/soc/samsung/exynos5250/fimd.h +++ b/src/soc/samsung/exynos5250/fimd.h @@ -61,6 +61,7 @@ struct exynos5_fimd { unsigned char res9[0x18]; unsigned int dpclkcon; }; +check_member(exynos5_fimd, dpclkcon, 0x27c); static struct exynos5_fimd * const exynos_fimd = (void *)EXYNOS5_FIMD_BASE; @@ -109,6 +110,7 @@ struct exynos5_disp_ctrl { unsigned char res2[0x184]; unsigned int trigcon; }; +check_member(exynos5_disp_ctrl, trigcon, 0x1a4); static struct exynos5_disp_ctrl * const exynos_disp_ctrl = (void *)EXYNOS5_DISP1_CTRL_BASE; diff --git a/src/soc/samsung/exynos5250/power.h b/src/soc/samsung/exynos5250/power.h index aa93893387..734bb29661 100644 --- a/src/soc/samsung/exynos5250/power.h +++ b/src/soc/samsung/exynos5250/power.h @@ -64,6 +64,7 @@ struct exynos5_power { uint8_t reserved8[0x1e0]; uint32_t ps_hold_ctrl; /* 0x330c */ } __attribute__ ((__packed__)); +check_member(exynos5_power, ps_hold_ctrl, 0x330c); static struct exynos5_power * const exynos_power = (void*)EXYNOS5_POWER_BASE; diff --git a/src/soc/samsung/exynos5250/spi.h b/src/soc/samsung/exynos5250/spi.h index 7ca311444c..4301d42e24 100644 --- a/src/soc/samsung/exynos5250/spi.h +++ b/src/soc/samsung/exynos5250/spi.h @@ -39,6 +39,7 @@ struct exynos_spi { unsigned int fb_clk; /* 0x2c */ unsigned char padding[0xffd0]; }; +check_member(exynos_spi, fb_clk, 0x2c); #define EXYNOS_SPI_MAX_FREQ 50000000 diff --git a/src/soc/samsung/exynos5250/sysreg.h b/src/soc/samsung/exynos5250/sysreg.h index 1362177a33..ece9011abf 100644 --- a/src/soc/samsung/exynos5250/sysreg.h +++ b/src/soc/samsung/exynos5250/sysreg.h @@ -32,6 +32,7 @@ struct exynos5_sysreg { unsigned char res2[0x18]; unsigned int usb20_phy_cfg; }; +check_member(exynos5_sysreg, usb20_phy_cfg, 0x230); static struct exynos5_sysreg * const exynos_sysreg = (void *)EXYNOS5_SYSREG_BASE; diff --git a/src/soc/samsung/exynos5250/tmu.h b/src/soc/samsung/exynos5250/tmu.h index bda4bd7dd8..34d1f45fef 100644 --- a/src/soc/samsung/exynos5250/tmu.h +++ b/src/soc/samsung/exynos5250/tmu.h @@ -57,6 +57,7 @@ struct tmu_reg { unsigned rsvd15; unsigned emul_con; }; +check_member(tmu_reg, emul_con, 0x80); enum tmu_status_t { TMU_STATUS_INIT = 0, diff --git a/src/soc/samsung/exynos5250/trustzone.h b/src/soc/samsung/exynos5250/trustzone.h index 7b4af9b1f1..4cbb1aa1a5 100644 --- a/src/soc/samsung/exynos5250/trustzone.h +++ b/src/soc/samsung/exynos5250/trustzone.h @@ -75,6 +75,7 @@ struct exynos_tzpc { u32 pcellid2; u32 pcellid3; }; +check_member(exynos_tzpc, pcellid3, 0xffc); void trustzone_init(void); diff --git a/src/soc/samsung/exynos5250/uart.h b/src/soc/samsung/exynos5250/uart.h index d324a2f93d..e2514d7b6d 100644 --- a/src/soc/samsung/exynos5250/uart.h +++ b/src/soc/samsung/exynos5250/uart.h @@ -21,12 +21,6 @@ #ifndef CPU_SAMSUNG_EXYNOS5250_UART_H #define CPU_SAMSUNG_EXYNOS5250_UART_H -/* baudrate rest value */ -union br_rest { - unsigned short slot; /* udivslot */ - unsigned char value; /* ufracval */ -}; - struct s5p_uart { unsigned int ulcon; unsigned int ucon; @@ -41,8 +35,8 @@ struct s5p_uart { unsigned char urxh; unsigned char res2[3]; unsigned int ubrdiv; - union br_rest rest; unsigned char res3[0xffd0]; }; +check_member(s5p_uart, ubrdiv, 0x28); #endif diff --git a/src/soc/samsung/exynos5250/usb.h b/src/soc/samsung/exynos5250/usb.h index ad617da96c..20a22571a2 100644 --- a/src/soc/samsung/exynos5250/usb.h +++ b/src/soc/samsung/exynos5250/usb.h @@ -58,6 +58,7 @@ struct exynos5_usb_host_phy { uint8_t reserved4[4]; uint32_t usbotgtune; }; +check_member(exynos5_usb_host_phy, usbotgtune, 0x40); static struct exynos5_usb_host_phy * const exynos_usb_host_phy = (void *)EXYNOS5_USB_HOST_PHY_BASE; @@ -81,6 +82,7 @@ struct exynos5_usb_drd_phy { uint32_t linkhcbelt; uint32_t linkport; }; +check_member(exynos5_usb_drd_phy, linkport, 0x44); static struct exynos5_usb_drd_phy * const exynos_usb_drd_phy = (void *)EXYNOS5_USB_DRD_PHY_BASE; @@ -121,6 +123,7 @@ struct exynos5_usb_drd_dwc3 { uint32_t usb3pipectl; uint8_t reserved6[60]; }; +check_member(exynos5_usb_drd_dwc3, usb3pipectl, 0x1c0); static struct exynos5_usb_drd_dwc3 * const exynos_usb_drd_dwc3 = (void *)EXYNOS5_USB_DRD_DWC3_BASE; -- cgit v1.2.3