Zong Li | 213ed17 | 2021-09-01 15:01:41 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2021 SiFive, Inc |
| 4 | */ |
| 5 | |
Zong Li | 213ed17 | 2021-09-01 15:01:41 +0800 | [diff] [blame] | 6 | #include <cache.h> |
| 7 | #include <cpu_func.h> |
Tom Rini | 0b9441a | 2023-10-12 19:03:59 -0400 | [diff] [blame] | 8 | #include <log.h> |
Zong Li | 213ed17 | 2021-09-01 15:01:41 +0800 | [diff] [blame] | 9 | #include <dm.h> |
Zong Li | 40c76df | 2023-12-14 14:09:37 +0000 | [diff] [blame^] | 10 | #include <dm/device-internal.h> |
| 11 | #include <dm/uclass-internal.h> |
Zong Li | 213ed17 | 2021-09-01 15:01:41 +0800 | [diff] [blame] | 12 | |
Zong Li | 40c76df | 2023-12-14 14:09:37 +0000 | [diff] [blame^] | 13 | #ifndef CONFIG_SPL_BUILD |
Zong Li | 213ed17 | 2021-09-01 15:01:41 +0800 | [diff] [blame] | 14 | void 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 Li | 40c76df | 2023-12-14 14:09:37 +0000 | [diff] [blame^] | 31 | #else |
| 32 | static 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 | |
| 42 | void 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 */ |