codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright@ Samsung Electronics Co. LTD |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /*! |
| 18 | * \file SecBuffer.h |
| 19 | * \brief header file for SecBuffer |
| 20 | * \author Sangwoo, Park(sw5771.park@samsung.com) |
| 21 | * \date 2011/06/02 |
| 22 | * |
| 23 | * <b>Revision History: </b> |
| 24 | * - 2010/06/03 : Sangwoo, Park(sw5771.park@samsung.com) \n |
| 25 | * Initial version |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | /** |
| 30 | * @page SecBuffer |
| 31 | * |
| 32 | * @section Introduction |
| 33 | * SecBuffer is common struct for buffer |
| 34 | * |
| 35 | * @section Copyright |
| 36 | * Copyright (c) 2008-2011 Samsung Electronics Co., Ltd.All rights reserved. \n |
| 37 | * Proprietary and Confidential |
| 38 | * |
| 39 | * @image html samsung.png |
| 40 | */ |
| 41 | |
| 42 | #ifndef __SEC_BUFFER_H__ |
| 43 | #define __SEC_BUFFER_H__ |
| 44 | |
| 45 | #include <sys/types.h> |
| 46 | |
| 47 | //! Buffer information |
| 48 | struct SecBuffer |
| 49 | { |
Daniel Hillenbrand | 41e1d1a | 2013-06-15 11:14:35 +0200 | [diff] [blame] | 50 | #ifdef __cplusplus |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 51 | public: |
Daniel Hillenbrand | 41e1d1a | 2013-06-15 11:14:35 +0200 | [diff] [blame] | 52 | #endif |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 53 | //! Buffer type |
| 54 | enum BUFFER_TYPE |
| 55 | { |
| 56 | BUFFER_TYPE_BASE = 0, |
| 57 | BUFFER_TYPE_VIRT = 1, //!< virtual address |
| 58 | BUFFER_TYPE_PHYS = 1 << 1, //!< physical address |
| 59 | BUFFER_TYPE_RESERVED = 1 << 2, //!< reserved type |
| 60 | BUFFER_TYPE_MAX, |
| 61 | }; |
| 62 | |
| 63 | //! Buffer virtual address |
| 64 | union { |
| 65 | char *p; //! single address. |
| 66 | char *extP[3]; //! Y Cb Cr. |
| 67 | } virt; |
| 68 | |
| 69 | //! Buffer physical address |
| 70 | union { |
| 71 | unsigned int p; //! single address. |
| 72 | unsigned int extP[3]; //! Y Cb Cr. |
| 73 | } phys; |
| 74 | |
| 75 | //! Buffer reserved id |
| 76 | union { |
| 77 | unsigned int p; //! \n |
| 78 | unsigned int extP[3]; //! \n |
| 79 | } reserved; |
| 80 | |
| 81 | //! Buffer size |
| 82 | union { |
| 83 | unsigned int s; |
| 84 | unsigned int extS[3]; |
| 85 | } size; |
| 86 | |
Daniel Hillenbrand | 41e1d1a | 2013-06-15 11:14:35 +0200 | [diff] [blame] | 87 | #ifdef __cplusplus |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 88 | //! Constructor |
| 89 | SecBuffer() |
| 90 | { |
| 91 | for (int i = 0; i < 3; i++) { |
| 92 | virt. extP[i] = NULL; |
| 93 | phys. extP[i] = 0; |
| 94 | reserved.extP[i] = 0; |
| 95 | size. extS[i] = 0; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | //! Constructor |
| 100 | SecBuffer(const SecBuffer *other) |
| 101 | { |
| 102 | for (int i = 0; i < 3; i++) { |
| 103 | virt. extP[i] = other->virt.extP[i]; |
| 104 | phys. extP[i] = other->phys.extP[i]; |
| 105 | reserved.extP[i] = other->reserved.extP[i]; |
| 106 | size. extS[i] = other->size.extS[i]; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | //! Operator(=) override |
| 111 | SecBuffer& operator =(const SecBuffer &other) |
| 112 | { |
| 113 | for (int i = 0; i < 3; i++) { |
| 114 | virt. extP[i] = other.virt.extP[i]; |
| 115 | phys. extP[i] = other.phys.extP[i]; |
| 116 | reserved.extP[i] = other.reserved.extP[i]; |
| 117 | size. extS[i] = other.size.extS[i]; |
| 118 | } |
| 119 | return *this; |
| 120 | } |
| 121 | |
| 122 | //! Operator(==) override |
| 123 | bool operator ==(const SecBuffer &other) const |
| 124 | { |
| 125 | return ( virt. extP[0] == other.virt.extP[0] |
| 126 | && virt. extP[1] == other.virt.extP[1] |
| 127 | && virt. extP[2] == other.virt.extP[2] |
| 128 | && phys. extP[0] == other.phys.extP[0] |
| 129 | && phys. extP[1] == other.phys.extP[1] |
| 130 | && phys. extP[2] == other.phys.extP[2] |
| 131 | && reserved.extP[0] == other.reserved.extP[0] |
| 132 | && reserved.extP[1] == other.reserved.extP[1] |
| 133 | && reserved.extP[2] == other.reserved.extP[2] |
| 134 | && size. extS[0] == other.size.extS[0] |
| 135 | && size. extS[1] == other.size.extS[1] |
| 136 | && size. extS[2] == other.size.extS[2]); |
| 137 | } |
| 138 | |
| 139 | //! Operator(!=) override |
| 140 | bool operator !=(const SecBuffer &other) const |
| 141 | { |
| 142 | // use operator(==) |
| 143 | return !(*this == other); |
| 144 | } |
| 145 | |
| 146 | //! Get Buffer type |
| 147 | static int BUFFER_TYPE(SecBuffer *buf) |
| 148 | { |
| 149 | int type = BUFFER_TYPE_BASE; |
| 150 | if (buf->virt.p) |
| 151 | type |= BUFFER_TYPE_VIRT; |
| 152 | if (buf->phys.p) |
| 153 | type |= BUFFER_TYPE_PHYS; |
| 154 | if (buf->reserved.p) |
| 155 | type |= BUFFER_TYPE_RESERVED; |
| 156 | |
| 157 | return type; |
| 158 | } |
Daniel Hillenbrand | 41e1d1a | 2013-06-15 11:14:35 +0200 | [diff] [blame] | 159 | #endif |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | #endif //__SEC_BUFFER_H__ |