blob: 36eb056c213e1c3bf3672a926bf0a445efc7ef18 [file] [log] [blame]
Abdellatif El Khlifi857360c2023-04-17 10:11:52 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
4 *
5 * Authors:
6 * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
7 */
8
9#include <common.h>
10#include <dm.h>
11#include <log.h>
Abdellatif El Khlifi6b005872023-04-17 10:11:55 +010012#if CONFIG_IS_ENABLED(SANDBOX64)
13#include <asm/test.h>
14#endif
Abdellatif El Khlifi857360c2023-04-17 10:11:52 +010015#include <linux/bitops.h>
16#include "nvmxip.h"
17
18/* LBA Macros */
19
20#define DEFAULT_LBA_SHIFT 10 /* 1024 bytes per block */
21#define DEFAULT_LBA_COUNT 1024 /* block count */
22
23#define DEFAULT_LBA_SZ BIT(DEFAULT_LBA_SHIFT)
24
Marek Vasutaec5dc72023-08-23 02:18:17 +020025int nvmxip_probe(struct udevice *udev)
Abdellatif El Khlifi857360c2023-04-17 10:11:52 +010026{
27 int ret;
28 struct udevice *bdev = NULL;
29 char bdev_name[NVMXIP_BLKDEV_NAME_SZ + 1];
30 int devnum;
31
Abdellatif El Khlifi6b005872023-04-17 10:11:55 +010032#if CONFIG_IS_ENABLED(SANDBOX64)
33 sandbox_set_enable_memio(true);
34#endif
35
Abdellatif El Khlifi857360c2023-04-17 10:11:52 +010036 devnum = uclass_id_count(UCLASS_NVMXIP);
37 snprintf(bdev_name, NVMXIP_BLKDEV_NAME_SZ, "blk#%d", devnum);
38
39 ret = blk_create_devicef(udev, NVMXIP_BLKDRV_NAME, bdev_name, UCLASS_NVMXIP,
40 devnum, DEFAULT_LBA_SZ,
41 DEFAULT_LBA_COUNT, &bdev);
42 if (ret) {
43 log_err("[%s]: failure during creation of the block device %s, error %d\n",
44 udev->name, bdev_name, ret);
45 return ret;
46 }
47
48 ret = blk_probe_or_unbind(bdev);
49 if (ret) {
50 log_err("[%s]: failure during probing the block device %s, error %d\n",
51 udev->name, bdev_name, ret);
52 return ret;
53 }
54
55 log_info("[%s]: the block device %s ready for use\n", udev->name, bdev_name);
56
Marek Vasutaec5dc72023-08-23 02:18:17 +020057 return 0;
58}
59
60static int nvmxip_post_bind(struct udevice *udev)
61{
62 dev_or_flags(udev, DM_FLAG_PROBE_AFTER_BIND);
Abdellatif El Khlifi857360c2023-04-17 10:11:52 +010063 return 0;
64}
65
66UCLASS_DRIVER(nvmxip) = {
67 .name = "nvmxip",
68 .id = UCLASS_NVMXIP,
69 .post_bind = nvmxip_post_bind,
70};