summaryrefslogtreecommitdiff
path: root/lib/utils/timer
AgeCommit message (Collapse)AuthorFilesLines
2024-11-28lib: utils/timer: Use fdt_driver for initializationSamuel Holland4-40/+9
The timer driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_timer_init() performs a best-effort initialization of all matching DT nodes. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28treewide: Make carray arrays const and NULL-terminatedSamuel Holland1-3/+2
This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also simplifies passing carray arrays to helper functions. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-05platform: Drop timer warm init and exit hooksSamuel Holland3-34/+1
Now that driver lifecycle is managed from within the SBI timer core, platforms need only to initialize the driver once during cold init. Remove the remaining platform hooks that are no longer used. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-05lib: sbi_timer: Call driver warm_init from SBI coreSamuel Holland4-14/+16
Currently, the platform's timer device is tracked in two places: the core SBI implementation has `timer_dev`, and the FDT timer layer has `current_driver`. The latter is used for warm initialization of the timer device. However, this warm init is not specific to FDT-based platforms; other platforms call exactly the same functions from the same point in the boot sequence. The code is simplified and made common across platforms by treating warm init and exit as properties of the driver, not the platform. Then the platform's only role is to select and prepare a driver during cold boot. For now, only add a .warm_init hook, since none of the existing drivers need an .exit hook. It could be added in the future if needed. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24lib: utils/timer: Constify FDT pointers in parsing functionsSamuel Holland3-3/+3
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-07-04Makefile: change to using .carray.c for carray filesBen Dooks1-1/+1
We would like to clean any files generated by the carray scripts by just searching for the filename as the current make system turns f.carray into f.o. Change to make the make system turn f.carray into f.carray.o note, command to go through .mk files changing the .o in the .mk files is: find . -type f -name "*.carray" | xargs -t -I fname /bin/bash -x -c ' fn=`basename -s .carray fname`; echo "$fn"; sed -i `dirname fname `/objects.mk -e s/"$fn".o/"$fn".carray.o/g' Link: https://patchwork.ozlabs.org/project/opensbi/patch/20240401213438.590209-2-ivan.orlov0322@gmail.com/ Reported-by: Ivan Orlov <ivan.orlov0322@gmail.com> Suggested-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-06-13lib: utils/timer: Skip initialize timer when dt is not enabledXiang W1-0/+3
When the dt node has a status property and the value is not ok or okay, skip initializing timer. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-04-05lib: utils/timer: Optimize current hart scratch accessSamuel Holland1-15/+3
The address of the local scratch area is stored in each hart's mscratch CSR. It is more efficient to read the CSR than to compute the address from the hart ID. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-27lib: utils/timer: mtimer: only use regname for aclintInochi Amaoto1-2/+3
The parser will fail if the timer is clint timer and has regname property. As the regname is only meaningful for aclint, it is more robust to only check regname for aclint timer. Fixes: 6112d58 ("lib: utils/fdt: Allow to use reg-names when parsing ACLINT") Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-11-16lib: utils/timer: mtimer: add separate T-Head C9xx CLINT mtimer compatibleInochi Amaoto1-0/+6
T-HEAD allows soc vendor to map the mtimer and mswi of C9xx clint on different address, which may cause a misuse if use the same compatible string, add a new timer compatible string to avoid this. Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Link: https://lore.kernel.org/linux-riscv/6e48cbe5e60f9ada2fd1fe58e803e127f1a678e5.1696433229.git.unicorn_wang@outlook.com/ Reviewed-by: Guo Ren <guoren@kernel.org> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-11-16lib: utils/timer: Allow ACLINT MTIMER driver to setup quirksInochi Amaoto1-15/+20
The quirks checking will cause ACLINT step into a CLINT code path, this is not expected when ACLINT needs custom quirks. Add a new quirk to identify custom ACLINT, and apply the general quirks after applying CLINT specific quirks. Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-10-06lib: utils: timer/ipi: Update memregion flags for PLMT and PLICSWYu Chien Peter Lin1-2/+5
This patch adds unspecified permission flags for the PLICSW region and updates the permission of the PLMT region. With this update, both regions will become M-mode only read/write regions in the root domain. Domain0 Region00: 0x00000000f0300000-0x00000000f0300fff M: (I,R,W) S/U: (R,W) Domain0 Region01: 0x0000000000040000-0x000000000005ffff M: (R,W) S/U: () Domain0 Region02: 0x0000000000000000-0x000000000003ffff M: (R,X) S/U: () > Domain0 Region03: 0x00000000e6000000-0x00000000e60fffff M: (I,R,W) S/U: () > Domain0 Region04: 0x00000000e6400000-0x00000000e67fffff M: (I,R,W) S/U: () Domain0 Region05: 0x0000000000000000-0xffffffffffffffff M: () S/U: (R,W,X) The PMP rules of AE350-AX65 (single-core) w/ Smepmp: p/x $pmpcfg0 $1 = {0x1f9b9b9d9b1e00, pmp0cfg = {0x0}, L--AAXWR pmp1cfg = {0x1e} (00011110), pmpaddr1: 0xf0300000 ~ 0xf0300fff (UART1) pmp2cfg = {0x9b} (10011011), pmpaddr2: 0x40000 ~ 0x5ffff pmp3cfg = {0x9d} (10011101), pmpaddr3: 0x0 ~ 0x3ffff pmp4cfg = {0x9b} (10011011), pmpaddr4: 0xe6000000 ~ 0xe60fffff (PLMT) pmp5cfg = {0x9b} (10011011), pmpaddr5: 0xe6400000 ~ 0xe67fffff (PLICSW) pmp6cfg = {0x1f} (00011111), pmpaddr6: 0x0 ~ 0xffffffffff pmp7cfg = {0x0 }} The PMP rules of AE350-AX45MP (qual-core) w/o Smepmp: p/x $pmpcfg0 $1 = {0x1f181818181b, L--AAXWR pmp0cfg = {0x1b}, (00011011), pmpaddr0: 0xf0300000 ~ 0xf0300fff (UART1) pmp1cfg = {0x18}, (00011000), pmpaddr1: 0x40000 ~ 0x5ffff pmp2cfg = {0x18}, (00011000), pmpaddr2: 0x0 ~ 0x3ffff pmp3cfg = {0x18}, (00011000), pmpaddr3: 0xe6000000 ~ 0xe60fffff (PLMT) pmp4cfg = {0x18}, (00011000), pmpaddr4: 0xe6400000 ~ 0xe67fffff (PLICSW) pmp5cfg = {0x1f}, (00011111), pmpaddr5: 0x0 ~ 0x1ffffffff pmp6cfg = {0x0 }} Note that starting from this patch, we restrict the S/U-mode read permission to the PLMT region, since we should read the TIME CSR in a lower privilege mode. Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-07-09lib: utils: Fix sbi_hartid_to_scratch() usage in ACLINT driversAnup Patel1-1/+6
The cold_init() functions of ACLINT drivers should skip the HART if sbi_hartid_to_scratch() returns NULL because we might be dealing with a HART that is disabled in the device tree. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Xiang W <wxjstz@126.com>
2023-06-05lib: utils/timer: Use scratch space to save per-HART MTIMER pointerAnup Patel1-15/+61
Instead of using a global array indexed by hartid, we should use scratch space to save per-HART MTIMER pointer. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-06-05lib: utils/timer: Use heap in ACLINT MTIMER driverAnup Patel1-17/+30
Let's use heap allocation in ACLINT MTIMER driver instead of using a fixed size global array. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-05-26lib: utils: Improve fdt_timerXiang W1-20/+21
Remove dummy driver. Optimize fdt_timer_cold_init to exit the loop early. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-01-09lib: utils: Add M-mode {R/W} flags to the MMIO regionsHimanshu Chauhan1-4/+12
Add the M-mode readable/writable flags to mmio regions of various drivers. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org> Tested-by: Anup Patel <anup@brainfault.org>
2022-12-17lib: utils/timer: mtimer: add T-Head C9xx CLINT compatibleIcenowy Zheng1-0/+6
As we already added the quirk for lacking mtime register to MTIMER driver, add T-Head C9xx CLINT compatible to it and wire the quirk. Signed-off-by: Icenowy Zheng <uwu@icenowy.me> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-12-17lib: utils/timer: mtimer: add a quirk for lacking mtime registerIcenowy Zheng2-13/+28
T-Head developers surely have a different understanding of time CSR and CLINT's mtime register with SiFive ones, that they did not implement the mtime register at all -- as shown in openC906 source code, their time CSR value is just exposed at the top of their processor IP block and expects an external continous counter, which makes it not overrideable, and thus mtime register is not implemented, even not for reading. However, if CLINTEE is not enabled in T-Head's MXSTATUS extended CSR, these systems still rely on the mtimecmp registers to generate timer interrupts. This makes it necessary to implement T-Head C9xx CLINT support in OpenSBI MTIMER driver, which skips implementing reading mtime register and falls back to default code that reads time CSR. Add a quirk into MTIMER driver, which represents a mtime register is lacking and time CSR value should be used instead. Signed-off-by: Icenowy Zheng <uwu@icenowy.me> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-10-23lib: utils/timer: Add Andes fdt timer supportYu Chien Peter Lin4-0/+168
Since we can get the PLMT base address and timer frequency from device tree, move plmt timer device to fdt timer framework. dts example (Quad-core AX45MP): cpus { ... timebase-frequency = <0x3938700>; ... } soc { ... plmt0@e6000000 { compatible = "andestech,plmt0"; reg = <0x00 0xe6000000 0x00 0x100000>; interrupts-extended = <&cpu0_intc 0x07 &cpu1_intc 0x07 &cpu2_intc 0x07 &cpu3_intc 0x07>; }; ... } Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-10-23lib: sbi: Add sbi_domain_root_add_memrange() APIYu Chien Peter Lin1-36/+14
This patch generalizes the logic to add a memory range with desired alignment and flags of consecutive regions to the root domain. Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-08lib: utils/fdt: Use kconfig for enabling/disablingAnup Patel1-0/+1
We update FDT support makefile to use kconfig for enabling/disabling. To avoid compilation errors, we also enable FDT for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/timer: Use kconfig for enabling/disabling driversAnup Patel2-5/+27
We update timer drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate timer drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-06-22lib: utils/timer: Remove Allwinner D1 CLINT compatiblesVF2_v2.6.0VF2_v2.5.0VF2_v2.4.4Samuel Holland1-6/+0
The allwinner,sun20i-d1-clint compatible string is not documented in any official binding, so it should not be used by drivers. The MSWI in the D1 CLINT is compatible with the ACLINT specification, so it can take advantage of generic driver support. However, that is only possible if the MSWI and MTIMER are split into separate DT nodes. This means the final binding for this device is likely to be incompatible with what is implemented here. Remove this compatible string from the driver to prevent it from appearing in a stable version and causing future issues. Signed-off-by: Samuel Holland <samuel@sholland.org> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-06-21lib: utils/timer: Add a separate compatible for the D1 CLINTSamuel Holland1-14/+25
The CLINT in the Allwinner D1 SoC apparently does not support 64-bit MMIO access. A property was added to support this quirk (and that property was copied to the ACLINT MTIMER code). However, since this difference in behavior makes the D1 CLINT incompatible with the SiFive CLINT's programming interface, a better solution is to use a separate compatible string. Signed-off-by: Samuel Holland <samuel@sholland.org> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-05-30lib: utils/fdt: Require match data to be constSamuel Holland1-1/+1
Match data stores hardware attributes which do not change at runtime, so it does not need to be mutable. Make it const. Reviewed-by: Guo Ren <guoren@kernel.org> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Samuel Holland <samuel@sholland.org>
2022-05-13lib: utils/timer: Generate FDT timer driver list at compile-timeAnup Patel3-7/+12
Instead of having FDT timer driver list hard-coded in the C source, we generate it using carray.sh at compile-time. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-02-04lib: fix compilation when strings.h is includedPetro Karashchenko1-1/+1
In a systems that provide strings.h and it is included together with sbi_bitops.h the compilation error appears. The ffs() and fls() are provided by strings.h Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-01-21lib: fix pointer of type 'void *' used in arithmeticJukka Laitinen1-1/+1
Using "void *" in arithmetic causes errors with strict compiler settings: "error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]" Avoid these by calculating on "char *" where 1-byte data size is assumed. Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae> Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2021-11-02include: sbi_utils: Introduce an helper to get fdt base addressAlexandre Ghiti1-1/+1
This simply adds an helper to get fdt address which is more explicit than sbi_scratch_thishart_arg1_ptr. Signed-off-by: Alexandre Ghiti <alexandre.ghiti@canonical.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-09-26lib: sbi: Add timer frequency to struct sbi_timer_deviceAnup Patel2-0/+7
Generic mdelay() and udelay() functions can be provided by the sbi_timer framework if timer frequency is available in the timer instance provided by the platform support or timer driver. This patch adds timer frequency (timer_freq) member in the struct sbi_timer_device for above purpose. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-08-14lib: utils/timer: Simplify MTIMER synchronizationAnup Patel2-32/+77
We simplify MTIMER synchronization as follows: 1) Detect MTIMER devices with unique (or non-shared) MTIME register at boot-time 2) Select first MTIMER device with no associated HART as our reference MTIMER device 3) Only synchronize MTIMER devices with unique (or non-shared) MTIME register using reference MTIMER device 4) Directly update the MTIME register at time of synchronization because MTIME is a read/write register. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-14lib: utils/timer: Allow ACLINT MTIMER supporting only 32-bit MMIOAnup Patel1-0/+3
We can have ACLINT MTIMER devices which only support 32-bit MMIO accesses on RV64 system so this patch adds a boolean DT property "mtimer,no-64bit-mmio" to detect this from MTIMER DT node. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-14lib: utils/fdt: Extend fdt_parse_aclint_node() functionAnup Patel1-8/+15
The fdt_parse_aclint_node() is used to parse DT node for SiFive CLINT, ACLINT MTIMER, and ACLINT MSWI devices. The ACLINT MTIMER has undergone following changes: 1) MTIMER DT node now requires separate addresses in for MTIME register and MTIMECMPx registers in the reg DT property. 2) MTIMER DT node might have no interrupts-extended DT property when the MTIMER device has no associated HARTs (i.e. the MTIMER device has no MTIMECMPx registers) This patch extends fdt_parse_aclint_node() to handle above mentioned changes in ACLINT MTIMER DT bindings. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-14lib: utils/timer: Allow separate base addresses for MTIME and MTIMECMPAnup Patel2-25/+69
We extend the ACLINT library to support separate base addresses for MTIME and MTIMECMP registers. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-06-24lib: utils/timer: Add FDT based ACLINT MTIMER driverAnup Patel4-60/+77
We add a new FDT based ACLINT MTIMER driver which works for both CLINT device and standalone ACLINT MTIMER device. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-06-24lib: utils: Add FDT parsing API common for both ACLINT and CLINTAnup Patel1-1/+8
We add fdt_parse_aclint_node() which can parse both ACLINT and CLINT DT nodes. This means fdt_parse_clint_node() is not required anymore so we remove it as well. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-06-24lib: utils/timer: Add ACLINT MTIMER libraryAnup Patel2-0/+181
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-05-24lib: utils: Try other FDT drivers when we see SBI_ENODEVAnup Patel1-0/+3
We should try other FDT drivers when we see SBI_ENODEV returned by cold_init() of FDT driver. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-04-28lib: sbi: Simplify timer platform operationsAnup Patel2-34/+0
Instead of having timer_value(), timer_event_start(), and timer_event_stop() callbacks in platform operations, it will be much simpler for timer driver to directly register these operations as device to the sbi_timer implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-01lib/utils: Support the official clint DT bindingsBin Meng1-0/+1
Linux kernel commit a2770b57d083 ("dt-bindings: timer: Add CLINT bindings") adds the official DT bindings for CLINT, which uses "sifive,clint0" as the compatible string. "riscv,clint0" is now legacy and has to be kept for backward compatibility of legacy systems. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-05-23lib: utils/timer: Initialize all matching timer DT nodesAnup Patel2-13/+26
We can have multiple matching DT nodes of the same FDT timer driver so in this case we should call cold_init() for all matching DT nodes instead of just first matching DT node. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils: Add fdt_parse_clint_node() functionAnup Patel1-13/+1
We add fdt_parse_clint_node() function which will be used by fdt_ipi_clint and fdt_timer_clint drivers to parse CLINT details from DT node. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils: Allow CLINT functions to be used for multiple CLINTsAnup Patel1-1/+8
We extend CLINT cold init function to have a "struct clint_data *" parameter pointing to CLINT details. This allows platforms to use CLINT functions for multiple CLINT instances. When multiple CLINTs are present, the platform can also provide one of the CLINT as reference CLINT for other CLINTs. This will help CLINTs to sync their time value with reference CLINT using a time_delta computed in warm init function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils: Extend fdt_find_match() ImplementationAnup Patel1-1/+1
We extend fdt_find_match() implementation by adding node offset parameter which represents the first node to match from. The improved fdt_find_match() can be used to find multiple match nodes. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-01lib: utils: Add simple FDT timer frameworkAnup Patel3-0/+167
We add simple timer framework which will select and use timer driver based on details in FDT passed by previous booting stage. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>