nvme-uclass.c 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include <common.h>
  7. #include <errno.h>
  8. #include <dm.h>
  9. #include <dm/device.h>
  10. #include "nvme.h"
  11. static int nvme_uclass_post_probe(struct udevice *udev)
  12. {
  13. char name[20];
  14. struct udevice *ns_udev;
  15. int i, ret;
  16. struct nvme_dev *ndev = dev_get_priv(udev);
  17. /* Create a blk device for each namespace */
  18. for (i = 0; i < ndev->nn; i++) {
  19. /*
  20. * Encode the namespace id to the device name so that
  21. * we can extract it when doing the probe.
  22. */
  23. sprintf(name, "blk#%d", i);
  24. /* The real blksz and size will be set by nvme_blk_probe() */
  25. ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
  26. -1, 512, 0, &ns_udev);
  27. if (ret)
  28. return ret;
  29. }
  30. return 0;
  31. }
  32. UCLASS_DRIVER(nvme) = {
  33. .name = "nvme",
  34. .id = UCLASS_NVME,
  35. .post_probe = nvme_uclass_post_probe,
  36. };