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_SMPT_H 22#define MIC_SMPT_H 23/** 24 * struct mic_smpt_ops - MIC HW specific SMPT operations. 25 * @init: Initialize hardware specific SMPT information in mic_smpt_hw_info. 26 * @set: Set the value for a particular SMPT entry. 27 */ 28struct mic_smpt_ops { 29 void (*init)(struct mic_device *mdev); 30 void (*set)(struct mic_device *mdev, dma_addr_t dma_addr, u8 index); 31}; 32 33/** 34 * struct mic_smpt - MIC SMPT entry information. 35 * @dma_addr: Base DMA address for this SMPT entry. 36 * @ref_count: Number of active mappings for this SMPT entry in bytes. 37 */ 38struct mic_smpt { 39 dma_addr_t dma_addr; 40 s64 ref_count; 41}; 42 43/** 44 * struct mic_smpt_hw_info - MIC SMPT hardware specific information. 45 * @num_reg: Number of SMPT registers. 46 * @page_shift: System memory page shift. 47 * @page_size: System memory page size. 48 * @base: System address base. 49 */ 50struct mic_smpt_hw_info { 51 u8 num_reg; 52 u8 page_shift; 53 u64 page_size; 54 u64 base; 55}; 56 57/** 58 * struct mic_smpt_info - MIC SMPT information. 59 * @entry: Array of SMPT entries. 60 * @smpt_lock: Spin lock protecting access to SMPT data structures. 61 * @info: Hardware specific SMPT information. 62 * @ref_count: Number of active SMPT mappings (for debug). 63 * @map_count: Number of SMPT mappings created (for debug). 64 * @unmap_count: Number of SMPT mappings destroyed (for debug). 65 */ 66struct mic_smpt_info { 67 struct mic_smpt *entry; 68 spinlock_t smpt_lock; 69 struct mic_smpt_hw_info info; 70 s64 ref_count; 71 s64 map_count; 72 s64 unmap_count; 73}; 74 75dma_addr_t mic_map_single(struct mic_device *mdev, void *va, size_t size); 76void mic_unmap_single(struct mic_device *mdev, 77 dma_addr_t mic_addr, size_t size); 78dma_addr_t mic_map(struct mic_device *mdev, 79 dma_addr_t dma_addr, size_t size); 80void mic_unmap(struct mic_device *mdev, dma_addr_t mic_addr, size_t size); 81dma_addr_t mic_to_dma_addr(struct mic_device *mdev, dma_addr_t mic_addr); 82 83/** 84 * mic_map_error - Check a MIC address for errors. 85 * 86 * @mdev: pointer to mic_device instance. 87 * 88 * returns Whether there was an error during mic_map..(..) APIs. 89 */ 90static inline bool mic_map_error(dma_addr_t mic_addr) 91{ 92 return !mic_addr; 93} 94 95int mic_smpt_init(struct mic_device *mdev); 96void mic_smpt_uninit(struct mic_device *mdev); 97void mic_smpt_restore(struct mic_device *mdev); 98 99#endif 100