blob: d8fe1dfa95887d21af721033c0795d631325cff9 [file] [log] [blame]
Zong Li213ed172021-09-01 15:01:41 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2021 SiFive, Inc
4 */
5
Zong Li213ed172021-09-01 15:01:41 +08006#include <cache.h>
7#include <cpu_func.h>
Tom Rini0b9441a2023-10-12 19:03:59 -04008#include <log.h>
Zong Li213ed172021-09-01 15:01:41 +08009#include <dm.h>
Zong Li40c76df2023-12-14 14:09:37 +000010#include <dm/device-internal.h>
11#include <dm/uclass-internal.h>
Zong Li213ed172021-09-01 15:01:41 +080012
Zong Li40c76df2023-12-14 14:09:37 +000013#ifndef CONFIG_SPL_BUILD
Zong Li213ed172021-09-01 15:01:41 +080014void enable_caches(void)
15{
16 struct udevice *dev;
17 int ret;
18
19 /* Enable ways of ccache */
20 ret = uclass_get_device_by_driver(UCLASS_CACHE,
21 DM_DRIVER_GET(sifive_ccache),
22 &dev);
23 if (ret) {
24 log_debug("Cannot enable cache ways");
25 } else {
26 ret = cache_enable(dev);
27 if (ret)
28 log_debug("ccache enable failed");
29 }
30}
Zong Li40c76df2023-12-14 14:09:37 +000031#else
32static inline void probe_cache_device(struct driver *driver, struct udevice *dev)
33{
34 for (uclass_find_first_device(UCLASS_CACHE, &dev);
35 dev;
36 uclass_find_next_device(&dev)) {
37 if (dev->driver == driver)
38 device_probe(dev);
39 }
40}
41
42void enable_caches(void)
43{
44 struct udevice *dev = NULL;
45
46 probe_cache_device(DM_DRIVER_GET(sifive_pl2), dev);
47}
48#endif /* !CONFIG_SPL_BUILD */