| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * Copyright 2019 Raspberry Pi (Trading) Ltd. All rights reserved. |
| 30 | * |
| 31 | * Based on vmcs_sm_ioctl.h Copyright Broadcom Corporation. |
| 32 | */ |
| 33 | |
| 34 | #ifndef __VC_SM_CMA_IOCTL_H |
| 35 | #define __VC_SM_CMA_IOCTL_H |
| 36 | |
| 37 | /* ---- Include Files ---------------------------------------------------- */ |
| 38 | |
| 39 | #include <linux/types.h> /* Needed for standard types */ |
| 40 | |
| 41 | #include <linux/ioctl.h> |
| 42 | |
| 43 | /* ---- Constants and Types ---------------------------------------------- */ |
| 44 | |
| 45 | #define VC_SM_CMA_RESOURCE_NAME 32 |
| 46 | #define VC_SM_CMA_RESOURCE_NAME_DEFAULT "sm-host-resource" |
| 47 | |
| 48 | /* Type define used to create unique IOCTL number */ |
| 49 | #define VC_SM_CMA_MAGIC_TYPE 'J' |
| 50 | |
| 51 | /* IOCTL commands on /dev/vc-sm-cma */ |
| 52 | enum vc_sm_cma_cmd_e { |
| 53 | VC_SM_CMA_CMD_ALLOC = 0x5A, /* Start at 0x5A arbitrarily */ |
| 54 | |
| 55 | VC_SM_CMA_CMD_IMPORT_DMABUF, |
| 56 | |
| 57 | VC_SM_CMA_CMD_CLEAN_INVALID2, |
| 58 | |
| 59 | VC_SM_CMA_CMD_LAST /* Do not delete */ |
| 60 | }; |
| 61 | |
| 62 | /* Cache type supported, conveniently matches the user space definition in |
| 63 | * user-vcsm.h. |
| 64 | */ |
| 65 | enum vc_sm_cma_cache_e { |
| 66 | VC_SM_CMA_CACHE_NONE, |
| 67 | VC_SM_CMA_CACHE_HOST, |
| 68 | VC_SM_CMA_CACHE_VC, |
| 69 | VC_SM_CMA_CACHE_BOTH, |
| 70 | }; |
| 71 | |
| 72 | /* IOCTL Data structures */ |
| 73 | struct vc_sm_cma_ioctl_alloc { |
| 74 | /* user -> kernel */ |
| 75 | __u32 size; |
| 76 | __u32 num; |
| 77 | __u32 cached; /* enum vc_sm_cma_cache_e */ |
| 78 | __u32 pad; |
| 79 | __u8 name[VC_SM_CMA_RESOURCE_NAME]; |
| 80 | |
| 81 | /* kernel -> user */ |
| 82 | __s32 handle; |
| 83 | __u32 vc_handle; |
| 84 | __u64 dma_addr; |
| 85 | }; |
| 86 | |
| 87 | struct vc_sm_cma_ioctl_import_dmabuf { |
| 88 | /* user -> kernel */ |
| 89 | __s32 dmabuf_fd; |
| 90 | __u32 cached; /* enum vc_sm_cma_cache_e */ |
| 91 | __u8 name[VC_SM_CMA_RESOURCE_NAME]; |
| 92 | |
| 93 | /* kernel -> user */ |
| 94 | __s32 handle; |
| 95 | __u32 vc_handle; |
| 96 | __u32 size; |
| 97 | __u32 pad; |
| 98 | __u64 dma_addr; |
| 99 | }; |
| 100 | |
| 101 | /* |
| 102 | * Cache functions to be set to struct vc_sm_cma_ioctl_clean_invalid2 |
| 103 | * invalidate_mode. |
| 104 | */ |
| 105 | #define VC_SM_CACHE_OP_NOP 0x00 |
| 106 | #define VC_SM_CACHE_OP_INV 0x01 |
| 107 | #define VC_SM_CACHE_OP_CLEAN 0x02 |
| 108 | #define VC_SM_CACHE_OP_FLUSH 0x03 |
| 109 | |
| 110 | struct vc_sm_cma_ioctl_clean_invalid2 { |
| 111 | __u32 op_count; |
| 112 | __u32 pad; |
| 113 | struct vc_sm_cma_ioctl_clean_invalid_block { |
| 114 | __u32 invalidate_mode; |
| 115 | __u32 block_count; |
| 116 | void * /*__user */start_address; |
| 117 | __u32 block_size; |
| 118 | __u32 inter_block_stride; |
| 119 | } s[0]; |
| 120 | }; |
| 121 | |
| 122 | /* IOCTL numbers */ |
| 123 | #define VC_SM_CMA_IOCTL_MEM_ALLOC\ |
| 124 | _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_ALLOC,\ |
| 125 | struct vc_sm_cma_ioctl_alloc) |
| 126 | |
| 127 | #define VC_SM_CMA_IOCTL_MEM_IMPORT_DMABUF\ |
| 128 | _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_IMPORT_DMABUF,\ |
| 129 | struct vc_sm_cma_ioctl_import_dmabuf) |
| 130 | |
| 131 | #define VC_SM_CMA_IOCTL_MEM_CLEAN_INVALID2\ |
| 132 | _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_CLEAN_INVALID2,\ |
| 133 | struct vc_sm_cma_ioctl_clean_invalid2) |
| 134 | |
| 135 | #endif /* __VC_SM_CMA_IOCTL_H */ |
| 136 | |