Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 NXP Semiconductors |
| 3 | * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <errno.h> |
| 10 | #include <dm.h> |
| 11 | #include <dm/device.h> |
| 12 | #include "nvme.h" |
| 13 | |
| 14 | static int nvme_info_init(struct uclass *uc) |
| 15 | { |
| 16 | struct nvme_info *info = (struct nvme_info *)uc->priv; |
| 17 | |
| 18 | info->ns_num = 0; |
| 19 | info->ndev_num = 0; |
| 20 | INIT_LIST_HEAD(&info->dev_list); |
| 21 | nvme_info = info; |
| 22 | |
| 23 | return 0; |
| 24 | } |
| 25 | |
| 26 | static int nvme_uclass_post_probe(struct udevice *udev) |
| 27 | { |
| 28 | char name[20]; |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 29 | struct udevice *ns_udev; |
| 30 | int i, ret; |
| 31 | struct nvme_dev *ndev = dev_get_priv(udev); |
| 32 | |
| 33 | /* Create a blk device for each namespace */ |
| 34 | for (i = 0; i < ndev->nn; i++) { |
Bin Meng | d5b7ee9 | 2017-08-22 08:15:15 -0700 | [diff] [blame^] | 35 | sprintf(name, "blk#%d", nvme_info->ns_num); |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 36 | |
| 37 | /* The real blksz and size will be set by nvme_blk_probe() */ |
Bin Meng | d5b7ee9 | 2017-08-22 08:15:15 -0700 | [diff] [blame^] | 38 | ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME, |
| 39 | nvme_info->ns_num++, 512, 0, &ns_udev); |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 40 | if (ret) { |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 41 | nvme_info->ns_num--; |
| 42 | |
| 43 | return ret; |
| 44 | } |
Zhikang Zhang | 982388e | 2017-08-03 02:30:57 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | UCLASS_DRIVER(nvme) = { |
| 51 | .name = "nvme", |
| 52 | .id = UCLASS_NVME, |
| 53 | .init = nvme_info_init, |
| 54 | .post_probe = nvme_uclass_post_probe, |
| 55 | .priv_auto_alloc_size = sizeof(struct nvme_info), |
| 56 | }; |