Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v4.2-rc7 236 lines 7.7 kB view raw
1/* 2 * Intel MIC Platform Software Stack (MPSS) 3 * 4 * Copyright(c) 2013 Intel Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License, version 2, as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * The full GNU General Public License is included in this distribution in 16 * the file called "COPYING". 17 * 18 * Intel MIC Host driver. 19 * 20 */ 21#ifndef _MIC_DEVICE_H_ 22#define _MIC_DEVICE_H_ 23 24#include <linux/cdev.h> 25#include <linux/idr.h> 26#include <linux/notifier.h> 27#include <linux/irqreturn.h> 28#include <linux/dmaengine.h> 29#include <linux/mic_bus.h> 30#include "../bus/scif_bus.h" 31#include "mic_intr.h" 32 33/* The maximum number of MIC devices supported in a single host system. */ 34#define MIC_MAX_NUM_DEVS 256 35 36/** 37 * enum mic_hw_family - The hardware family to which a device belongs. 38 */ 39enum mic_hw_family { 40 MIC_FAMILY_X100 = 0, 41 MIC_FAMILY_UNKNOWN 42}; 43 44/** 45 * enum mic_stepping - MIC stepping ids. 46 */ 47enum mic_stepping { 48 MIC_A0_STEP = 0x0, 49 MIC_B0_STEP = 0x10, 50 MIC_B1_STEP = 0x11, 51 MIC_C0_STEP = 0x20, 52}; 53 54/** 55 * struct mic_device - MIC device information for each card. 56 * 57 * @mmio: MMIO bar information. 58 * @aper: Aperture bar information. 59 * @family: The MIC family to which this device belongs. 60 * @ops: MIC HW specific operations. 61 * @id: The unique device id for this MIC device. 62 * @stepping: Stepping ID. 63 * @attr_group: Pointer to list of sysfs attribute groups. 64 * @sdev: Device for sysfs entries. 65 * @mic_mutex: Mutex for synchronizing access to mic_device. 66 * @intr_ops: HW specific interrupt operations. 67 * @smpt_ops: Hardware specific SMPT operations. 68 * @smpt: MIC SMPT information. 69 * @intr_info: H/W specific interrupt information. 70 * @irq_info: The OS specific irq information 71 * @dbg_dir: debugfs directory of this MIC device. 72 * @cmdline: Kernel command line. 73 * @firmware: Firmware file name. 74 * @ramdisk: Ramdisk file name. 75 * @bootmode: Boot mode i.e. "linux" or "elf" for flash updates. 76 * @bootaddr: MIC boot address. 77 * @reset_trigger_work: Work for triggering reset requests. 78 * @shutdown_work: Work for handling shutdown interrupts. 79 * @state: MIC state. 80 * @shutdown_status: MIC status reported by card for shutdown/crashes. 81 * @state_sysfs: Sysfs dirent for notifying ring 3 about MIC state changes. 82 * @reset_wait: Waitqueue for sleeping while reset completes. 83 * @log_buf_addr: Log buffer address for MIC. 84 * @log_buf_len: Log buffer length address for MIC. 85 * @dp: virtio device page 86 * @dp_dma_addr: virtio device page DMA address. 87 * @shutdown_db: shutdown doorbell. 88 * @shutdown_cookie: shutdown cookie. 89 * @cdev: Character device for MIC. 90 * @vdev_list: list of virtio devices. 91 * @pm_notifier: Handles PM notifications from the OS. 92 * @dma_mbdev: MIC BUS DMA device. 93 * @dma_ch - Array of DMA channels 94 * @num_dma_ch - Number of DMA channels available 95 * @scdev: SCIF device on the SCIF virtual bus. 96 */ 97struct mic_device { 98 struct mic_mw mmio; 99 struct mic_mw aper; 100 enum mic_hw_family family; 101 struct mic_hw_ops *ops; 102 int id; 103 enum mic_stepping stepping; 104 const struct attribute_group **attr_group; 105 struct device *sdev; 106 struct mutex mic_mutex; 107 struct mic_hw_intr_ops *intr_ops; 108 struct mic_smpt_ops *smpt_ops; 109 struct mic_smpt_info *smpt; 110 struct mic_intr_info *intr_info; 111 struct mic_irq_info irq_info; 112 struct dentry *dbg_dir; 113 char *cmdline; 114 char *firmware; 115 char *ramdisk; 116 char *bootmode; 117 u32 bootaddr; 118 struct work_struct reset_trigger_work; 119 struct work_struct shutdown_work; 120 u8 state; 121 u8 shutdown_status; 122 struct kernfs_node *state_sysfs; 123 struct completion reset_wait; 124 void *log_buf_addr; 125 int *log_buf_len; 126 void *dp; 127 dma_addr_t dp_dma_addr; 128 int shutdown_db; 129 struct mic_irq *shutdown_cookie; 130 struct cdev cdev; 131 struct list_head vdev_list; 132 struct notifier_block pm_notifier; 133 struct mbus_device *dma_mbdev; 134 struct dma_chan *dma_ch[MIC_MAX_DMA_CHAN]; 135 int num_dma_ch; 136 struct scif_hw_dev *scdev; 137}; 138 139/** 140 * struct mic_hw_ops - MIC HW specific operations. 141 * @aper_bar: Aperture bar resource number. 142 * @mmio_bar: MMIO bar resource number. 143 * @read_spad: Read from scratch pad register. 144 * @write_spad: Write to scratch pad register. 145 * @send_intr: Send an interrupt for a particular doorbell on the card. 146 * @ack_interrupt: Hardware specific operations to ack the h/w on 147 * receipt of an interrupt. 148 * @intr_workarounds: Hardware specific workarounds needed after 149 * handling an interrupt. 150 * @reset: Reset the remote processor. 151 * @reset_fw_ready: Reset firmware ready field. 152 * @is_fw_ready: Check if firmware is ready for OS download. 153 * @send_firmware_intr: Send an interrupt to the card firmware. 154 * @load_mic_fw: Load firmware segments required to boot the card 155 * into card memory. This includes the kernel, command line, ramdisk etc. 156 * @get_postcode: Get post code status from firmware. 157 * @dma_filter: DMA filter function to be used. 158 */ 159struct mic_hw_ops { 160 u8 aper_bar; 161 u8 mmio_bar; 162 u32 (*read_spad)(struct mic_device *mdev, unsigned int idx); 163 void (*write_spad)(struct mic_device *mdev, unsigned int idx, u32 val); 164 void (*send_intr)(struct mic_device *mdev, int doorbell); 165 u32 (*ack_interrupt)(struct mic_device *mdev); 166 void (*intr_workarounds)(struct mic_device *mdev); 167 void (*reset)(struct mic_device *mdev); 168 void (*reset_fw_ready)(struct mic_device *mdev); 169 bool (*is_fw_ready)(struct mic_device *mdev); 170 void (*send_firmware_intr)(struct mic_device *mdev); 171 int (*load_mic_fw)(struct mic_device *mdev, const char *buf); 172 u32 (*get_postcode)(struct mic_device *mdev); 173 bool (*dma_filter)(struct dma_chan *chan, void *param); 174}; 175 176/** 177 * mic_mmio_read - read from an MMIO register. 178 * @mw: MMIO register base virtual address. 179 * @offset: register offset. 180 * 181 * RETURNS: register value. 182 */ 183static inline u32 mic_mmio_read(struct mic_mw *mw, u32 offset) 184{ 185 return ioread32(mw->va + offset); 186} 187 188/** 189 * mic_mmio_write - write to an MMIO register. 190 * @mw: MMIO register base virtual address. 191 * @val: the data value to put into the register 192 * @offset: register offset. 193 * 194 * RETURNS: none. 195 */ 196static inline void 197mic_mmio_write(struct mic_mw *mw, u32 val, u32 offset) 198{ 199 iowrite32(val, mw->va + offset); 200} 201 202static inline struct dma_chan *mic_request_dma_chan(struct mic_device *mdev) 203{ 204 dma_cap_mask_t mask; 205 struct dma_chan *chan; 206 207 dma_cap_zero(mask); 208 dma_cap_set(DMA_MEMCPY, mask); 209 chan = dma_request_channel(mask, mdev->ops->dma_filter, 210 mdev->sdev->parent); 211 if (chan) 212 return chan; 213 dev_err(mdev->sdev->parent, "%s %d unable to acquire channel\n", 214 __func__, __LINE__); 215 return NULL; 216} 217 218void mic_sysfs_init(struct mic_device *mdev); 219int mic_start(struct mic_device *mdev, const char *buf); 220void mic_stop(struct mic_device *mdev, bool force); 221void mic_shutdown(struct mic_device *mdev); 222void mic_reset_delayed_work(struct work_struct *work); 223void mic_reset_trigger_work(struct work_struct *work); 224void mic_shutdown_work(struct work_struct *work); 225void mic_bootparam_init(struct mic_device *mdev); 226void mic_set_state(struct mic_device *mdev, u8 state); 227void mic_set_shutdown_status(struct mic_device *mdev, u8 status); 228void mic_create_debug_dir(struct mic_device *dev); 229void mic_delete_debug_dir(struct mic_device *dev); 230void __init mic_init_debugfs(void); 231void mic_exit_debugfs(void); 232void mic_prepare_suspend(struct mic_device *mdev); 233void mic_complete_resume(struct mic_device *mdev); 234void mic_suspend(struct mic_device *mdev); 235extern atomic_t g_num_mics; 236#endif