u-boot-brain/drivers/nvme/nvme-uclass.c
Bin Meng 18aa5a4134 nvme: Get rid of the global variable nvme_info
At present the NVMe uclass driver uses a global variable nvme_info
to store global information like namespace id, and NVMe controller
driver's priv struct has a blk_dev_start that is used to calculate
the namespace id based on the global information from nvme_info.

This is not a good design in the DM world and can be replaced with
the following changes:

- Encode the namespace id in the NVMe block device name during
  the NVMe uclass post probe
- Extract the namespace id from the device name during the NVMe
  block device probe
- Let BLK uclass calculate the devnum for us by passing -1 to
  blk_create_devicef() as the devnum

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2017-08-28 07:17:14 -04:00

44 lines
925 B
C

/*
* Copyright (C) 2017 NXP Semiconductors
* Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <errno.h>
#include <dm.h>
#include <dm/device.h>
#include "nvme.h"
static int nvme_uclass_post_probe(struct udevice *udev)
{
char name[20];
struct udevice *ns_udev;
int i, ret;
struct nvme_dev *ndev = dev_get_priv(udev);
/* Create a blk device for each namespace */
for (i = 0; i < ndev->nn; i++) {
/*
* Encode the namespace id to the device name so that
* we can extract it when doing the probe.
*/
sprintf(name, "blk#%d", i);
/* The real blksz and size will be set by nvme_blk_probe() */
ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
-1, 512, 0, &ns_udev);
if (ret)
return ret;
}
return 0;
}
UCLASS_DRIVER(nvme) = {
.name = "nvme",
.id = UCLASS_NVME,
.post_probe = nvme_uclass_post_probe,
};