nvme-uclass.c 939 B

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