Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Zhikang Zhang | 145b88f | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 NXP Semiconductors |
| 4 | * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> |
Zhikang Zhang | 145b88f | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Patrick Delaunay | 8131335 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 7 | #define LOG_CATEGORY UCLASS_NVME |
| 8 | |
Zhikang Zhang | 145b88f | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 9 | #include <common.h> |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 10 | #include <bootdev.h> |
Zhikang Zhang | 145b88f | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 12 | #include <init.h> |
| 13 | #include <log.h> |
| 14 | #include <nvme.h> |
| 15 | |
| 16 | static int nvme_bootdev_bind(struct udevice *dev) |
| 17 | { |
| 18 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 19 | |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 20 | ucp->prio = BOOTDEVP_4_SCAN_FAST; |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 21 | |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | static int nvme_bootdev_hunt(struct bootdev_hunter *info, bool show) |
| 26 | { |
| 27 | int ret; |
| 28 | |
| 29 | /* init PCI first since this is often used to provide NVMe */ |
| 30 | if (IS_ENABLED(CONFIG_PCI)) { |
| 31 | ret = pci_init(); |
| 32 | if (ret) |
| 33 | log_warning("Failed to init PCI (%dE)\n", ret); |
| 34 | } |
| 35 | |
| 36 | ret = nvme_scan_namespace(); |
| 37 | if (ret) |
| 38 | return log_msg_ret("scan", ret); |
| 39 | |
| 40 | return 0; |
| 41 | } |
Zhikang Zhang | 145b88f | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 42 | |
| 43 | UCLASS_DRIVER(nvme) = { |
| 44 | .name = "nvme", |
| 45 | .id = UCLASS_NVME, |
Zhikang Zhang | 145b88f | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 46 | }; |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 47 | |
| 48 | struct bootdev_ops nvme_bootdev_ops = { |
| 49 | }; |
| 50 | |
| 51 | static const struct udevice_id nvme_bootdev_ids[] = { |
| 52 | { .compatible = "u-boot,bootdev-nvme" }, |
| 53 | { } |
| 54 | }; |
| 55 | |
| 56 | U_BOOT_DRIVER(nvme_bootdev) = { |
| 57 | .name = "nvme_bootdev", |
| 58 | .id = UCLASS_BOOTDEV, |
| 59 | .ops = &nvme_bootdev_ops, |
| 60 | .bind = nvme_bootdev_bind, |
| 61 | .of_match = nvme_bootdev_ids, |
| 62 | }; |
| 63 | |
| 64 | BOOTDEV_HUNTER(nvme_bootdev_hunter) = { |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 65 | .prio = BOOTDEVP_4_SCAN_FAST, |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 66 | .uclass = UCLASS_NVME, |
| 67 | .hunt = nvme_bootdev_hunt, |
| 68 | .drv = DM_DRIVER_REF(nvme_bootdev), |
| 69 | }; |