| 1 | /* |
| 2 | * Copyright 2010-2017 Intel Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License, version 2, |
| 6 | * as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * Disclaimer: The codes contained in these modules may be specific to |
| 14 | * the Intel Software Development Platform codenamed Knights Ferry, |
| 15 | * and the Intel product codenamed Knights Corner, and are not backward |
| 16 | * compatible with other Intel products. Additionally, Intel will NOT |
| 17 | * support the codes or instruction set in future products. |
| 18 | * |
| 19 | * Intel offers no warranty of any kind regarding the code. This code is |
| 20 | * licensed on an "AS IS" basis and Intel is not obligated to provide |
| 21 | * any support, assistance, installation, training, or other services |
| 22 | * of any kind. Intel is also not obligated to provide any updates, |
| 23 | * enhancements or extensions. Intel specifically disclaims any warranty |
| 24 | * of merchantability, non-infringement, fitness for any particular |
| 25 | * purpose, and any other warranty. |
| 26 | * |
| 27 | * Further, Intel disclaims all liability of any kind, including but |
| 28 | * not limited to liability for infringement of any proprietary rights, |
| 29 | * relating to the use of the code, even if Intel is notified of the |
| 30 | * possibility of such liability. Except as expressly stated in an Intel |
| 31 | * license agreement provided with this code and agreed upon with Intel, |
| 32 | * no license, express or implied, by estoppel or otherwise, to any |
| 33 | * intellectual property rights is granted herein. |
| 34 | */ |
| 35 | |
| 36 | #ifndef MIC_SMPT_H |
| 37 | #define MIC_SMPT_H |
| 38 | |
| 39 | #include <linux/errno.h> |
| 40 | #include <linux/hardirq.h> |
| 41 | #include <linux/types.h> |
| 42 | #include <linux/capability.h> |
| 43 | #include <linux/slab.h> |
| 44 | #include <linux/string.h> |
| 45 | #include <linux/gfp.h> |
| 46 | #include <linux/vmalloc.h> |
| 47 | #include <asm/io.h> |
| 48 | #include <linux/kernel.h> |
| 49 | #include <linux/mm_types.h> |
| 50 | #include <linux/jiffies.h> |
| 51 | #include <linux/timer.h> |
| 52 | #include <linux/irqflags.h> |
| 53 | #include <linux/time.h> |
| 54 | #include <linux/spinlock.h> |
| 55 | #include <linux/mutex.h> |
| 56 | #include <linux/semaphore.h> |
| 57 | #include <linux/kthread.h> |
| 58 | #include <linux/sched.h> |
| 59 | #include <linux/delay.h> |
| 60 | #include <linux/wait.h> |
| 61 | #include <asm/bug.h> |
| 62 | #include <linux/pci.h> |
| 63 | #include <linux/device.h> |
| 64 | #include <linux/fs.h> |
| 65 | #include <linux/list.h> |
| 66 | #include <linux/workqueue.h> |
| 67 | #include <linux/interrupt.h> |
| 68 | #include <asm/atomic.h> |
| 69 | #include <linux/netdevice.h> |
| 70 | #include <linux/debugfs.h> |
| 71 | |
| 72 | #define MAX_BOARD_SUPPORTED 256 |
| 73 | |
| 74 | #define SNOOP_ON (0 << 0) |
| 75 | #define SNOOP_OFF (1 << 0) |
| 76 | #define NUM_SMPT_REGISTERS 32 |
| 77 | #define NUM_SMPT_ENTRIES_IN_USE 32 |
| 78 | #define SMPT_MASK 0x1F |
| 79 | #define MIC_SYSTEM_PAGE_SHIFT 34ULL |
| 80 | #define MIC_SYSTEM_PAGE_MASK ((1ULL << MIC_SYSTEM_PAGE_SHIFT) - 1ULL) |
| 81 | |
| 82 | struct _mic_ctx_t; |
| 83 | struct pci_dev; |
| 84 | |
| 85 | typedef struct mic_smpt { |
| 86 | dma_addr_t dma_addr; |
| 87 | int64_t ref_count; |
| 88 | } mic_smpt_t; |
| 89 | |
| 90 | |
| 91 | /* Sbox Smpt Reg Bits: |
| 92 | * Bits 31:2 Host address |
| 93 | * Bits 1 RSVD |
| 94 | * Bits 0 No snoop |
| 95 | */ |
| 96 | #define BUILD_SMPT(NO_SNOOP, HOST_ADDR) \ |
| 97 | (uint32_t)(((((HOST_ADDR)<< 2) & (~0x03)) | ((NO_SNOOP) & (0x01)))) |
| 98 | |
| 99 | bool is_syspa(dma_addr_t hostmic_pa); |
| 100 | |
| 101 | dma_addr_t mic_map(int bid, dma_addr_t dma_addr, size_t size); |
| 102 | void mic_unmap(int bid, dma_addr_t dma_addr, size_t size); |
| 103 | |
| 104 | dma_addr_t mic_map_single(int bid, struct pci_dev *hwdev, void *p, size_t size); |
| 105 | void mic_unmap_single(int bid, struct pci_dev *hwdev, dma_addr_t mic_addr, |
| 106 | size_t size); |
| 107 | |
| 108 | dma_addr_t mic_ctx_map_single(struct _mic_ctx_t *mic_ctx, void *p, size_t size); |
| 109 | void mic_ctx_unmap_single(struct _mic_ctx_t *mic_ctx, dma_addr_t dma_addr, |
| 110 | size_t size); |
| 111 | |
| 112 | dma_addr_t mic_to_dma_addr(int bid, dma_addr_t mic_addr); |
| 113 | void mic_smpt_set(volatile void *mm_sbox, uint64_t dma_addr, uint64_t index); |
| 114 | |
| 115 | static inline |
| 116 | bool mic_map_error(dma_addr_t mic_addr) |
| 117 | { |
| 118 | return !mic_addr; |
| 119 | } |
| 120 | #endif // MIC_SMPT_H |