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 | { |
| 50 | public: |
| 51 | //! Buffer type |
| 52 | enum BUFFER_TYPE |
| 53 | { |
| 54 | BUFFER_TYPE_BASE = 0, |
| 55 | BUFFER_TYPE_VIRT = 1, //!< virtual address |
| 56 | BUFFER_TYPE_PHYS = 1 << 1, //!< physical address |
| 57 | BUFFER_TYPE_RESERVED = 1 << 2, //!< reserved type |
| 58 | BUFFER_TYPE_MAX, |
| 59 | }; |
| 60 | |
| 61 | //! Buffer virtual address |
| 62 | union { |
| 63 | char *p; //! single address. |
| 64 | char *extP[3]; //! Y Cb Cr. |
| 65 | } virt; |
| 66 | |
| 67 | //! Buffer physical address |
| 68 | union { |
| 69 | unsigned int p; //! single address. |
| 70 | unsigned int extP[3]; //! Y Cb Cr. |
| 71 | } phys; |
| 72 | |
| 73 | //! Buffer reserved id |
| 74 | union { |
| 75 | unsigned int p; //! \n |
| 76 | unsigned int extP[3]; //! \n |
| 77 | } reserved; |
| 78 | |
| 79 | //! Buffer size |
| 80 | union { |
| 81 | unsigned int s; |
| 82 | unsigned int extS[3]; |
| 83 | } size; |
| 84 | |
| 85 | //! Constructor |
| 86 | SecBuffer() |
| 87 | { |
| 88 | for (int i = 0; i < 3; i++) { |
| 89 | virt. extP[i] = NULL; |
| 90 | phys. extP[i] = 0; |
| 91 | reserved.extP[i] = 0; |
| 92 | size. extS[i] = 0; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | //! Constructor |
| 97 | SecBuffer(const SecBuffer *other) |
| 98 | { |
| 99 | for (int i = 0; i < 3; i++) { |
| 100 | virt. extP[i] = other->virt.extP[i]; |
| 101 | phys. extP[i] = other->phys.extP[i]; |
| 102 | reserved.extP[i] = other->reserved.extP[i]; |
| 103 | size. extS[i] = other->size.extS[i]; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | //! Operator(=) override |
| 108 | SecBuffer& operator =(const SecBuffer &other) |
| 109 | { |
| 110 | for (int i = 0; i < 3; i++) { |
| 111 | virt. extP[i] = other.virt.extP[i]; |
| 112 | phys. extP[i] = other.phys.extP[i]; |
| 113 | reserved.extP[i] = other.reserved.extP[i]; |
| 114 | size. extS[i] = other.size.extS[i]; |
| 115 | } |
| 116 | return *this; |
| 117 | } |
| 118 | |
| 119 | //! Operator(==) override |
| 120 | bool operator ==(const SecBuffer &other) const |
| 121 | { |
| 122 | return ( virt. extP[0] == other.virt.extP[0] |
| 123 | && virt. extP[1] == other.virt.extP[1] |
| 124 | && virt. extP[2] == other.virt.extP[2] |
| 125 | && phys. extP[0] == other.phys.extP[0] |
| 126 | && phys. extP[1] == other.phys.extP[1] |
| 127 | && phys. extP[2] == other.phys.extP[2] |
| 128 | && reserved.extP[0] == other.reserved.extP[0] |
| 129 | && reserved.extP[1] == other.reserved.extP[1] |
| 130 | && reserved.extP[2] == other.reserved.extP[2] |
| 131 | && size. extS[0] == other.size.extS[0] |
| 132 | && size. extS[1] == other.size.extS[1] |
| 133 | && size. extS[2] == other.size.extS[2]); |
| 134 | } |
| 135 | |
| 136 | //! Operator(!=) override |
| 137 | bool operator !=(const SecBuffer &other) const |
| 138 | { |
| 139 | // use operator(==) |
| 140 | return !(*this == other); |
| 141 | } |
| 142 | |
| 143 | //! Get Buffer type |
| 144 | static int BUFFER_TYPE(SecBuffer *buf) |
| 145 | { |
| 146 | int type = BUFFER_TYPE_BASE; |
| 147 | if (buf->virt.p) |
| 148 | type |= BUFFER_TYPE_VIRT; |
| 149 | if (buf->phys.p) |
| 150 | type |= BUFFER_TYPE_PHYS; |
| 151 | if (buf->reserved.p) |
| 152 | type |= BUFFER_TYPE_RESERVED; |
| 153 | |
| 154 | return type; |
| 155 | } |
| 156 | }; |
| 157 | |
| 158 | #endif //__SEC_BUFFER_H__ |