nvme-uclass.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 NXP Semiconductors
  4. * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
  5. */
  6. #define LOG_CATEGORY UCLASS_NVME
  7. #include <common.h>
  8. #include <bootdev.h>
  9. #include <dm.h>
  10. #include <init.h>
  11. #include <log.h>
  12. #include <nvme.h>
  13. static int nvme_bootdev_bind(struct udevice *dev)
  14. {
  15. struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
  16. ucp->prio = BOOTDEVP_4_SCAN_FAST;
  17. return 0;
  18. }
  19. static int nvme_bootdev_hunt(struct bootdev_hunter *info, bool show)
  20. {
  21. int ret;
  22. /* init PCI first since this is often used to provide NVMe */
  23. if (IS_ENABLED(CONFIG_PCI)) {
  24. ret = pci_init();
  25. if (ret)
  26. log_warning("Failed to init PCI (%dE)\n", ret);
  27. }
  28. ret = nvme_scan_namespace();
  29. if (ret)
  30. return log_msg_ret("scan", ret);
  31. return 0;
  32. }
  33. UCLASS_DRIVER(nvme) = {
  34. .name = "nvme",
  35. .id = UCLASS_NVME,
  36. };
  37. struct bootdev_ops nvme_bootdev_ops = {
  38. };
  39. static const struct udevice_id nvme_bootdev_ids[] = {
  40. { .compatible = "u-boot,bootdev-nvme" },
  41. { }
  42. };
  43. U_BOOT_DRIVER(nvme_bootdev) = {
  44. .name = "nvme_bootdev",
  45. .id = UCLASS_BOOTDEV,
  46. .ops = &nvme_bootdev_ops,
  47. .bind = nvme_bootdev_bind,
  48. .of_match = nvme_bootdev_ids,
  49. };
  50. BOOTDEV_HUNTER(nvme_bootdev_hunter) = {
  51. .prio = BOOTDEVP_4_SCAN_FAST,
  52. .uclass = UCLASS_NVME,
  53. .hunt = nvme_bootdev_hunt,
  54. .drv = DM_DRIVER_REF(nvme_bootdev),
  55. };