1 /* 2 * Edu PCI device header. 3 * 4 * Copyright (C) 2016 Red Hat, Inc. 5 * 6 * Authors: 7 * Peter Xu <peterx@redhat.com>, 8 * 9 * This work is licensed under the terms of the GNU LGPL, version 2 or 10 * later. 11 * 12 * Edu device is a virtualized device in QEMU. Please refer to 13 * docs/specs/edu.txt in QEMU repository for EDU device manual. 14 */ 15 #ifndef __PCI_EDU_H__ 16 #define __PCI_EDU_H__ 17 18 #include "pci.h" 19 #include "asm/io.h" 20 21 #define PCI_VENDOR_ID_QEMU 0x1234 22 #define PCI_DEVICE_ID_EDU 0x11e8 23 24 /* The only bar used by EDU device */ 25 #define EDU_BAR 0 26 #define EDU_MAGIC 0xed 27 #define EDU_VERSION 0x100 28 #define EDU_DMA_BUF_SIZE (1 << 20) 29 #define EDU_INPUT_BUF_SIZE 256 30 31 #define EDU_REG_ID 0x0 32 #define EDU_REG_ALIVE 0x4 33 #define EDU_REG_FACTORIAL 0x8 34 #define EDU_REG_STATUS 0x20 35 #define EDU_REG_INTR_RAISE 0x60 36 #define EDU_REG_DMA_SRC 0x80 37 #define EDU_REG_DMA_DST 0x88 38 #define EDU_REG_DMA_COUNT 0x90 39 #define EDU_REG_DMA_CMD 0x98 40 41 #define EDU_CMD_DMA_START 0x01 42 #define EDU_CMD_DMA_FROM 0x02 43 #define EDU_CMD_DMA_TO 0x00 44 45 #define EDU_STATUS_FACTORIAL 0x1 46 #define EDU_STATUS_INT_ENABLE 0x80 47 48 #define EDU_DMA_START 0x40000 49 #define EDU_DMA_SIZE_MAX 4096 50 51 struct pci_edu_dev { 52 struct pci_dev pci_dev; 53 volatile void *reg_base; 54 }; 55 56 #define edu_reg(d, r) (volatile void *)((d)->reg_base + (r)) 57 58 static inline uint64_t edu_reg_readq(struct pci_edu_dev *dev, int reg) 59 { 60 return __raw_readq(edu_reg(dev, reg)); 61 } 62 63 static inline uint32_t edu_reg_readl(struct pci_edu_dev *dev, int reg) 64 { 65 return __raw_readl(edu_reg(dev, reg)); 66 } 67 68 static inline void edu_reg_writeq(struct pci_edu_dev *dev, int reg, 69 uint64_t val) 70 { 71 __raw_writeq(val, edu_reg(dev, reg)); 72 } 73 74 static inline void edu_reg_writel(struct pci_edu_dev *dev, int reg, 75 uint32_t val) 76 { 77 __raw_writel(val, edu_reg(dev, reg)); 78 } 79 80 bool edu_init(struct pci_edu_dev *dev); 81 void edu_dma(struct pci_edu_dev *dev, iova_t iova, 82 size_t size, unsigned int dev_offset, bool from_device); 83 84 #endif 85