virtio_pci_modern.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
  4. *
  5. * VirtIO PCI bus transport driver
  6. * Ported from Linux drivers/virtio/virtio_pci*.c
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <log.h>
  11. #include <virtio_types.h>
  12. #include <virtio.h>
  13. #include <virtio_ring.h>
  14. #include <dm/device.h>
  15. #include <linux/bug.h>
  16. #include <linux/compat.h>
  17. #include <linux/delay.h>
  18. #include <linux/err.h>
  19. #include <linux/io.h>
  20. #include "virtio_pci.h"
  21. #define VIRTIO_PCI_DRV_NAME "virtio-pci.m"
  22. /* PCI device ID in the range 0x1040 to 0x107f */
  23. #define VIRTIO_PCI_VENDOR_ID 0x1af4
  24. #define VIRTIO_PCI_DEVICE_ID00 0x1040
  25. #define VIRTIO_PCI_DEVICE_ID01 0x1041
  26. #define VIRTIO_PCI_DEVICE_ID02 0x1042
  27. #define VIRTIO_PCI_DEVICE_ID03 0x1043
  28. #define VIRTIO_PCI_DEVICE_ID04 0x1044
  29. #define VIRTIO_PCI_DEVICE_ID05 0x1045
  30. #define VIRTIO_PCI_DEVICE_ID06 0x1046
  31. #define VIRTIO_PCI_DEVICE_ID07 0x1047
  32. #define VIRTIO_PCI_DEVICE_ID08 0x1048
  33. #define VIRTIO_PCI_DEVICE_ID09 0x1049
  34. #define VIRTIO_PCI_DEVICE_ID0A 0x104a
  35. #define VIRTIO_PCI_DEVICE_ID0B 0x104b
  36. #define VIRTIO_PCI_DEVICE_ID0C 0x104c
  37. #define VIRTIO_PCI_DEVICE_ID0D 0x104d
  38. #define VIRTIO_PCI_DEVICE_ID0E 0x104e
  39. #define VIRTIO_PCI_DEVICE_ID0F 0x104f
  40. #define VIRTIO_PCI_DEVICE_ID10 0x1050
  41. #define VIRTIO_PCI_DEVICE_ID11 0x1051
  42. #define VIRTIO_PCI_DEVICE_ID12 0x1052
  43. #define VIRTIO_PCI_DEVICE_ID13 0x1053
  44. #define VIRTIO_PCI_DEVICE_ID14 0x1054
  45. #define VIRTIO_PCI_DEVICE_ID15 0x1055
  46. #define VIRTIO_PCI_DEVICE_ID16 0x1056
  47. #define VIRTIO_PCI_DEVICE_ID17 0x1057
  48. #define VIRTIO_PCI_DEVICE_ID18 0x1058
  49. #define VIRTIO_PCI_DEVICE_ID19 0x1059
  50. #define VIRTIO_PCI_DEVICE_ID1A 0x105a
  51. #define VIRTIO_PCI_DEVICE_ID1B 0x105b
  52. #define VIRTIO_PCI_DEVICE_ID1C 0x105c
  53. #define VIRTIO_PCI_DEVICE_ID1D 0x105d
  54. #define VIRTIO_PCI_DEVICE_ID1E 0x105e
  55. #define VIRTIO_PCI_DEVICE_ID1F 0x105f
  56. #define VIRTIO_PCI_DEVICE_ID20 0x1060
  57. #define VIRTIO_PCI_DEVICE_ID21 0x1061
  58. #define VIRTIO_PCI_DEVICE_ID22 0x1062
  59. #define VIRTIO_PCI_DEVICE_ID23 0x1063
  60. #define VIRTIO_PCI_DEVICE_ID24 0x1064
  61. #define VIRTIO_PCI_DEVICE_ID25 0x1065
  62. #define VIRTIO_PCI_DEVICE_ID26 0x1066
  63. #define VIRTIO_PCI_DEVICE_ID27 0x1067
  64. #define VIRTIO_PCI_DEVICE_ID28 0x1068
  65. #define VIRTIO_PCI_DEVICE_ID29 0x1069
  66. #define VIRTIO_PCI_DEVICE_ID2A 0x106a
  67. #define VIRTIO_PCI_DEVICE_ID2B 0x106b
  68. #define VIRTIO_PCI_DEVICE_ID2C 0x106c
  69. #define VIRTIO_PCI_DEVICE_ID2D 0x106d
  70. #define VIRTIO_PCI_DEVICE_ID2E 0x106e
  71. #define VIRTIO_PCI_DEVICE_ID2F 0x106f
  72. #define VIRTIO_PCI_DEVICE_ID30 0x1070
  73. #define VIRTIO_PCI_DEVICE_ID31 0x1071
  74. #define VIRTIO_PCI_DEVICE_ID32 0x1072
  75. #define VIRTIO_PCI_DEVICE_ID33 0x1073
  76. #define VIRTIO_PCI_DEVICE_ID34 0x1074
  77. #define VIRTIO_PCI_DEVICE_ID35 0x1075
  78. #define VIRTIO_PCI_DEVICE_ID36 0x1076
  79. #define VIRTIO_PCI_DEVICE_ID37 0x1077
  80. #define VIRTIO_PCI_DEVICE_ID38 0x1078
  81. #define VIRTIO_PCI_DEVICE_ID39 0x1079
  82. #define VIRTIO_PCI_DEVICE_ID3A 0x107a
  83. #define VIRTIO_PCI_DEVICE_ID3B 0x107b
  84. #define VIRTIO_PCI_DEVICE_ID3C 0x107c
  85. #define VIRTIO_PCI_DEVICE_ID3D 0x107d
  86. #define VIRTIO_PCI_DEVICE_ID3E 0x107e
  87. #define VIRTIO_PCI_DEVICE_ID3F 0x107f
  88. /**
  89. * virtio pci transport driver private data
  90. *
  91. * @common: pci transport device common register block base
  92. * @notify_base: pci transport device notify register block base
  93. * @notify_len: pci transport device notify register block length
  94. * @device: pci transport device device-specific register block base
  95. * @device_len: pci transport device device-specific register block length
  96. * @notify_offset_multiplier: multiply queue_notify_off by this value
  97. */
  98. struct virtio_pci_priv {
  99. struct virtio_pci_common_cfg __iomem *common;
  100. void __iomem *notify_base;
  101. u32 notify_len;
  102. void __iomem *device;
  103. u32 device_len;
  104. u32 notify_offset_multiplier;
  105. };
  106. static int virtio_pci_get_config(struct udevice *udev, unsigned int offset,
  107. void *buf, unsigned int len)
  108. {
  109. struct virtio_pci_priv *priv = dev_get_priv(udev);
  110. u8 b;
  111. __le16 w;
  112. __le32 l;
  113. if (!priv->device)
  114. return -ENOSYS;
  115. if (offset + len > priv->device_len)
  116. return -EINVAL;
  117. switch (len) {
  118. case 1:
  119. b = ioread8(priv->device + offset);
  120. memcpy(buf, &b, sizeof(b));
  121. break;
  122. case 2:
  123. w = cpu_to_le16(ioread16(priv->device + offset));
  124. memcpy(buf, &w, sizeof(w));
  125. break;
  126. case 4:
  127. l = cpu_to_le32(ioread32(priv->device + offset));
  128. memcpy(buf, &l, sizeof(l));
  129. break;
  130. case 8:
  131. l = cpu_to_le32(ioread32(priv->device + offset));
  132. memcpy(buf, &l, sizeof(l));
  133. l = cpu_to_le32(ioread32(priv->device + offset + sizeof(l)));
  134. memcpy(buf + sizeof(l), &l, sizeof(l));
  135. break;
  136. default:
  137. return -EINVAL;
  138. }
  139. return 0;
  140. }
  141. static int virtio_pci_set_config(struct udevice *udev, unsigned int offset,
  142. const void *buf, unsigned int len)
  143. {
  144. struct virtio_pci_priv *priv = dev_get_priv(udev);
  145. u8 b;
  146. __le16 w;
  147. __le32 l;
  148. if (!priv->device)
  149. return -ENOSYS;
  150. if (offset + len > priv->device_len)
  151. return -EINVAL;
  152. switch (len) {
  153. case 1:
  154. memcpy(&b, buf, sizeof(b));
  155. iowrite8(b, priv->device + offset);
  156. break;
  157. case 2:
  158. memcpy(&w, buf, sizeof(w));
  159. iowrite16(le16_to_cpu(w), priv->device + offset);
  160. break;
  161. case 4:
  162. memcpy(&l, buf, sizeof(l));
  163. iowrite32(le32_to_cpu(l), priv->device + offset);
  164. break;
  165. case 8:
  166. memcpy(&l, buf, sizeof(l));
  167. iowrite32(le32_to_cpu(l), priv->device + offset);
  168. memcpy(&l, buf + sizeof(l), sizeof(l));
  169. iowrite32(le32_to_cpu(l), priv->device + offset + sizeof(l));
  170. break;
  171. default:
  172. return -EINVAL;
  173. }
  174. return 0;
  175. }
  176. static int virtio_pci_generation(struct udevice *udev, u32 *counter)
  177. {
  178. struct virtio_pci_priv *priv = dev_get_priv(udev);
  179. *counter = ioread8(&priv->common->config_generation);
  180. return 0;
  181. }
  182. static int virtio_pci_get_status(struct udevice *udev, u8 *status)
  183. {
  184. struct virtio_pci_priv *priv = dev_get_priv(udev);
  185. *status = ioread8(&priv->common->device_status);
  186. return 0;
  187. }
  188. static int virtio_pci_set_status(struct udevice *udev, u8 status)
  189. {
  190. struct virtio_pci_priv *priv = dev_get_priv(udev);
  191. /* We should never be setting status to 0 */
  192. WARN_ON(status == 0);
  193. iowrite8(status, &priv->common->device_status);
  194. return 0;
  195. }
  196. static int virtio_pci_get_features(struct udevice *udev, u64 *features)
  197. {
  198. struct virtio_pci_priv *priv = dev_get_priv(udev);
  199. iowrite32(0, &priv->common->device_feature_select);
  200. *features = ioread32(&priv->common->device_feature);
  201. iowrite32(1, &priv->common->device_feature_select);
  202. *features |= ((u64)ioread32(&priv->common->device_feature) << 32);
  203. return 0;
  204. }
  205. static int virtio_pci_set_features(struct udevice *udev)
  206. {
  207. struct virtio_pci_priv *priv = dev_get_priv(udev);
  208. struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
  209. if (!__virtio_test_bit(udev, VIRTIO_F_VERSION_1)) {
  210. debug("virtio: device uses modern interface but does not have VIRTIO_F_VERSION_1\n");
  211. return -EINVAL;
  212. }
  213. iowrite32(0, &priv->common->guest_feature_select);
  214. iowrite32((u32)uc_priv->features, &priv->common->guest_feature);
  215. iowrite32(1, &priv->common->guest_feature_select);
  216. iowrite32(uc_priv->features >> 32, &priv->common->guest_feature);
  217. return 0;
  218. }
  219. static struct virtqueue *virtio_pci_setup_vq(struct udevice *udev,
  220. unsigned int index)
  221. {
  222. struct virtio_pci_priv *priv = dev_get_priv(udev);
  223. struct virtio_pci_common_cfg __iomem *cfg = priv->common;
  224. struct virtqueue *vq;
  225. u16 num;
  226. u64 addr;
  227. int err;
  228. if (index >= ioread16(&cfg->num_queues))
  229. return ERR_PTR(-ENOENT);
  230. /* Select the queue we're interested in */
  231. iowrite16(index, &cfg->queue_select);
  232. /* Check if queue is either not available or already active */
  233. num = ioread16(&cfg->queue_size);
  234. if (!num || ioread16(&cfg->queue_enable))
  235. return ERR_PTR(-ENOENT);
  236. if (num & (num - 1)) {
  237. printf("(%s): bad queue size %u", udev->name, num);
  238. return ERR_PTR(-EINVAL);
  239. }
  240. /* Create the vring */
  241. vq = vring_create_virtqueue(index, num, VIRTIO_PCI_VRING_ALIGN, udev);
  242. if (!vq) {
  243. err = -ENOMEM;
  244. goto error_available;
  245. }
  246. /* Activate the queue */
  247. iowrite16(virtqueue_get_vring_size(vq), &cfg->queue_size);
  248. addr = virtqueue_get_desc_addr(vq);
  249. iowrite32((u32)addr, &cfg->queue_desc_lo);
  250. iowrite32(addr >> 32, &cfg->queue_desc_hi);
  251. addr = virtqueue_get_avail_addr(vq);
  252. iowrite32((u32)addr, &cfg->queue_avail_lo);
  253. iowrite32(addr >> 32, &cfg->queue_avail_hi);
  254. addr = virtqueue_get_used_addr(vq);
  255. iowrite32((u32)addr, &cfg->queue_used_lo);
  256. iowrite32(addr >> 32, &cfg->queue_used_hi);
  257. iowrite16(1, &cfg->queue_enable);
  258. return vq;
  259. error_available:
  260. return ERR_PTR(err);
  261. }
  262. static void virtio_pci_del_vq(struct virtqueue *vq)
  263. {
  264. struct virtio_pci_priv *priv = dev_get_priv(vq->vdev);
  265. unsigned int index = vq->index;
  266. iowrite16(index, &priv->common->queue_select);
  267. /* Select and deactivate the queue */
  268. iowrite16(0, &priv->common->queue_enable);
  269. vring_del_virtqueue(vq);
  270. }
  271. static int virtio_pci_del_vqs(struct udevice *udev)
  272. {
  273. struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
  274. struct virtqueue *vq, *n;
  275. list_for_each_entry_safe(vq, n, &uc_priv->vqs, list)
  276. virtio_pci_del_vq(vq);
  277. return 0;
  278. }
  279. static int virtio_pci_find_vqs(struct udevice *udev, unsigned int nvqs,
  280. struct virtqueue *vqs[])
  281. {
  282. int i;
  283. for (i = 0; i < nvqs; ++i) {
  284. vqs[i] = virtio_pci_setup_vq(udev, i);
  285. if (IS_ERR(vqs[i])) {
  286. virtio_pci_del_vqs(udev);
  287. return PTR_ERR(vqs[i]);
  288. }
  289. }
  290. return 0;
  291. }
  292. static int virtio_pci_reset(struct udevice *udev)
  293. {
  294. struct virtio_pci_priv *priv = dev_get_priv(udev);
  295. /* 0 status means a reset */
  296. iowrite8(0, &priv->common->device_status);
  297. /*
  298. * After writing 0 to device_status, the driver MUST wait for a read
  299. * of device_status to return 0 before reinitializing the device.
  300. * This will flush out the status write, and flush in device writes,
  301. * including MSI-X interrupts, if any.
  302. */
  303. while (ioread8(&priv->common->device_status))
  304. udelay(1000);
  305. return virtio_pci_del_vqs(udev);
  306. }
  307. static int virtio_pci_notify(struct udevice *udev, struct virtqueue *vq)
  308. {
  309. struct virtio_pci_priv *priv = dev_get_priv(udev);
  310. u16 off;
  311. /* Select the queue we're interested in */
  312. iowrite16(vq->index, &priv->common->queue_select);
  313. /* get offset of notification word for this vq */
  314. off = ioread16(&priv->common->queue_notify_off);
  315. /*
  316. * Check the effective offset is in bounds and leaves space for the
  317. * notification, which is just a single 16-bit value since
  318. * VIRTIO_F_NOTIFICATION_DATA isn't negotiated by the drivers.
  319. */
  320. off *= priv->notify_offset_multiplier;
  321. if (off > priv->notify_len - sizeof(u16))
  322. return -EIO;
  323. /*
  324. * We write the queue's selector into the notification register
  325. * to signal the other end
  326. */
  327. iowrite16(vq->index, priv->notify_base + off);
  328. return 0;
  329. }
  330. /**
  331. * virtio_pci_find_capability - walk capabilities to find device info
  332. *
  333. * @udev: the transport device
  334. * @cfg_type: the VIRTIO_PCI_CAP_* value we seek
  335. * @cap_size: expected size of the capability
  336. * @cap: capability read from the config space
  337. *
  338. * Return: offset of the configuration structure
  339. */
  340. static int virtio_pci_find_capability(struct udevice *udev, u8 cfg_type,
  341. size_t cap_size,
  342. struct virtio_pci_cap *cap)
  343. {
  344. int pos;
  345. int offset;
  346. assert(cap_size >= sizeof(struct virtio_pci_cap));
  347. assert(cap_size <= PCI_CFG_SPACE_SIZE);
  348. if (!cap)
  349. return 0;
  350. for (pos = dm_pci_find_capability(udev, PCI_CAP_ID_VNDR);
  351. pos > 0;
  352. pos = dm_pci_find_next_capability(udev, pos, PCI_CAP_ID_VNDR)) {
  353. /* Ensure the capability is within bounds */
  354. if (PCI_CFG_SPACE_SIZE - cap_size < pos)
  355. return 0;
  356. offset = pos + offsetof(struct virtio_pci_cap, cap_vndr);
  357. dm_pci_read_config8(udev, offset, &cap->cap_vndr);
  358. offset = pos + offsetof(struct virtio_pci_cap, cap_next);
  359. dm_pci_read_config8(udev, offset, &cap->cap_next);
  360. offset = pos + offsetof(struct virtio_pci_cap, cap_len);
  361. dm_pci_read_config8(udev, offset, &cap->cap_len);
  362. offset = pos + offsetof(struct virtio_pci_cap, cfg_type);
  363. dm_pci_read_config8(udev, offset, &cap->cfg_type);
  364. offset = pos + offsetof(struct virtio_pci_cap, bar);
  365. dm_pci_read_config8(udev, offset, &cap->bar);
  366. offset = pos + offsetof(struct virtio_pci_cap, offset);
  367. dm_pci_read_config32(udev, offset, &cap->offset);
  368. offset = pos + offsetof(struct virtio_pci_cap, length);
  369. dm_pci_read_config32(udev, offset, &cap->length);
  370. /* Ignore structures with reserved BAR values */
  371. if (cap->bar > 0x5)
  372. continue;
  373. if (cap->cfg_type == cfg_type)
  374. return pos;
  375. }
  376. return 0;
  377. }
  378. /**
  379. * virtio_pci_map_capability - map base address of the capability
  380. *
  381. * @udev: the transport device
  382. * @cap: capability to map
  383. *
  384. * Return: base address of the capability
  385. */
  386. static void __iomem *virtio_pci_map_capability(struct udevice *udev,
  387. const struct virtio_pci_cap *cap)
  388. {
  389. /*
  390. * Find the corresponding memory region that isn't system memory but is
  391. * writable.
  392. */
  393. unsigned long mask =
  394. PCI_REGION_TYPE | PCI_REGION_SYS_MEMORY | PCI_REGION_RO;
  395. unsigned long flags = PCI_REGION_MEM;
  396. u8 *p = dm_pci_map_bar(udev, PCI_BASE_ADDRESS_0 + 4 * cap->bar, cap->offset,
  397. cap->length, mask, flags);
  398. return (void __iomem *)p;
  399. }
  400. static int virtio_pci_bind(struct udevice *udev)
  401. {
  402. static int num_devs;
  403. char name[20];
  404. /* Create a unique device name */
  405. sprintf(name, "%s#%u", VIRTIO_PCI_DRV_NAME, num_devs++);
  406. device_set_name(udev, name);
  407. return 0;
  408. }
  409. static int virtio_pci_probe(struct udevice *udev)
  410. {
  411. struct pci_child_plat *pplat = dev_get_parent_plat(udev);
  412. struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
  413. struct virtio_pci_priv *priv = dev_get_priv(udev);
  414. u16 subvendor;
  415. u8 revision;
  416. int common, notify, device;
  417. struct virtio_pci_cap common_cap, notify_cap, device_cap;
  418. int offset;
  419. /* We only own devices >= 0x1040 and <= 0x107f: leave the rest. */
  420. if (pplat->device < 0x1040 || pplat->device > 0x107f)
  421. return -ENODEV;
  422. /* Transitional devices must not have a PCI revision ID of 0 */
  423. dm_pci_read_config8(udev, PCI_REVISION_ID, &revision);
  424. /* Modern devices: simply use PCI device id, but start from 0x1040. */
  425. uc_priv->device = pplat->device - 0x1040;
  426. dm_pci_read_config16(udev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor);
  427. uc_priv->vendor = subvendor;
  428. /* Check for a common config: if not, use legacy mode (bar 0) */
  429. common = virtio_pci_find_capability(udev, VIRTIO_PCI_CAP_COMMON_CFG,
  430. sizeof(struct virtio_pci_cap),
  431. &common_cap);
  432. if (!common) {
  433. printf("(%s): leaving for legacy driver\n", udev->name);
  434. return -ENODEV;
  435. }
  436. if (common_cap.length < sizeof(struct virtio_pci_common_cfg)) {
  437. printf("(%s): virtio common config too small\n", udev->name);
  438. return -EINVAL;
  439. }
  440. /* If common is there, notify should be too */
  441. notify = virtio_pci_find_capability(udev, VIRTIO_PCI_CAP_NOTIFY_CFG,
  442. sizeof(struct virtio_pci_notify_cap),
  443. &notify_cap);
  444. if (!notify) {
  445. printf("(%s): missing capabilities %i/%i\n", udev->name,
  446. common, notify);
  447. return -EINVAL;
  448. }
  449. /* Map configuration structures */
  450. priv->common = virtio_pci_map_capability(udev, &common_cap);
  451. if (!priv->common) {
  452. printf("(%s): could not map common config\n", udev->name);
  453. return -EINVAL;
  454. }
  455. priv->notify_len = notify_cap.length;
  456. priv->notify_base = virtio_pci_map_capability(udev, &notify_cap);
  457. if (!priv->notify_base) {
  458. printf("(%s): could not map notify config\n", udev->name);
  459. return -EINVAL;
  460. }
  461. /*
  462. * Device capability is only mandatory for devices that have
  463. * device-specific configuration.
  464. */
  465. device = virtio_pci_find_capability(udev, VIRTIO_PCI_CAP_DEVICE_CFG,
  466. sizeof(struct virtio_pci_cap),
  467. &device_cap);
  468. if (device) {
  469. priv->device_len = device_cap.length;
  470. priv->device = virtio_pci_map_capability(udev, &device_cap);
  471. if (!priv->device) {
  472. printf("(%s): could not map device config\n",
  473. udev->name);
  474. return -EINVAL;
  475. }
  476. }
  477. debug("(%p): common @ %p, notify base @ %p, device @ %p\n",
  478. udev, priv->common, priv->notify_base, priv->device);
  479. /* Read notify_off_multiplier from config space */
  480. offset = notify + offsetof(struct virtio_pci_notify_cap,
  481. notify_off_multiplier);
  482. dm_pci_read_config32(udev, offset, &priv->notify_offset_multiplier);
  483. debug("(%s): device (%d) vendor (%08x) version (%d)\n", udev->name,
  484. uc_priv->device, uc_priv->vendor, revision);
  485. return 0;
  486. }
  487. static const struct dm_virtio_ops virtio_pci_ops = {
  488. .get_config = virtio_pci_get_config,
  489. .set_config = virtio_pci_set_config,
  490. .generation = virtio_pci_generation,
  491. .get_status = virtio_pci_get_status,
  492. .set_status = virtio_pci_set_status,
  493. .reset = virtio_pci_reset,
  494. .get_features = virtio_pci_get_features,
  495. .set_features = virtio_pci_set_features,
  496. .find_vqs = virtio_pci_find_vqs,
  497. .del_vqs = virtio_pci_del_vqs,
  498. .notify = virtio_pci_notify,
  499. };
  500. U_BOOT_DRIVER(virtio_pci_modern) = {
  501. .name = VIRTIO_PCI_DRV_NAME,
  502. .id = UCLASS_VIRTIO,
  503. .ops = &virtio_pci_ops,
  504. .bind = virtio_pci_bind,
  505. .probe = virtio_pci_probe,
  506. .priv_auto = sizeof(struct virtio_pci_priv),
  507. };
  508. static struct pci_device_id virtio_pci_supported[] = {
  509. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID00) },
  510. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID01) },
  511. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID02) },
  512. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID03) },
  513. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID04) },
  514. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID05) },
  515. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID06) },
  516. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID07) },
  517. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID08) },
  518. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID09) },
  519. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID0A) },
  520. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID0B) },
  521. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID0C) },
  522. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID0D) },
  523. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID0E) },
  524. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID0F) },
  525. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID10) },
  526. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID11) },
  527. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID12) },
  528. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID13) },
  529. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID14) },
  530. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID15) },
  531. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID16) },
  532. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID17) },
  533. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID18) },
  534. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID19) },
  535. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID1A) },
  536. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID1B) },
  537. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID1C) },
  538. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID1D) },
  539. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID1E) },
  540. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID1F) },
  541. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID20) },
  542. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID21) },
  543. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID22) },
  544. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID23) },
  545. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID24) },
  546. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID25) },
  547. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID26) },
  548. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID27) },
  549. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID28) },
  550. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID29) },
  551. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID2A) },
  552. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID2B) },
  553. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID2C) },
  554. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID2D) },
  555. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID2E) },
  556. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID2F) },
  557. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID30) },
  558. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID31) },
  559. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID32) },
  560. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID33) },
  561. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID34) },
  562. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID35) },
  563. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID36) },
  564. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID37) },
  565. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID38) },
  566. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID39) },
  567. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID3A) },
  568. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID3B) },
  569. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID3C) },
  570. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID3D) },
  571. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID3E) },
  572. { PCI_DEVICE(VIRTIO_PCI_VENDOR_ID, VIRTIO_PCI_DEVICE_ID3F) },
  573. {},
  574. };
  575. U_BOOT_PCI_DEVICE(virtio_pci_modern, virtio_pci_supported);