├── Android.mk ├── CleanSpec.mk ├── boot └── boot.ld ├── dspcrashd ├── Android.mk ├── MODULE_LICENSE_BSD ├── NOTICE └── dspcrashd.c ├── libaudio-qdsp5v2 ├── Android.mk ├── AudioHardware.cpp ├── AudioHardware.h ├── AudioPolicyManager.cpp ├── AudioPolicyManager.h ├── MODULE_LICENSE_APACHE2 ├── NOTICE └── msm_audio.h ├── libaudio-qsd8k ├── Android.mk ├── AudioHardware.cpp ├── AudioHardware.h ├── AudioPolicyManager.cpp ├── AudioPolicyManager.h ├── MODULE_LICENSE_APACHE2 ├── NOTICE └── msm_audio.h ├── libaudio ├── Android.mk ├── AudioHardware.cpp ├── AudioHardware.h ├── AudioPolicyManager.cpp ├── AudioPolicyManager.h ├── MODULE_LICENSE_APACHE2 └── NOTICE ├── libcamera ├── Android.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE ├── QualcommCameraHardware.cpp ├── QualcommCameraHardware.h └── camera_ifc.h ├── libgralloc-qsd8k ├── Android.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE ├── allocator.cpp ├── allocator.h ├── framebuffer.cpp ├── gpu.cpp ├── gpu.h ├── gr.h ├── gralloc.cpp ├── gralloc_priv.h ├── mapper.cpp ├── pmemalloc.cpp ├── pmemalloc.h └── tests │ ├── Android.mk │ └── pmemalloc_test.cpp ├── libgralloc ├── Android.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE ├── allocator.cpp ├── allocator.h ├── framebuffer.cpp ├── gr.h ├── gralloc.cpp ├── gralloc_priv.h └── mapper.cpp ├── liblights ├── Android.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE └── lights.c └── librpc ├── Android.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE ├── clnt.c ├── debug.h ├── librpc.h ├── ops.c ├── rpc.c ├── rpc ├── clnt.h ├── pmap_clnt.h ├── rpc.h ├── rpc_router_ioctl.h ├── svc.h ├── types.h └── xdr.h ├── svc.c ├── svc_clnt_common.c └── xdr.c /Android.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2009 The Android Open Source Project 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 | ifeq ($(BOARD_USES_QCOM_HARDWARE),true) 18 | 19 | common_msm_dirs := librpc dspcrashd 20 | msm7k_dirs := $(common_msm_dirs) boot 21 | 22 | ifeq ($(TARGET_BOARD_PLATFORM),msm7x27) 23 | include $(call all-named-subdir-makefiles,$(msm7k_dirs)) 24 | else 25 | ifeq ($(filter msm8960 msm8660 msm7627a msm7x30,$(TARGET_BOARD_PLATFORM)),) 26 | include $(call all-named-subdir-makefiles,$(common_msm_dirs)) 27 | else 28 | include $(call all-named-subdir-makefiles,librpc) 29 | endif 30 | endif 31 | 32 | endif 33 | -------------------------------------------------------------------------------- /CleanSpec.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # If you don't need to do a full clean build but would like to touch 17 | # a file or delete some intermediate files, add a clean step to the end 18 | # of the list. These steps will only be run once, if they haven't been 19 | # run before. 20 | # 21 | # E.g.: 22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h) 23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) 24 | # 25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with 26 | # files that are missing or have been moved. 27 | # 28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. 29 | # Use $(OUT_DIR) to refer to the "out" directory. 30 | # 31 | # If you need to re-do something that's already mentioned, just copy 32 | # the command and add it to the bottom of the list. E.g., if a change 33 | # that you made last week required touching a file and a change you 34 | # made today requires touching the same file, just copy the old 35 | # touch step and add it to the end of the list. 36 | # 37 | # ************************************************ 38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 39 | # ************************************************ 40 | 41 | # For example: 42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) 43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) 44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) 45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) 46 | 47 | # ************************************************ 48 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 49 | # ************************************************ 50 | -------------------------------------------------------------------------------- /boot/boot.ld: -------------------------------------------------------------------------------- 1 | SECTIONS { 2 | BOOTLOADER_START = 0x00000000 ; 3 | .text BOOTLOADER_START : 4 | { 5 | *(.text) 6 | . = ALIGN(8); 7 | } 8 | .init : { 9 | . = ALIGN(8); 10 | BOOTLOADER_INIT_FIRST = . ; 11 | *(.init.func.0) 12 | BOOTLOADER_INIT_LAST = . ; 13 | } 14 | .data : { 15 | . = ALIGN(8); 16 | *(.data) 17 | . = ALIGN(8); 18 | } 19 | .bss : { 20 | BOOTLOADER_BSS = . ; 21 | . = ALIGN(8); 22 | *(.bss) *(COMMON) 23 | . = ALIGN(8); 24 | BOOTLOADER_END = . ; 25 | } 26 | BOOTLOADER_STACK = 0x000FF000 ; 27 | BOOTLOADER_HEAP = 0x00100000 ; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /dspcrashd/Android.mk: -------------------------------------------------------------------------------- 1 | ifneq ($(BUILD_TINY_ANDROID),true) 2 | LOCAL_PATH:= $(call my-dir) 3 | 4 | include $(CLEAR_VARS) 5 | LOCAL_SRC_FILES:= dspcrashd.c 6 | LOCAL_MODULE:= dspcrashd 7 | 8 | LOCAL_SHARED_LIBRARIES := libc libcutils 9 | 10 | LOCAL_MODULE_TAGS := debug 11 | 12 | include $(BUILD_EXECUTABLE) 13 | endif 14 | -------------------------------------------------------------------------------- /dspcrashd/MODULE_LICENSE_BSD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/dspcrashd/MODULE_LICENSE_BSD -------------------------------------------------------------------------------- /dspcrashd/NOTICE: -------------------------------------------------------------------------------- 1 | /* dspcrashd.c 2 | ** 3 | ** Copyright 2010, The Android Open Source Project 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 Google Inc. nor the names of its contributors may 13 | ** be used to endorse or promote products derived from this software 14 | ** without specific prior written permission. 15 | ** 16 | ** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR 17 | ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | ** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | -------------------------------------------------------------------------------- /dspcrashd/dspcrashd.c: -------------------------------------------------------------------------------- 1 | /* dspcrashd.c 2 | ** 3 | ** Copyright 2010, The Android Open Source Project 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 Google Inc. nor the names of its contributors may 13 | ** be used to endorse or promote products derived from this software 14 | ** without specific prior written permission. 15 | ** 16 | ** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR 17 | ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | ** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | #define KLOG_BUF_SHIFT 17 /* CONFIG_LOG_BUF_SHIFT from our kernel */ 39 | #define KLOG_BUF_LEN (1 << KLOG_BUF_SHIFT) 40 | 41 | char *props[] = { 42 | "ro.product.name", 43 | "ro.build.id", 44 | "ro.build.date", 45 | "ro.serialno", 46 | "ro.baseband", 47 | 0, 48 | }; 49 | 50 | char *dashes = "---- ---- ---- ---- ---- ---- ---- ---- ---- ----\n"; 51 | 52 | void dump_dmesg(int fd) 53 | { 54 | char buffer[KLOG_BUF_LEN + 1]; 55 | char *p = buffer; 56 | ssize_t ret; 57 | int n, op; 58 | 59 | n = klogctl(KLOG_READ_ALL, buffer, KLOG_BUF_LEN); 60 | if (n < 0) 61 | return; 62 | buffer[n] = '\0'; 63 | 64 | while((ret = write(fd, p, n))) { 65 | if (ret < 0) { 66 | if (errno == EINTR) 67 | continue; 68 | return; 69 | } 70 | p += ret; 71 | n -= ret; 72 | } 73 | 74 | return 0; 75 | } 76 | 77 | void dump_info(int fd) 78 | { 79 | char buf[4096]; 80 | char val[PROPERTY_VALUE_MAX]; 81 | char **p = props; 82 | 83 | write(fd, dashes, strlen(dashes)); 84 | while (*p) { 85 | property_get(*p,val,""); 86 | sprintf(buf,"%s: %s\n", *p, val); 87 | write(fd, buf, strlen(buf)); 88 | p++; 89 | } 90 | write(fd, dashes, strlen(dashes)); 91 | dump_dmesg(fd); 92 | write(fd, dashes, strlen(dashes)); 93 | } 94 | 95 | void dump_dsp_state(int dsp) 96 | { 97 | int fd, r; 98 | char name[128]; 99 | char buf[128*1024]; 100 | 101 | sprintf(name,"/sdcard/dsp.crash.%d.img", (int) time(0)); 102 | 103 | fd = open(name, O_CREAT | O_TRUNC | O_WRONLY, 0644); 104 | if (fd < 0) 105 | return; 106 | 107 | for (;;) { 108 | r = read(dsp, buf, sizeof(buf)); 109 | if (r == 0) break; 110 | if (r < 0) { 111 | if (errno == EINTR) 112 | continue; 113 | break; 114 | } 115 | write(fd, buf, r); 116 | } 117 | 118 | dump_info(fd); 119 | close(fd); 120 | 121 | fd = open("/dev/kmsg", O_WRONLY); 122 | if (fd >= 0) { 123 | sprintf(buf,"*** WROTE DSP RAMDUMP TO %s ***\n",name); 124 | write(fd, buf, strlen(buf)); 125 | close(fd); 126 | } 127 | } 128 | 129 | int main(int argc, char **argv) 130 | { 131 | int fd; 132 | fd = open("/dev/dsp_debug", O_RDWR); 133 | if (fd < 0) 134 | return -1; 135 | 136 | write(fd, "wait-for-crash", 14); 137 | 138 | dump_dsp_state(fd); 139 | 140 | sync(); 141 | sync(); 142 | sync(); 143 | 144 | write(fd, "continue-crash", 14); 145 | 146 | close(fd); 147 | 148 | for (;;) 149 | sleep(100); 150 | 151 | return 0; 152 | } 153 | 154 | -------------------------------------------------------------------------------- /libaudio-qdsp5v2/Android.mk: -------------------------------------------------------------------------------- 1 | 2 | ifneq ($(BUILD_TINY_ANDROID),true) 3 | 4 | LOCAL_PATH := $(call my-dir) 5 | 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_SRC_FILES:= \ 9 | AudioPolicyManager.cpp 10 | 11 | LOCAL_SHARED_LIBRARIES := \ 12 | libcutils \ 13 | libutils \ 14 | libmedia 15 | 16 | LOCAL_STATIC_LIBRARIES := libaudiopolicybase 17 | 18 | LOCAL_MODULE:= libaudiopolicy 19 | LOCAL_MODULE_TAGS := optional 20 | ifeq ($(BOARD_HAVE_BLUETOOTH),true) 21 | LOCAL_CFLAGS += -DWITH_A2DP 22 | endif 23 | 24 | include $(BUILD_SHARED_LIBRARY) 25 | 26 | 27 | include $(CLEAR_VARS) 28 | 29 | LOCAL_MODULE := libaudio 30 | LOCAL_MODULE_TAGS := optional 31 | LOCAL_SHARED_LIBRARIES := \ 32 | libcutils \ 33 | libutils \ 34 | libmedia \ 35 | libhardware_legacy 36 | 37 | LOCAL_SHARED_LIBRARIES += libdl 38 | 39 | LOCAL_SRC_FILES += AudioHardware.cpp 40 | 41 | LOCAL_CFLAGS += -fno-short-enums 42 | 43 | LOCAL_STATIC_LIBRARIES += libaudiointerface 44 | ifeq ($(BOARD_HAVE_BLUETOOTH),true) 45 | LOCAL_SHARED_LIBRARIES += liba2dp 46 | endif 47 | 48 | include $(BUILD_SHARED_LIBRARY) 49 | 50 | endif # not BUILD_TINY_ANDROID 51 | 52 | -------------------------------------------------------------------------------- /libaudio-qdsp5v2/AudioHardware.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2008, The Android Open-Source Project 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 | #include 18 | 19 | //#define LOG_NDEBUG 0 20 | #define LOG_TAG "AudioHardware" 21 | 22 | #include 23 | #include 24 | //#include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "AudioHardware.h" 35 | #include 36 | 37 | extern "C" { 38 | #include "msm_audio.h" 39 | } 40 | 41 | 42 | namespace android { 43 | // ---------------------------------------------------------------------------- 44 | 45 | AudioHardware::AudioHardware() : 46 | mInit(false), mMicMute(true), mOutput(0) 47 | { 48 | mInit = true; 49 | } 50 | 51 | AudioHardware::~AudioHardware() 52 | { 53 | closeOutputStream((AudioStreamOut*)mOutput); 54 | mInit = false; 55 | } 56 | 57 | status_t AudioHardware::initCheck() 58 | { 59 | return mInit ? NO_ERROR : NO_INIT; 60 | } 61 | 62 | AudioStreamOut* AudioHardware::openOutputStream( 63 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status) 64 | { 65 | { // scope for the lock 66 | Mutex::Autolock lock(mLock); 67 | 68 | // only one output stream allowed 69 | if (mOutput) { 70 | if (status) { 71 | *status = INVALID_OPERATION; 72 | } 73 | return 0; 74 | } 75 | 76 | AudioStreamOutQ5V2* out = new AudioStreamOutQ5V2(); 77 | 78 | status_t rc = out->set(this, devices, format, channels, sampleRate); 79 | if (rc) { 80 | *status = rc; 81 | } 82 | if (rc == NO_ERROR) { 83 | mOutput = out; 84 | } else { 85 | delete out; 86 | } 87 | } 88 | return mOutput; 89 | } 90 | 91 | void AudioHardware::closeOutputStream(AudioStreamOut* out) { 92 | Mutex::Autolock lock(mLock); 93 | if (mOutput == 0 || mOutput != out) { 94 | ALOGW("Attempt to close invalid output stream"); 95 | } 96 | else { 97 | delete mOutput; 98 | mOutput = 0; 99 | } 100 | } 101 | 102 | AudioStreamIn* AudioHardware::openInputStream( 103 | uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status, 104 | AudioSystem::audio_in_acoustics acoustic_flags) 105 | { 106 | return 0; 107 | } 108 | 109 | void AudioHardware::closeInputStream(AudioStreamIn* in) { 110 | } 111 | 112 | status_t AudioHardware::setMode(int mode) 113 | { 114 | return NO_ERROR; 115 | } 116 | 117 | status_t AudioHardware::setMicMute(bool state) 118 | { 119 | return NO_ERROR; 120 | } 121 | 122 | status_t AudioHardware::getMicMute(bool* state) 123 | { 124 | *state = mMicMute; 125 | return NO_ERROR; 126 | } 127 | 128 | status_t AudioHardware::setParameters(const String8& keyValuePairs) 129 | { 130 | return NO_ERROR; 131 | } 132 | 133 | String8 AudioHardware::getParameters(const String8& keys) 134 | { 135 | AudioParameter request = AudioParameter(keys); 136 | AudioParameter reply = AudioParameter(); 137 | 138 | ALOGV("getParameters() %s", keys.string()); 139 | 140 | return reply.toString(); 141 | } 142 | 143 | size_t AudioHardware::getInputBufferSize(uint32_t sampleRate, int format, int channelCount) 144 | { 145 | return 4096; 146 | } 147 | 148 | status_t AudioHardware::setVoiceVolume(float v) 149 | { 150 | return NO_ERROR; 151 | } 152 | 153 | status_t AudioHardware::setMasterVolume(float v) 154 | { 155 | ALOGI("Set master volume to %f.\n", v); 156 | // We return an error code here to let the audioflinger do in-software 157 | // volume on top of the maximum volume that we set through the SND API. 158 | // return error - software mixer will handle it 159 | return -1; 160 | } 161 | 162 | status_t AudioHardware::dump(int fd, const Vector& args) 163 | { 164 | return NO_ERROR; 165 | } 166 | 167 | AudioHardware::AudioStreamOutQ5V2::AudioStreamOutQ5V2() : 168 | mHardware(0), mFd(-1), mStartCount(0), mRetryCount(0), mStandby(true), 169 | mDevices(0), mChannels(AUDIO_HW_OUT_CHANNELS), mSampleRate(AUDIO_HW_OUT_SAMPLERATE), 170 | mBufferSize(AUDIO_HW_OUT_BUFSZ) 171 | { 172 | } 173 | 174 | status_t AudioHardware::AudioStreamOutQ5V2::set( 175 | AudioHardware* hw, uint32_t devices, int *pFormat, uint32_t *pChannels, uint32_t *pRate) 176 | { 177 | int lFormat = pFormat ? *pFormat : 0; 178 | uint32_t lChannels = pChannels ? *pChannels : 0; 179 | uint32_t lRate = pRate ? *pRate : 0; 180 | 181 | mHardware = hw; 182 | mDevices = devices; 183 | 184 | // fix up defaults 185 | if (lFormat == 0) lFormat = format(); 186 | if (lChannels == 0) lChannels = channels(); 187 | if (lRate == 0) lRate = sampleRate(); 188 | 189 | // check values 190 | if ((lFormat != format()) || 191 | (lChannels != channels()) || 192 | (lRate != sampleRate())) { 193 | if (pFormat) *pFormat = format(); 194 | if (pChannels) *pChannels = channels(); 195 | if (pRate) *pRate = sampleRate(); 196 | return BAD_VALUE; 197 | } 198 | 199 | if (pFormat) *pFormat = lFormat; 200 | if (pChannels) *pChannels = lChannels; 201 | if (pRate) *pRate = lRate; 202 | 203 | mChannels = lChannels; 204 | mSampleRate = lRate; 205 | mBufferSize = 4096; 206 | 207 | return NO_ERROR; 208 | } 209 | 210 | AudioHardware::AudioStreamOutQ5V2::~AudioStreamOutQ5V2() 211 | { 212 | standby(); 213 | } 214 | 215 | ssize_t AudioHardware::AudioStreamOutQ5V2::write(const void* buffer, size_t bytes) 216 | { 217 | // ALOGD("AudioStreamOutQ5V2::write(%p, %u)", buffer, bytes); 218 | status_t status = NO_INIT; 219 | size_t count = bytes; 220 | const uint8_t* p = static_cast(buffer); 221 | 222 | if (mStandby) { 223 | ALOGV("open pcm_out driver"); 224 | status = ::open("/dev/msm_pcm_out", O_RDWR); 225 | if (status < 0) { 226 | ALOGE("Cannot open /dev/msm_pcm_out errno: %d", errno); 227 | goto Error; 228 | } 229 | mFd = status; 230 | 231 | // configuration 232 | ALOGV("get config"); 233 | struct msm_audio_config config; 234 | status = ioctl(mFd, AUDIO_GET_CONFIG, &config); 235 | if (status < 0) { 236 | ALOGE("Cannot read pcm_out config"); 237 | goto Error; 238 | } 239 | 240 | ALOGV("set pcm_out config"); 241 | config.channel_count = AudioSystem::popCount(channels()); 242 | config.sample_rate = mSampleRate; 243 | config.buffer_size = mBufferSize; 244 | config.buffer_count = AUDIO_HW_NUM_OUT_BUF; 245 | // config.codec_type = CODEC_TYPE_PCM; 246 | status = ioctl(mFd, AUDIO_SET_CONFIG, &config); 247 | if (status < 0) { 248 | ALOGE("Cannot set config"); 249 | goto Error; 250 | } 251 | 252 | ALOGV("buffer_size: %u", config.buffer_size); 253 | ALOGV("buffer_count: %u", config.buffer_count); 254 | ALOGV("channel_count: %u", config.channel_count); 255 | ALOGV("sample_rate: %u", config.sample_rate); 256 | 257 | #if 0 258 | status = ioctl(mFd, AUDIO_START, &acdb_id); 259 | if (status < 0) { 260 | ALOGE("Cannot start pcm playback"); 261 | goto Error; 262 | } 263 | 264 | status = ioctl(mFd, AUDIO_SET_VOLUME, &stream_volume); 265 | if (status < 0) { 266 | ALOGE("Cannot start pcm playback"); 267 | goto Error; 268 | } 269 | #endif 270 | mStandby = false; 271 | } 272 | 273 | while (count) { 274 | ssize_t written = ::write(mFd, p, count); 275 | if (written >= 0) { 276 | count -= written; 277 | p += written; 278 | } else { 279 | if (errno != EAGAIN) return written; 280 | mRetryCount++; 281 | ALOGW("EAGAIN - retry"); 282 | } 283 | } 284 | 285 | return bytes; 286 | 287 | Error: 288 | if (mFd >= 0) { 289 | ::close(mFd); 290 | mFd = -1; 291 | } 292 | // Simulate audio output timing in case of error 293 | usleep(bytes * 1000000 / frameSize() / sampleRate()); 294 | 295 | return status; 296 | } 297 | 298 | status_t AudioHardware::AudioStreamOutQ5V2::standby() 299 | { 300 | status_t status = NO_ERROR; 301 | if (!mStandby && mFd >= 0) { 302 | ::close(mFd); 303 | mFd = -1; 304 | } 305 | mStandby = true; 306 | ALOGI("AudioHardware pcm playback is going to standby."); 307 | return status; 308 | } 309 | 310 | status_t AudioHardware::AudioStreamOutQ5V2::dump(int fd, const Vector& args) 311 | { 312 | return NO_ERROR; 313 | } 314 | 315 | bool AudioHardware::AudioStreamOutQ5V2::checkStandby() 316 | { 317 | return mStandby; 318 | } 319 | 320 | status_t AudioHardware::AudioStreamOutQ5V2::setParameters(const String8& keyValuePairs) 321 | { 322 | return NO_ERROR; 323 | } 324 | 325 | String8 AudioHardware::AudioStreamOutQ5V2::getParameters(const String8& keys) 326 | { 327 | AudioParameter param = AudioParameter(keys); 328 | ALOGV("AudioStreamOutQ5V2::getParameters() %s", param.toString().string()); 329 | return param.toString(); 330 | } 331 | 332 | status_t AudioHardware::AudioStreamOutQ5V2::getRenderPosition(uint32_t *dspFrames) 333 | { 334 | return INVALID_OPERATION; 335 | } 336 | 337 | extern "C" AudioHardwareInterface* createAudioHardware(void) { 338 | return new AudioHardware(); 339 | } 340 | 341 | }; // namespace android 342 | -------------------------------------------------------------------------------- /libaudio-qdsp5v2/AudioHardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2008, The Android Open-Source Project 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 | #ifndef ANDROID_AUDIO_HARDWARE_H 18 | #define ANDROID_AUDIO_HARDWARE_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | namespace android { 29 | 30 | #define CODEC_TYPE_PCM 0 31 | #define PCM_FILL_BUFFER_COUNT 1 32 | #define AUDIO_HW_NUM_OUT_BUF 2 // Number of buffers in audio driver for output 33 | 34 | // TODO: determine actual audio DSP and hardware latency 35 | #define AUDIO_HW_OUT_LATENCY_MS 0 // Additionnal latency introduced by audio DSP and hardware in ms 36 | #define AUDIO_HW_OUT_SAMPLERATE 44100 // Default audio output sample rate 37 | #define AUDIO_HW_OUT_CHANNELS (AudioSystem::CHANNEL_OUT_STEREO) // Default audio output channel mask 38 | #define AUDIO_HW_OUT_FORMAT (AudioSystem::PCM_16_BIT) // Default audio output sample format 39 | #define AUDIO_HW_OUT_BUFSZ 4096 // Default audio output buffer size 40 | 41 | #if 0 42 | #define AUDIO_HW_IN_SAMPLERATE 8000 // Default audio input sample rate 43 | #define AUDIO_HW_IN_CHANNELS (AudioSystem::CHANNEL_IN_MONO) // Default audio input channel mask 44 | #define AUDIO_HW_IN_FORMAT (AudioSystem::PCM_16_BIT) // Default audio input sample format 45 | #define AUDIO_HW_IN_BUFSZ 256 // Default audio input buffer size 46 | 47 | #define VOICE_VOLUME_MAX 5 // Maximum voice volume 48 | #endif 49 | 50 | class AudioHardware : public AudioHardwareBase 51 | { 52 | class AudioStreamOutQ5V2; 53 | 54 | public: 55 | AudioHardware(); 56 | virtual ~AudioHardware(); 57 | virtual status_t initCheck(); 58 | 59 | virtual status_t setVoiceVolume(float volume); 60 | virtual status_t setMasterVolume(float volume); 61 | 62 | virtual status_t setMode(int mode); 63 | 64 | virtual status_t setMicMute(bool state); 65 | virtual status_t getMicMute(bool* state); 66 | 67 | virtual status_t setParameters(const String8& keyValuePairs); 68 | virtual String8 getParameters(const String8& keys); 69 | 70 | virtual AudioStreamOut* openOutputStream( 71 | uint32_t devices, 72 | int *format=0, 73 | uint32_t *channels=0, 74 | uint32_t *sampleRate=0, 75 | status_t *status=0); 76 | 77 | virtual AudioStreamIn* openInputStream( 78 | uint32_t devices, 79 | int *format, 80 | uint32_t *channels, 81 | uint32_t *sampleRate, 82 | status_t *status, 83 | AudioSystem::audio_in_acoustics acoustics); 84 | 85 | virtual void closeOutputStream(AudioStreamOut* out); 86 | virtual void closeInputStream(AudioStreamIn* in); 87 | 88 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 89 | 90 | void clearCurDevice() { } 91 | 92 | protected: 93 | virtual status_t dump(int fd, const Vector& args); 94 | 95 | private: 96 | 97 | class AudioStreamOutQ5V2 : public AudioStreamOut { 98 | public: 99 | AudioStreamOutQ5V2(); 100 | virtual ~AudioStreamOutQ5V2(); 101 | status_t set(AudioHardware* mHardware, 102 | uint32_t devices, 103 | int *pFormat, 104 | uint32_t *pChannels, 105 | uint32_t *pRate); 106 | virtual uint32_t sampleRate() const { return mSampleRate; } 107 | // must be 32-bit aligned 108 | virtual size_t bufferSize() const { return mBufferSize; } 109 | virtual uint32_t channels() const { return mChannels; } 110 | virtual int format() const { return AUDIO_HW_OUT_FORMAT; } 111 | virtual uint32_t latency() const { return (1000*AUDIO_HW_NUM_OUT_BUF*(bufferSize()/frameSize()))/sampleRate()+AUDIO_HW_OUT_LATENCY_MS; } 112 | virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } 113 | virtual ssize_t write(const void* buffer, size_t bytes); 114 | virtual status_t standby(); 115 | virtual status_t dump(int fd, const Vector& args); 116 | bool checkStandby(); 117 | virtual status_t setParameters(const String8& keyValuePairs); 118 | virtual String8 getParameters(const String8& keys); 119 | uint32_t devices() { return mDevices; } 120 | virtual status_t getRenderPosition(uint32_t *dspFrames); 121 | 122 | private: 123 | AudioHardware* mHardware; 124 | int mFd; 125 | int mStartCount; 126 | int mRetryCount; 127 | bool mStandby; 128 | uint32_t mDevices; 129 | uint32_t mChannels; 130 | uint32_t mSampleRate; 131 | size_t mBufferSize; 132 | }; 133 | 134 | bool mInit; 135 | bool mMicMute; 136 | 137 | AudioStreamOutQ5V2* mOutput; 138 | Mutex mLock; 139 | }; 140 | 141 | 142 | }; // namespace android 143 | 144 | #endif // ANDROID_AUDIO_HARDWARE_MSM72XX_H 145 | -------------------------------------------------------------------------------- /libaudio-qdsp5v2/AudioPolicyManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 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 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace android { 27 | 28 | // ---------------------------------------------------------------------------- 29 | 30 | class AudioPolicyManager: public AudioPolicyManagerBase 31 | { 32 | 33 | public: 34 | AudioPolicyManager(AudioPolicyClientInterface *clientInterface) 35 | : AudioPolicyManagerBase(clientInterface) {} 36 | 37 | virtual ~AudioPolicyManager() {} 38 | 39 | protected: 40 | 41 | // true is current platform implements a back microphone 42 | virtual bool hasBackMicrophone() const { return true; } 43 | 44 | #ifdef WITH_A2DP 45 | // true is current platform supports suplication of notifications and ringtones over A2DP output 46 | virtual bool a2dpUsedForSonification() const { return true; } 47 | #endif 48 | 49 | // return appropriate device for streams handled by the specified strategy according to current 50 | // phone state, connected devices... 51 | virtual uint32_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true); 52 | virtual float computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device); 53 | }; 54 | 55 | }; 56 | -------------------------------------------------------------------------------- /libaudio-qdsp5v2/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/libaudio-qdsp5v2/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /libaudio-qdsp5v2/msm_audio.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Linux kernel header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to libc. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | **************************************************************************** 11 | ****************************************************************************/ 12 | #ifndef __LINUX_MSM_AUDIO_H 13 | #define __LINUX_MSM_AUDIO_H 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #define AUDIO_IOCTL_MAGIC 'a' 20 | 21 | #define AUDIO_START _IOW(AUDIO_IOCTL_MAGIC, 0, unsigned) 22 | #define AUDIO_STOP _IOW(AUDIO_IOCTL_MAGIC, 1, unsigned) 23 | #define AUDIO_FLUSH _IOW(AUDIO_IOCTL_MAGIC, 2, unsigned) 24 | #define AUDIO_GET_CONFIG _IOR(AUDIO_IOCTL_MAGIC, 3, unsigned) 25 | #define AUDIO_SET_CONFIG _IOW(AUDIO_IOCTL_MAGIC, 4, unsigned) 26 | #define AUDIO_GET_STATS _IOR(AUDIO_IOCTL_MAGIC, 5, unsigned) 27 | #define AUDIO_ENABLE_AUDPP _IOW(AUDIO_IOCTL_MAGIC, 6, unsigned) 28 | #define AUDIO_SET_ADRC _IOW(AUDIO_IOCTL_MAGIC, 7, unsigned) 29 | #define AUDIO_SET_EQ _IOW(AUDIO_IOCTL_MAGIC, 8, unsigned) 30 | #define AUDIO_SET_RX_IIR _IOW(AUDIO_IOCTL_MAGIC, 9, unsigned) 31 | #define AUDIO_SET_VOLUME _IOW(AUDIO_IOCTL_MAGIC, 10, unsigned) 32 | #define AUDIO_ENABLE_AUDPRE _IOW(AUDIO_IOCTL_MAGIC, 11, unsigned) 33 | #define AUDIO_SET_AGC _IOW(AUDIO_IOCTL_MAGIC, 12, unsigned) 34 | #define AUDIO_SET_NS _IOW(AUDIO_IOCTL_MAGIC, 13, unsigned) 35 | #define AUDIO_SET_TX_IIR _IOW(AUDIO_IOCTL_MAGIC, 14, unsigned) 36 | #define AUDIO_SET_AAC_CONFIG _IOW(AUDIO_IOCTL_MAGIC, 15, unsigned) 37 | #define AUDIO_WAIT_ADSP_DONE _IOR(AUDIO_IOCTL_MAGIC, 16, unsigned) 38 | #define AUDIO_ADSP_PAUSE _IOR(AUDIO_IOCTL_MAGIC, 17, unsigned) 39 | #define AUDIO_ADSP_RESUME _IOR(AUDIO_IOCTL_MAGIC, 18, unsigned) 40 | #define AUDIO_PLAY_DTMF _IOW(AUDIO_IOCTL_MAGIC, 19, unsigned) 41 | #define AUDIO_GET_AAC_CONFIG _IOR(AUDIO_IOCTL_MAGIC, 20, unsigned) 42 | #define AUDIO_GET_AMRNB_ENC_CONFIG _IOW(AUDIO_IOCTL_MAGIC, 21, unsigned) 43 | #define AUDIO_SET_AMRNB_ENC_CONFIG _IOR(AUDIO_IOCTL_MAGIC, 22, unsigned) 44 | #define AUDIO_GET_PCM_CONFIG _IOR(AUDIO_IOCTL_MAGIC, 30, unsigned) 45 | #define AUDIO_SET_PCM_CONFIG _IOW(AUDIO_IOCTL_MAGIC, 31, unsigned) 46 | #define AUDIO_SWITCH_DEVICE _IOW(AUDIO_IOCTL_MAGIC, 32, unsigned) 47 | #define AUDIO_SET_MUTE _IOW(AUDIO_IOCTL_MAGIC, 33, unsigned) 48 | #define AUDIO_UPDATE_ACDB _IOW(AUDIO_IOCTL_MAGIC, 34, unsigned) 49 | #define AUDIO_START_VOICE _IOW(AUDIO_IOCTL_MAGIC, 35, unsigned) 50 | #define AUDIO_STOP_VOICE _IOW(AUDIO_IOCTL_MAGIC, 36, unsigned) 51 | 52 | struct msm_audio_config { 53 | uint32_t buffer_size; 54 | uint32_t buffer_count; 55 | uint32_t channel_count; 56 | uint32_t sample_rate; 57 | uint32_t type; 58 | uint32_t unused[3]; 59 | }; 60 | 61 | struct msm_audio_stats { 62 | uint32_t byte_count; 63 | uint32_t sample_count; 64 | uint32_t unused[2]; 65 | }; 66 | 67 | #define SND_IOCTL_MAGIC 's' 68 | 69 | #define SND_MUTE_UNMUTED 0 70 | #define SND_MUTE_MUTED 1 71 | 72 | struct msm_snd_device_config { 73 | uint32_t device; 74 | uint32_t ear_mute; 75 | uint32_t mic_mute; 76 | }; 77 | 78 | #define SND_SET_DEVICE _IOW(SND_IOCTL_MAGIC, 2, struct msm_device_config *) 79 | 80 | #define SND_METHOD_VOICE 0 81 | 82 | struct msm_snd_volume_config { 83 | uint32_t device; 84 | uint32_t method; 85 | uint32_t volume; 86 | }; 87 | 88 | #define SND_SET_VOLUME _IOW(SND_IOCTL_MAGIC, 3, struct msm_snd_volume_config *) 89 | 90 | #define SND_GET_NUM_ENDPOINTS _IOR(SND_IOCTL_MAGIC, 4, unsigned *) 91 | 92 | struct msm_snd_endpoint { 93 | int id; 94 | char name[64]; 95 | }; 96 | 97 | #define SND_GET_ENDPOINT _IOWR(SND_IOCTL_MAGIC, 5, struct msm_snd_endpoint *) 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /libaudio-qsd8k/Android.mk: -------------------------------------------------------------------------------- 1 | 2 | ifneq ($(BUILD_TINY_ANDROID),true) 3 | 4 | LOCAL_PATH := $(call my-dir) 5 | 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_MODULE:= audio_policy.qsd8k 9 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 10 | LOCAL_STATIC_LIBRARIES := libmedia_helper 11 | LOCAL_WHOLE_STATIC_LIBRARIES := libaudiopolicy_legacy 12 | LOCAL_MODULE_TAGS := optional 13 | 14 | LOCAL_SHARED_LIBRARIES := \ 15 | libcutils \ 16 | libutils \ 17 | libmedia 18 | 19 | LOCAL_SRC_FILES:= AudioPolicyManager.cpp 20 | 21 | ifeq ($(BOARD_HAVE_BLUETOOTH),true) 22 | LOCAL_CFLAGS += -DWITH_A2DP 23 | endif 24 | 25 | include $(BUILD_SHARED_LIBRARY) 26 | 27 | 28 | include $(CLEAR_VARS) 29 | 30 | LOCAL_MODULE := audio.primary.qsd8k 31 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 32 | LOCAL_STATIC_LIBRARIES += libmedia_helper 33 | LOCAL_WHOLE_STATIC_LIBRARIES := libaudiohw_legacy 34 | LOCAL_MODULE_TAGS := optional 35 | 36 | LOCAL_SHARED_LIBRARIES := \ 37 | libcutils \ 38 | libutils \ 39 | libmedia \ 40 | libhardware_legacy \ 41 | libdl 42 | 43 | LOCAL_SRC_FILES += AudioHardware.cpp 44 | 45 | LOCAL_CFLAGS += -fno-short-enums 46 | 47 | ifeq ($(BOARD_HAVE_BLUETOOTH),true) 48 | LOCAL_SHARED_LIBRARIES += audio.a2dp.default 49 | endif 50 | 51 | include $(BUILD_SHARED_LIBRARY) 52 | 53 | endif # not BUILD_TINY_ANDROID 54 | 55 | -------------------------------------------------------------------------------- /libaudio-qsd8k/AudioPolicyManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 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 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace android_audio_legacy { 27 | 28 | // ---------------------------------------------------------------------------- 29 | 30 | class AudioPolicyManager: public AudioPolicyManagerBase 31 | { 32 | 33 | public: 34 | AudioPolicyManager(AudioPolicyClientInterface *clientInterface) 35 | : AudioPolicyManagerBase(clientInterface) {} 36 | 37 | virtual ~AudioPolicyManager() {} 38 | 39 | protected: 40 | 41 | // true is current platform implements a back microphone 42 | virtual bool hasBackMicrophone() const { return true; } 43 | 44 | #ifdef WITH_A2DP 45 | // true is current platform supports suplication of notifications and ringtones over A2DP output 46 | virtual bool a2dpUsedForSonification() const { return true; } 47 | #endif 48 | 49 | // return appropriate device for streams handled by the specified strategy according to current 50 | // phone state, connected devices... 51 | virtual uint32_t getDeviceForStrategy(routing_strategy strategy, bool fromCache = true); 52 | virtual float computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device); 53 | }; 54 | 55 | }; 56 | -------------------------------------------------------------------------------- /libaudio-qsd8k/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/libaudio-qsd8k/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /libaudio-qsd8k/msm_audio.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | **************************************************************************** 3 | *** 4 | *** This header was automatically generated from a Linux kernel header 5 | *** of the same name, to make information necessary for userspace to 6 | *** call into the kernel available to libc. It contains only constants, 7 | *** structures, and macros generated from the original header, and thus, 8 | *** contains no copyrightable information. 9 | *** 10 | **************************************************************************** 11 | ****************************************************************************/ 12 | #ifndef __LINUX_MSM_AUDIO_H 13 | #define __LINUX_MSM_AUDIO_H 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #define AUDIO_IOCTL_MAGIC 'a' 20 | 21 | #define AUDIO_START _IOW(AUDIO_IOCTL_MAGIC, 0, unsigned) 22 | #define AUDIO_STOP _IOW(AUDIO_IOCTL_MAGIC, 1, unsigned) 23 | #define AUDIO_FLUSH _IOW(AUDIO_IOCTL_MAGIC, 2, unsigned) 24 | #define AUDIO_GET_CONFIG _IOR(AUDIO_IOCTL_MAGIC, 3, unsigned) 25 | #define AUDIO_SET_CONFIG _IOW(AUDIO_IOCTL_MAGIC, 4, unsigned) 26 | #define AUDIO_GET_STATS _IOR(AUDIO_IOCTL_MAGIC, 5, unsigned) 27 | #define AUDIO_ENABLE_AUDPP _IOW(AUDIO_IOCTL_MAGIC, 6, unsigned) 28 | #define AUDIO_SET_ADRC _IOW(AUDIO_IOCTL_MAGIC, 7, unsigned) 29 | #define AUDIO_SET_EQ _IOW(AUDIO_IOCTL_MAGIC, 8, unsigned) 30 | #define AUDIO_SET_RX_IIR _IOW(AUDIO_IOCTL_MAGIC, 9, unsigned) 31 | #define AUDIO_SET_VOLUME _IOW(AUDIO_IOCTL_MAGIC, 10, unsigned) 32 | #define AUDIO_ENABLE_AUDPRE _IOW(AUDIO_IOCTL_MAGIC, 11, unsigned) 33 | #define AUDIO_SET_AGC _IOW(AUDIO_IOCTL_MAGIC, 12, unsigned) 34 | #define AUDIO_SET_NS _IOW(AUDIO_IOCTL_MAGIC, 13, unsigned) 35 | #define AUDIO_SET_TX_IIR _IOW(AUDIO_IOCTL_MAGIC, 14, unsigned) 36 | #define AUDIO_SET_AAC_CONFIG _IOW(AUDIO_IOCTL_MAGIC, 15, unsigned) 37 | #define AUDIO_WAIT_ADSP_DONE _IOR(AUDIO_IOCTL_MAGIC, 16, unsigned) 38 | #define AUDIO_ADSP_PAUSE _IOR(AUDIO_IOCTL_MAGIC, 17, unsigned) 39 | #define AUDIO_ADSP_RESUME _IOR(AUDIO_IOCTL_MAGIC, 18, unsigned) 40 | #define AUDIO_PLAY_DTMF _IOW(AUDIO_IOCTL_MAGIC, 19, unsigned) 41 | #define AUDIO_GET_AAC_CONFIG _IOR(AUDIO_IOCTL_MAGIC, 20, unsigned) 42 | #define AUDIO_GET_AMRNB_ENC_CONFIG _IOW(AUDIO_IOCTL_MAGIC, 21, unsigned) 43 | #define AUDIO_SET_AMRNB_ENC_CONFIG _IOR(AUDIO_IOCTL_MAGIC, 22, unsigned) 44 | #define AUDIO_GET_PCM_CONFIG _IOR(AUDIO_IOCTL_MAGIC, 30, unsigned) 45 | #define AUDIO_SET_PCM_CONFIG _IOW(AUDIO_IOCTL_MAGIC, 31, unsigned) 46 | #define AUDIO_SWITCH_DEVICE _IOW(AUDIO_IOCTL_MAGIC, 32, unsigned) 47 | #define AUDIO_SET_MUTE _IOW(AUDIO_IOCTL_MAGIC, 33, unsigned) 48 | #define AUDIO_UPDATE_ACDB _IOW(AUDIO_IOCTL_MAGIC, 34, unsigned) 49 | #define AUDIO_START_VOICE _IOW(AUDIO_IOCTL_MAGIC, 35, unsigned) 50 | #define AUDIO_STOP_VOICE _IOW(AUDIO_IOCTL_MAGIC, 36, unsigned) 51 | 52 | struct msm_audio_config { 53 | uint32_t buffer_size; 54 | uint32_t buffer_count; 55 | uint32_t channel_count; 56 | uint32_t sample_rate; 57 | uint32_t type; 58 | uint32_t unused[3]; 59 | }; 60 | 61 | struct msm_audio_stats { 62 | uint32_t byte_count; 63 | uint32_t sample_count; 64 | uint32_t unused[2]; 65 | }; 66 | 67 | #define SND_IOCTL_MAGIC 's' 68 | 69 | #define SND_MUTE_UNMUTED 0 70 | #define SND_MUTE_MUTED 1 71 | 72 | struct msm_snd_device_config { 73 | uint32_t device; 74 | uint32_t ear_mute; 75 | uint32_t mic_mute; 76 | }; 77 | 78 | #define SND_SET_DEVICE _IOW(SND_IOCTL_MAGIC, 2, struct msm_device_config *) 79 | 80 | #define SND_METHOD_VOICE 0 81 | 82 | struct msm_snd_volume_config { 83 | uint32_t device; 84 | uint32_t method; 85 | uint32_t volume; 86 | }; 87 | 88 | #define SND_SET_VOLUME _IOW(SND_IOCTL_MAGIC, 3, struct msm_snd_volume_config *) 89 | 90 | #define SND_GET_NUM_ENDPOINTS _IOR(SND_IOCTL_MAGIC, 4, unsigned *) 91 | 92 | struct msm_snd_endpoint { 93 | int id; 94 | char name[64]; 95 | }; 96 | 97 | #define SND_GET_ENDPOINT _IOWR(SND_IOCTL_MAGIC, 5, struct msm_snd_endpoint *) 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /libaudio/Android.mk: -------------------------------------------------------------------------------- 1 | 2 | ifneq ($(BUILD_TINY_ANDROID),true) 3 | 4 | LOCAL_PATH := $(call my-dir) 5 | 6 | include $(CLEAR_VARS) 7 | 8 | LOCAL_SRC_FILES:= \ 9 | AudioPolicyManager.cpp 10 | 11 | LOCAL_SHARED_LIBRARIES := \ 12 | libcutils \ 13 | libutils \ 14 | libmedia 15 | 16 | LOCAL_STATIC_LIBRARIES := libaudiopolicybase 17 | 18 | LOCAL_MODULE:= libaudiopolicy 19 | LOCAL_MODULE_TAGS:= optional 20 | ifeq ($(BOARD_HAVE_BLUETOOTH),true) 21 | LOCAL_CFLAGS += -DWITH_A2DP 22 | endif 23 | 24 | include $(BUILD_SHARED_LIBRARY) 25 | 26 | 27 | include $(CLEAR_VARS) 28 | 29 | LOCAL_MODULE := libaudio 30 | LOCAL_MODULE_TAGS := optional 31 | 32 | LOCAL_SHARED_LIBRARIES := \ 33 | libcutils \ 34 | libutils \ 35 | libmedia \ 36 | libhardware_legacy 37 | 38 | LOCAL_SHARED_LIBRARIES += libdl 39 | 40 | LOCAL_SRC_FILES += AudioHardware.cpp 41 | 42 | LOCAL_CFLAGS += -fno-short-enums 43 | 44 | LOCAL_STATIC_LIBRARIES += libaudiointerface 45 | ifeq ($(BOARD_HAVE_BLUETOOTH),true) 46 | LOCAL_SHARED_LIBRARIES += liba2dp 47 | endif 48 | 49 | include $(BUILD_SHARED_LIBRARY) 50 | 51 | endif # not BUILD_TINY_ANDROID 52 | 53 | -------------------------------------------------------------------------------- /libaudio/AudioHardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2008, The Android Open-Source Project 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 | #ifndef ANDROID_AUDIO_HARDWARE_H 18 | #define ANDROID_AUDIO_HARDWARE_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | extern "C" { 29 | #include 30 | } 31 | 32 | namespace android { 33 | 34 | // ---------------------------------------------------------------------------- 35 | // Kernel driver interface 36 | // 37 | 38 | #define SAMP_RATE_INDX_8000 0 39 | #define SAMP_RATE_INDX_11025 1 40 | #define SAMP_RATE_INDX_12000 2 41 | #define SAMP_RATE_INDX_16000 3 42 | #define SAMP_RATE_INDX_22050 4 43 | #define SAMP_RATE_INDX_24000 5 44 | #define SAMP_RATE_INDX_32000 6 45 | #define SAMP_RATE_INDX_44100 7 46 | #define SAMP_RATE_INDX_48000 8 47 | 48 | #define EQ_MAX_BAND_NUM 12 49 | 50 | #define ADRC_ENABLE 0x0001 51 | #define ADRC_DISABLE 0x0000 52 | #define EQ_ENABLE 0x0002 53 | #define EQ_DISABLE 0x0000 54 | #define RX_IIR_ENABLE 0x0004 55 | #define RX_IIR_DISABLE 0x0000 56 | 57 | struct eq_filter_type { 58 | int16_t gain; 59 | uint16_t freq; 60 | uint16_t type; 61 | uint16_t qf; 62 | }; 63 | 64 | struct eqalizer { 65 | uint16_t bands; 66 | uint16_t params[132]; 67 | }; 68 | 69 | struct rx_iir_filter { 70 | uint16_t num_bands; 71 | uint16_t iir_params[48]; 72 | }; 73 | 74 | struct msm_audio_config { 75 | uint32_t buffer_size; 76 | uint32_t buffer_count; 77 | uint32_t channel_count; 78 | uint32_t sample_rate; 79 | uint32_t codec_type; 80 | uint32_t unused[3]; 81 | }; 82 | 83 | struct msm_audio_stats { 84 | uint32_t out_bytes; 85 | uint32_t unused[3]; 86 | }; 87 | 88 | #define CODEC_TYPE_PCM 0 89 | #define AUDIO_HW_NUM_OUT_BUF 2 // Number of buffers in audio driver for output 90 | // TODO: determine actual audio DSP and hardware latency 91 | #define AUDIO_HW_OUT_LATENCY_MS 0 // Additionnal latency introduced by audio DSP and hardware in ms 92 | 93 | #define AUDIO_HW_IN_SAMPLERATE 8000 // Default audio input sample rate 94 | #define AUDIO_HW_IN_CHANNELS (AudioSystem::CHANNEL_IN_MONO) // Default audio input channel mask 95 | #define AUDIO_HW_IN_BUFFERSIZE 2048 // Default audio input buffer size 96 | #define AUDIO_HW_IN_FORMAT (AudioSystem::PCM_16_BIT) // Default audio input sample format 97 | // ---------------------------------------------------------------------------- 98 | 99 | 100 | class AudioHardware : public AudioHardwareBase 101 | { 102 | class AudioStreamOutMSM72xx; 103 | class AudioStreamInMSM72xx; 104 | 105 | public: 106 | AudioHardware(); 107 | virtual ~AudioHardware(); 108 | virtual status_t initCheck(); 109 | 110 | virtual status_t setVoiceVolume(float volume); 111 | virtual status_t setMasterVolume(float volume); 112 | 113 | virtual status_t setMode(int mode); 114 | 115 | // mic mute 116 | virtual status_t setMicMute(bool state); 117 | virtual status_t getMicMute(bool* state); 118 | 119 | virtual status_t setParameters(const String8& keyValuePairs); 120 | virtual String8 getParameters(const String8& keys); 121 | 122 | // create I/O streams 123 | virtual AudioStreamOut* openOutputStream( 124 | uint32_t devices, 125 | int *format=0, 126 | uint32_t *channels=0, 127 | uint32_t *sampleRate=0, 128 | status_t *status=0); 129 | 130 | virtual AudioStreamIn* openInputStream( 131 | 132 | uint32_t devices, 133 | int *format, 134 | uint32_t *channels, 135 | uint32_t *sampleRate, 136 | status_t *status, 137 | AudioSystem::audio_in_acoustics acoustics); 138 | 139 | virtual void closeOutputStream(AudioStreamOut* out); 140 | virtual void closeInputStream(AudioStreamIn* in); 141 | 142 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 143 | void clearCurDevice() { mCurSndDevice = -1; } 144 | 145 | protected: 146 | virtual status_t dump(int fd, const Vector& args); 147 | 148 | private: 149 | 150 | status_t doAudioRouteOrMute(uint32_t device); 151 | status_t setMicMute_nosync(bool state); 152 | status_t checkMicMute(); 153 | status_t dumpInternals(int fd, const Vector& args); 154 | uint32_t getInputSampleRate(uint32_t sampleRate); 155 | bool checkOutputStandby(); 156 | status_t doRouting(); 157 | AudioStreamInMSM72xx* getActiveInput_l(); 158 | 159 | class AudioStreamOutMSM72xx : public AudioStreamOut { 160 | public: 161 | AudioStreamOutMSM72xx(); 162 | virtual ~AudioStreamOutMSM72xx(); 163 | status_t set(AudioHardware* mHardware, 164 | uint32_t devices, 165 | int *pFormat, 166 | uint32_t *pChannels, 167 | uint32_t *pRate); 168 | virtual uint32_t sampleRate() const { return 44100; } 169 | // must be 32-bit aligned - driver only seems to like 4800 170 | virtual size_t bufferSize() const { return 4800; } 171 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; } 172 | virtual int format() const { return AudioSystem::PCM_16_BIT; } 173 | virtual uint32_t latency() const { return (1000*AUDIO_HW_NUM_OUT_BUF*(bufferSize()/frameSize()))/sampleRate()+AUDIO_HW_OUT_LATENCY_MS; } 174 | virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } 175 | virtual ssize_t write(const void* buffer, size_t bytes); 176 | virtual status_t standby(); 177 | virtual status_t dump(int fd, const Vector& args); 178 | bool checkStandby(); 179 | virtual status_t setParameters(const String8& keyValuePairs); 180 | virtual String8 getParameters(const String8& keys); 181 | uint32_t devices() { return mDevices; } 182 | virtual status_t getRenderPosition(uint32_t *dspFrames); 183 | 184 | private: 185 | AudioHardware* mHardware; 186 | int mFd; 187 | int mStartCount; 188 | int mRetryCount; 189 | bool mStandby; 190 | uint32_t mDevices; 191 | }; 192 | 193 | class AudioStreamInMSM72xx : public AudioStreamIn { 194 | public: 195 | enum input_state { 196 | AUDIO_INPUT_CLOSED, 197 | AUDIO_INPUT_OPENED, 198 | AUDIO_INPUT_STARTED 199 | }; 200 | 201 | AudioStreamInMSM72xx(); 202 | virtual ~AudioStreamInMSM72xx(); 203 | status_t set(AudioHardware* mHardware, 204 | uint32_t devices, 205 | int *pFormat, 206 | uint32_t *pChannels, 207 | uint32_t *pRate, 208 | AudioSystem::audio_in_acoustics acoustics); 209 | virtual size_t bufferSize() const { return mBufferSize; } 210 | virtual uint32_t channels() const { return mChannels; } 211 | virtual int format() const { return mFormat; } 212 | virtual uint32_t sampleRate() const { return mSampleRate; } 213 | virtual status_t setGain(float gain) { return INVALID_OPERATION; } 214 | virtual ssize_t read(void* buffer, ssize_t bytes); 215 | virtual status_t dump(int fd, const Vector& args); 216 | virtual status_t standby(); 217 | virtual status_t setParameters(const String8& keyValuePairs); 218 | virtual String8 getParameters(const String8& keys); 219 | virtual unsigned int getInputFramesLost() const { return 0; } 220 | uint32_t devices() { return mDevices; } 221 | int state() const { return mState; } 222 | 223 | private: 224 | AudioHardware* mHardware; 225 | int mFd; 226 | int mState; 227 | int mRetryCount; 228 | int mFormat; 229 | uint32_t mChannels; 230 | uint32_t mSampleRate; 231 | size_t mBufferSize; 232 | AudioSystem::audio_in_acoustics mAcoustics; 233 | uint32_t mDevices; 234 | }; 235 | 236 | static const uint32_t inputSamplingRates[]; 237 | bool mInit; 238 | bool mMicMute; 239 | bool mBluetoothNrec; 240 | uint32_t mBluetoothId; 241 | AudioStreamOutMSM72xx* mOutput; 242 | SortedVector mInputs; 243 | 244 | msm_snd_endpoint *mSndEndpoints; 245 | int mNumSndEndpoints; 246 | int mCurSndDevice; 247 | 248 | friend class AudioStreamInMSM72xx; 249 | Mutex mLock; 250 | 251 | int SND_DEVICE_CURRENT; 252 | int SND_DEVICE_HANDSET; 253 | int SND_DEVICE_SPEAKER; 254 | int SND_DEVICE_HEADSET; 255 | int SND_DEVICE_BT; 256 | int SND_DEVICE_CARKIT; 257 | int SND_DEVICE_TTY_FULL; 258 | int SND_DEVICE_TTY_VCO; 259 | int SND_DEVICE_TTY_HCO; 260 | int SND_DEVICE_NO_MIC_HEADSET; 261 | int SND_DEVICE_FM_HEADSET; 262 | int SND_DEVICE_HEADSET_AND_SPEAKER; 263 | int SND_DEVICE_FM_SPEAKER; 264 | int SND_DEVICE_BT_EC_OFF; 265 | }; 266 | 267 | // ---------------------------------------------------------------------------- 268 | 269 | }; // namespace android 270 | 271 | #endif // ANDROID_AUDIO_HARDWARE_MSM72XX_H 272 | -------------------------------------------------------------------------------- /libaudio/AudioPolicyManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 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 | #define LOG_TAG "AudioPolicyManager" 18 | //#define LOG_NDEBUG 0 19 | #include 20 | #include "AudioPolicyManager.h" 21 | #include 22 | 23 | namespace android { 24 | 25 | 26 | 27 | // ---------------------------------------------------------------------------- 28 | // AudioPolicyManager for msm7k platform 29 | // Common audio policy manager code is implemented in AudioPolicyManagerBase class 30 | // ---------------------------------------------------------------------------- 31 | 32 | // --- class factory 33 | 34 | 35 | extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface) 36 | { 37 | return new AudioPolicyManager(clientInterface); 38 | } 39 | 40 | extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface) 41 | { 42 | delete interface; 43 | } 44 | 45 | }; // namespace android 46 | -------------------------------------------------------------------------------- /libaudio/AudioPolicyManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 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 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace android { 27 | 28 | class AudioPolicyManager: public AudioPolicyManagerBase 29 | { 30 | 31 | public: 32 | AudioPolicyManager(AudioPolicyClientInterface *clientInterface) 33 | : AudioPolicyManagerBase(clientInterface) {} 34 | 35 | virtual ~AudioPolicyManager() {} 36 | 37 | protected: 38 | // true is current platform implements a back microphone 39 | virtual bool hasBackMicrophone() const { return false; } 40 | #ifdef WITH_A2DP 41 | // true is current platform supports suplication of notifications and ringtones over A2DP output 42 | virtual bool a2dpUsedForSonification() const { return true; } 43 | #endif 44 | 45 | }; 46 | }; 47 | -------------------------------------------------------------------------------- /libaudio/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/libaudio/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /libcamera/Android.mk: -------------------------------------------------------------------------------- 1 | 2 | BUILD_OLD_LIBCAMERA:= 3 | ifeq ($(BUILD_OLD_LIBCAMERA),true) 4 | 5 | # When zero we link against libqcamera; when 1, we dlopen libqcamera. 6 | DLOPEN_LIBQCAMERA:=1 7 | 8 | ifneq ($(BUILD_TINY_ANDROID),true) 9 | 10 | LOCAL_PATH:= $(call my-dir) 11 | 12 | include $(CLEAR_VARS) 13 | 14 | LOCAL_CFLAGS:=-fno-short-enums 15 | LOCAL_CFLAGS+=-DDLOPEN_LIBQCAMERA=$(DLOPEN_LIBQCAMERA) 16 | 17 | LOCAL_SRC_FILES:= QualcommCameraHardware.cpp 18 | 19 | LOCAL_SHARED_LIBRARIES:= libutils libbinder libui liblog libcamera_client 20 | ifneq ($(DLOPEN_LIBQCAMERA),1) 21 | LOCAL_SHARED_LIBRARIES+= liboemcamera 22 | else 23 | LOCAL_SHARED_LIBRARIES+= libdl 24 | endif 25 | 26 | LOCAL_MODULE:= libcamera 27 | 28 | LOCAL_MODULE_TAGS := optional 29 | 30 | include $(BUILD_SHARED_LIBRARY) 31 | 32 | endif # not BUILD_TINY_ANDROID 33 | endif # not BUILD_OLD_LIBCAMERA 34 | -------------------------------------------------------------------------------- /libcamera/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/libcamera/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /libcamera/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2008, The Android Open Source Project 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 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | 13 | 14 | Apache License 15 | Version 2.0, January 2004 16 | http://www.apache.org/licenses/ 17 | 18 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 19 | 20 | 1. Definitions. 21 | 22 | "License" shall mean the terms and conditions for use, reproduction, 23 | and distribution as defined by Sections 1 through 9 of this document. 24 | 25 | "Licensor" shall mean the copyright owner or entity authorized by 26 | the copyright owner that is granting the License. 27 | 28 | "Legal Entity" shall mean the union of the acting entity and all 29 | other entities that control, are controlled by, or are under common 30 | control with that entity. For the purposes of this definition, 31 | "control" means (i) the power, direct or indirect, to cause the 32 | direction or management of such entity, whether by contract or 33 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 34 | outstanding shares, or (iii) beneficial ownership of such entity. 35 | 36 | "You" (or "Your") shall mean an individual or Legal Entity 37 | exercising permissions granted by this License. 38 | 39 | "Source" form shall mean the preferred form for making modifications, 40 | including but not limited to software source code, documentation 41 | source, and configuration files. 42 | 43 | "Object" form shall mean any form resulting from mechanical 44 | transformation or translation of a Source form, including but 45 | not limited to compiled object code, generated documentation, 46 | and conversions to other media types. 47 | 48 | "Work" shall mean the work of authorship, whether in Source or 49 | Object form, made available under the License, as indicated by a 50 | copyright notice that is included in or attached to the work 51 | (an example is provided in the Appendix below). 52 | 53 | "Derivative Works" shall mean any work, whether in Source or Object 54 | form, that is based on (or derived from) the Work and for which the 55 | editorial revisions, annotations, elaborations, or other modifications 56 | represent, as a whole, an original work of authorship. For the purposes 57 | of this License, Derivative Works shall not include works that remain 58 | separable from, or merely link (or bind by name) to the interfaces of, 59 | the Work and Derivative Works thereof. 60 | 61 | "Contribution" shall mean any work of authorship, including 62 | the original version of the Work and any modifications or additions 63 | to that Work or Derivative Works thereof, that is intentionally 64 | submitted to Licensor for inclusion in the Work by the copyright owner 65 | or by an individual or Legal Entity authorized to submit on behalf of 66 | the copyright owner. For the purposes of this definition, "submitted" 67 | means any form of electronic, verbal, or written communication sent 68 | to the Licensor or its representatives, including but not limited to 69 | communication on electronic mailing lists, source code control systems, 70 | and issue tracking systems that are managed by, or on behalf of, the 71 | Licensor for the purpose of discussing and improving the Work, but 72 | excluding communication that is conspicuously marked or otherwise 73 | designated in writing by the copyright owner as "Not a Contribution." 74 | 75 | "Contributor" shall mean Licensor and any individual or Legal Entity 76 | on behalf of whom a Contribution has been received by Licensor and 77 | subsequently incorporated within the Work. 78 | 79 | 2. Grant of Copyright License. Subject to the terms and conditions of 80 | this License, each Contributor hereby grants to You a perpetual, 81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 82 | copyright license to reproduce, prepare Derivative Works of, 83 | publicly display, publicly perform, sublicense, and distribute the 84 | Work and such Derivative Works in Source or Object form. 85 | 86 | 3. Grant of Patent License. Subject to the terms and conditions of 87 | this License, each Contributor hereby grants to You a perpetual, 88 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 89 | (except as stated in this section) patent license to make, have made, 90 | use, offer to sell, sell, import, and otherwise transfer the Work, 91 | where such license applies only to those patent claims licensable 92 | by such Contributor that are necessarily infringed by their 93 | Contribution(s) alone or by combination of their Contribution(s) 94 | with the Work to which such Contribution(s) was submitted. If You 95 | institute patent litigation against any entity (including a 96 | cross-claim or counterclaim in a lawsuit) alleging that the Work 97 | or a Contribution incorporated within the Work constitutes direct 98 | or contributory patent infringement, then any patent licenses 99 | granted to You under this License for that Work shall terminate 100 | as of the date such litigation is filed. 101 | 102 | 4. Redistribution. You may reproduce and distribute copies of the 103 | Work or Derivative Works thereof in any medium, with or without 104 | modifications, and in Source or Object form, provided that You 105 | meet the following conditions: 106 | 107 | (a) You must give any other recipients of the Work or 108 | Derivative Works a copy of this License; and 109 | 110 | (b) You must cause any modified files to carry prominent notices 111 | stating that You changed the files; and 112 | 113 | (c) You must retain, in the Source form of any Derivative Works 114 | that You distribute, all copyright, patent, trademark, and 115 | attribution notices from the Source form of the Work, 116 | excluding those notices that do not pertain to any part of 117 | the Derivative Works; and 118 | 119 | (d) If the Work includes a "NOTICE" text file as part of its 120 | distribution, then any Derivative Works that You distribute must 121 | include a readable copy of the attribution notices contained 122 | within such NOTICE file, excluding those notices that do not 123 | pertain to any part of the Derivative Works, in at least one 124 | of the following places: within a NOTICE text file distributed 125 | as part of the Derivative Works; within the Source form or 126 | documentation, if provided along with the Derivative Works; or, 127 | within a display generated by the Derivative Works, if and 128 | wherever such third-party notices normally appear. The contents 129 | of the NOTICE file are for informational purposes only and 130 | do not modify the License. You may add Your own attribution 131 | notices within Derivative Works that You distribute, alongside 132 | or as an addendum to the NOTICE text from the Work, provided 133 | that such additional attribution notices cannot be construed 134 | as modifying the License. 135 | 136 | You may add Your own copyright statement to Your modifications and 137 | may provide additional or different license terms and conditions 138 | for use, reproduction, or distribution of Your modifications, or 139 | for any such Derivative Works as a whole, provided Your use, 140 | reproduction, and distribution of the Work otherwise complies with 141 | the conditions stated in this License. 142 | 143 | 5. Submission of Contributions. Unless You explicitly state otherwise, 144 | any Contribution intentionally submitted for inclusion in the Work 145 | by You to the Licensor shall be under the terms and conditions of 146 | this License, without any additional terms or conditions. 147 | Notwithstanding the above, nothing herein shall supersede or modify 148 | the terms of any separate license agreement you may have executed 149 | with Licensor regarding such Contributions. 150 | 151 | 6. Trademarks. This License does not grant permission to use the trade 152 | names, trademarks, service marks, or product names of the Licensor, 153 | except as required for reasonable and customary use in describing the 154 | origin of the Work and reproducing the content of the NOTICE file. 155 | 156 | 7. Disclaimer of Warranty. Unless required by applicable law or 157 | agreed to in writing, Licensor provides the Work (and each 158 | Contributor provides its Contributions) on an "AS IS" BASIS, 159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 160 | implied, including, without limitation, any warranties or conditions 161 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 162 | PARTICULAR PURPOSE. You are solely responsible for determining the 163 | appropriateness of using or redistributing the Work and assume any 164 | risks associated with Your exercise of permissions under this License. 165 | 166 | 8. Limitation of Liability. In no event and under no legal theory, 167 | whether in tort (including negligence), contract, or otherwise, 168 | unless required by applicable law (such as deliberate and grossly 169 | negligent acts) or agreed to in writing, shall any Contributor be 170 | liable to You for damages, including any direct, indirect, special, 171 | incidental, or consequential damages of any character arising as a 172 | result of this License or out of the use or inability to use the 173 | Work (including but not limited to damages for loss of goodwill, 174 | work stoppage, computer failure or malfunction, or any and all 175 | other commercial damages or losses), even if such Contributor 176 | has been advised of the possibility of such damages. 177 | 178 | 9. Accepting Warranty or Additional Liability. While redistributing 179 | the Work or Derivative Works thereof, You may choose to offer, 180 | and charge a fee for, acceptance of support, warranty, indemnity, 181 | or other liability obligations and/or rights consistent with this 182 | License. However, in accepting such obligations, You may act only 183 | on Your own behalf and on Your sole responsibility, not on behalf 184 | of any other Contributor, and only if You agree to indemnify, 185 | defend, and hold each Contributor harmless for any liability 186 | incurred by, or claims asserted against, such Contributor by reason 187 | of your accepting any such warranty or additional liability. 188 | 189 | END OF TERMS AND CONDITIONS 190 | 191 | -------------------------------------------------------------------------------- /libcamera/QualcommCameraHardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2008, The Android Open-Source Project 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 | #ifndef ANDROID_HARDWARE_QUALCOMM_CAMERA_HARDWARE_H 18 | #define ANDROID_HARDWARE_QUALCOMM_CAMERA_HARDWARE_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | extern "C" { 25 | #include 26 | } 27 | 28 | namespace android { 29 | 30 | class QualcommCameraHardware : public CameraHardwareInterface { 31 | public: 32 | 33 | virtual sp getPreviewHeap() const; 34 | virtual sp getRawHeap() const; 35 | 36 | virtual status_t dump(int fd, const Vector& args) const; 37 | virtual status_t startPreview(preview_callback cb, void* user); 38 | virtual void stopPreview(); 39 | virtual bool previewEnabled(); 40 | virtual status_t startRecording(recording_callback cb, void* user); 41 | virtual void stopRecording(); 42 | virtual bool recordingEnabled(); 43 | virtual void releaseRecordingFrame(const sp& mem); 44 | virtual status_t autoFocus(autofocus_callback, void *user); 45 | virtual status_t takePicture(shutter_callback, 46 | raw_callback, 47 | jpeg_callback, 48 | void* user); 49 | virtual status_t cancelPicture(bool cancel_shutter, 50 | bool cancel_raw, bool cancel_jpeg); 51 | virtual status_t setParameters(const CameraParameters& params); 52 | virtual CameraParameters getParameters() const; 53 | 54 | virtual void release(); 55 | 56 | static sp createInstance(); 57 | static sp getInstance(); 58 | 59 | void* get_preview_mem(uint32_t size, uint32_t *phy_addr, uint32_t index); 60 | void* get_raw_mem(uint32_t size, uint32_t *phy_addr, uint32_t index); 61 | void free_preview_mem(uint32_t *phy_addr, uint32_t size, uint32_t index); 62 | void free_raw_mem(uint32_t *phy_addr, uint32_t size, uint32_t index); 63 | 64 | private: 65 | 66 | QualcommCameraHardware(); 67 | virtual ~QualcommCameraHardware(); 68 | status_t startPreviewInternal(preview_callback pcb, void *puser, 69 | recording_callback rcb, void *ruser); 70 | void stopPreviewInternal(); 71 | 72 | static wp singleton; 73 | 74 | /* These constants reflect the number of buffers that libqcamera requires 75 | for preview and raw, and need to be updated when libqcamera 76 | changes. 77 | */ 78 | static const int kPreviewBufferCount = 4; 79 | static const int kRawBufferCount = 1; 80 | static const int kJpegBufferCount = 1; 81 | static const int kRawFrameHeaderSize = 0x48; 82 | 83 | //TODO: put the picture dimensions in the CameraParameters object; 84 | CameraParameters mParameters; 85 | int mPreviewHeight; 86 | int mPreviewWidth; 87 | int mRawHeight; 88 | int mRawWidth; 89 | 90 | void receivePreviewFrame(camera_frame_type *frame); 91 | 92 | static void stop_camera_cb(camera_cb_type cb, 93 | const void *client_data, 94 | camera_func_type func, 95 | int32_t parm4); 96 | 97 | static void camera_cb(camera_cb_type cb, 98 | const void *client_data, 99 | camera_func_type func, 100 | int32_t parm4); 101 | 102 | // This class represents a heap which maintains several contiguous 103 | // buffers. The heap may be backed by pmem (when pmem_pool contains 104 | // the name of a /dev/pmem* file), or by ashmem (when pmem_pool == NULL). 105 | 106 | struct MemPool : public RefBase { 107 | MemPool(int buffer_size, int num_buffers, 108 | int frame_size, 109 | int frame_offset, 110 | const char *name); 111 | 112 | virtual ~MemPool() = 0; 113 | 114 | void completeInitialization(); 115 | bool initialized() const { 116 | return mHeap != NULL && mHeap->base() != MAP_FAILED; 117 | } 118 | 119 | virtual status_t dump(int fd, const Vector& args) const; 120 | 121 | int mBufferSize; 122 | int mNumBuffers; 123 | int mFrameSize; 124 | int mFrameOffset; 125 | sp mHeap; 126 | sp *mBuffers; 127 | 128 | const char *mName; 129 | }; 130 | 131 | struct AshmemPool : public MemPool { 132 | AshmemPool(int buffer_size, int num_buffers, 133 | int frame_size, 134 | int frame_offset, 135 | const char *name); 136 | }; 137 | 138 | struct PmemPool : public MemPool { 139 | PmemPool(const char *pmem_pool, 140 | int buffer_size, int num_buffers, 141 | int frame_size, 142 | int frame_offset, 143 | const char *name); 144 | virtual ~PmemPool() { } 145 | int mFd; 146 | uint32_t mAlignedSize; 147 | struct pmem_region mSize; 148 | }; 149 | 150 | struct PreviewPmemPool : public PmemPool { 151 | virtual ~PreviewPmemPool(); 152 | PreviewPmemPool(int buffer_size, int num_buffers, 153 | int frame_size, 154 | int frame_offset, 155 | const char *name); 156 | }; 157 | 158 | struct RawPmemPool : public PmemPool { 159 | virtual ~RawPmemPool(); 160 | RawPmemPool(const char *pmem_pool, 161 | int buffer_size, int num_buffers, 162 | int frame_size, 163 | int frame_offset, 164 | const char *name); 165 | }; 166 | 167 | sp mPreviewHeap; 168 | sp mRawHeap; 169 | sp mJpegHeap; 170 | 171 | void startCameraIfNecessary(); 172 | bool initPreview(); 173 | void deinitPreview(); 174 | bool initRaw(bool initJpegHeap); 175 | 176 | void initDefaultParameters(); 177 | void initCameraParameters(); 178 | void setCameraDimensions(); 179 | 180 | // The states described by qualcomm_camera_state are very similar to the 181 | // CAMERA_FUNC_xxx notifications reported by libqcamera. The differences 182 | // are that they reflect not only the response from libqcamera, but also 183 | // the requests made by the clients of this object. For example, 184 | // QCS_PREVIEW_REQUESTED is a state that we enter when we call 185 | // QualcommCameraHardware::startPreview(), and stay in until libqcamera 186 | // confirms that it has received the start-preview command (but not 187 | // actually initiated preview yet). 188 | // 189 | // NOTE: keep those values small; they are used internally as indices 190 | // into a array of strings. 191 | // NOTE: if you add to this enumeration, make sure you update 192 | // getCameraStateStr(). 193 | 194 | enum qualcomm_camera_state { 195 | QCS_INIT, 196 | QCS_IDLE, 197 | QCS_ERROR, 198 | QCS_PREVIEW_IN_PROGRESS, 199 | QCS_WAITING_RAW, 200 | QCS_WAITING_JPEG, 201 | /* internal states */ 202 | QCS_INTERNAL_PREVIEW_STOPPING, 203 | QCS_INTERNAL_PREVIEW_REQUESTED, 204 | QCS_INTERNAL_RAW_REQUESTED, 205 | QCS_INTERNAL_STOPPING, 206 | }; 207 | 208 | volatile qualcomm_camera_state mCameraState; 209 | static const char* const getCameraStateStr(qualcomm_camera_state s); 210 | qualcomm_camera_state change_state(qualcomm_camera_state new_state, 211 | bool lock = true); 212 | 213 | void notifyShutter(); 214 | void receiveJpegPictureFragment(JPEGENC_CBrtnType *encInfo); 215 | 216 | void receivePostLpmRawPicture(camera_frame_type *frame); 217 | void receiveRawPicture(camera_frame_type *frame); 218 | void receiveJpegPicture(void); 219 | 220 | Mutex mLock; // API lock -- all public methods 221 | Mutex mCallbackLock; 222 | Mutex mStateLock; 223 | Condition mStateWait; 224 | 225 | /* mJpegSize keeps track of the size of the accumulated JPEG. We clear it 226 | when we are about to take a picture, so at any time it contains either 227 | zero, or the size of the last JPEG picture taken. 228 | */ 229 | uint32_t mJpegSize; 230 | camera_handle_type camera_handle; 231 | camera_encode_properties_type encode_properties; 232 | camera_position_type pt; 233 | 234 | shutter_callback mShutterCallback; 235 | raw_callback mRawPictureCallback; 236 | jpeg_callback mJpegPictureCallback; 237 | void *mPictureCallbackCookie; 238 | 239 | autofocus_callback mAutoFocusCallback; 240 | void *mAutoFocusCallbackCookie; 241 | 242 | preview_callback mPreviewCallback; 243 | void *mPreviewCallbackCookie; 244 | recording_callback mRecordingCallback; 245 | void *mRecordingCallbackCookie; 246 | bool setCallbacks(preview_callback pcb, void *pu, 247 | recording_callback rcb, void *ru); 248 | 249 | int mPreviewFrameSize; 250 | int mRawSize; 251 | int mJpegMaxSize; 252 | 253 | // hack to prevent black frame on first preview 254 | int mPreviewCount; 255 | 256 | #if DLOPEN_LIBQCAMERA == 1 257 | void *libqcamera; 258 | #endif 259 | }; 260 | 261 | }; // namespace android 262 | 263 | #endif 264 | 265 | 266 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | # HAL module implemenation stored in 18 | # hw/..so 19 | include $(CLEAR_VARS) 20 | 21 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 22 | LOCAL_SHARED_LIBRARIES := liblog libcutils libGLESv1_CM 23 | 24 | LOCAL_SRC_FILES := \ 25 | allocator.cpp \ 26 | framebuffer.cpp \ 27 | gpu.cpp \ 28 | gralloc.cpp \ 29 | mapper.cpp \ 30 | pmemalloc.cpp 31 | 32 | LOCAL_MODULE := gralloc.$(TARGET_BOARD_PLATFORM) 33 | LOCAL_MODULE_TAGS := optional 34 | LOCAL_CFLAGS:= -DLOG_TAG=\"$(TARGET_BOARD_PLATFORM).gralloc\" 35 | ifeq ($(TARGET_GRALLOC_USES_ASHMEM),true) 36 | LOCAL_CFLAGS += -DUSE_ASHMEM 37 | endif 38 | include $(BUILD_SHARED_LIBRARY) 39 | 40 | # Build a host library for testing 41 | ifeq ($(HOST_OS),linux) 42 | include $(CLEAR_VARS) 43 | LOCAL_SRC_FILES := \ 44 | gpu.cpp \ 45 | pmemalloc.cpp 46 | 47 | LOCAL_MODULE_TAGS := tests 48 | LOCAL_MODULE := libgralloc_qsd8k_host 49 | LOCAL_MODULE_TAGS := optional 50 | LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc-qsd8k\" 51 | include $(BUILD_HOST_STATIC_LIBRARY) 52 | endif 53 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/libgralloc-qsd8k/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /libgralloc-qsd8k/allocator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 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 | #include 18 | 19 | #include "allocator.h" 20 | 21 | 22 | // align all the memory blocks on a cache-line boundary 23 | const int SimpleBestFitAllocator::kMemoryAlign = 32; 24 | 25 | SimpleBestFitAllocator::SimpleBestFitAllocator() 26 | : mHeapSize(0) 27 | { 28 | } 29 | 30 | SimpleBestFitAllocator::SimpleBestFitAllocator(size_t size) 31 | : mHeapSize(0) 32 | { 33 | setSize(size); 34 | } 35 | 36 | SimpleBestFitAllocator::~SimpleBestFitAllocator() 37 | { 38 | while(!mList.isEmpty()) { 39 | delete mList.remove(mList.head()); 40 | } 41 | } 42 | 43 | ssize_t SimpleBestFitAllocator::setSize(size_t size) 44 | { 45 | Locker::Autolock _l(mLock); 46 | if (mHeapSize != 0) return -EINVAL; 47 | size_t pagesize = getpagesize(); 48 | mHeapSize = ((size + pagesize-1) & ~(pagesize-1)); 49 | chunk_t* node = new chunk_t(0, mHeapSize / kMemoryAlign); 50 | mList.insertHead(node); 51 | return size; 52 | } 53 | 54 | 55 | size_t SimpleBestFitAllocator::size() const 56 | { 57 | return mHeapSize; 58 | } 59 | 60 | ssize_t SimpleBestFitAllocator::allocate(size_t size, uint32_t flags) 61 | { 62 | Locker::Autolock _l(mLock); 63 | if (mHeapSize == 0) return -EINVAL; 64 | ssize_t offset = alloc(size, flags); 65 | return offset; 66 | } 67 | 68 | ssize_t SimpleBestFitAllocator::deallocate(size_t offset) 69 | { 70 | Locker::Autolock _l(mLock); 71 | if (mHeapSize == 0) return -EINVAL; 72 | chunk_t const * const freed = dealloc(offset); 73 | if (freed) { 74 | return 0; 75 | } 76 | return -ENOENT; 77 | } 78 | 79 | ssize_t SimpleBestFitAllocator::alloc(size_t size, uint32_t flags) 80 | { 81 | if (size == 0) { 82 | return 0; 83 | } 84 | size = (size + kMemoryAlign-1) / kMemoryAlign; 85 | chunk_t* free_chunk = 0; 86 | chunk_t* cur = mList.head(); 87 | 88 | size_t pagesize = getpagesize(); 89 | while (cur) { 90 | int extra = ( -cur->start & ((pagesize/kMemoryAlign)-1) ) ; 91 | 92 | // best fit 93 | if (cur->free && (cur->size >= (size+extra))) { 94 | if ((!free_chunk) || (cur->size < free_chunk->size)) { 95 | free_chunk = cur; 96 | } 97 | if (cur->size == size) { 98 | break; 99 | } 100 | } 101 | cur = cur->next; 102 | } 103 | 104 | if (free_chunk) { 105 | const size_t free_size = free_chunk->size; 106 | free_chunk->free = 0; 107 | free_chunk->size = size; 108 | if (free_size > size) { 109 | int extra = ( -free_chunk->start & ((pagesize/kMemoryAlign)-1) ) ; 110 | if (extra) { 111 | chunk_t* split = new chunk_t(free_chunk->start, extra); 112 | free_chunk->start += extra; 113 | mList.insertBefore(free_chunk, split); 114 | } 115 | 116 | ALOGE_IF(((free_chunk->start*kMemoryAlign)&(pagesize-1)), 117 | "page is not aligned!!!"); 118 | 119 | const ssize_t tail_free = free_size - (size+extra); 120 | if (tail_free > 0) { 121 | chunk_t* split = new chunk_t( 122 | free_chunk->start + free_chunk->size, tail_free); 123 | mList.insertAfter(free_chunk, split); 124 | } 125 | } 126 | return (free_chunk->start)*kMemoryAlign; 127 | } 128 | return -ENOMEM; 129 | } 130 | 131 | SimpleBestFitAllocator::chunk_t* SimpleBestFitAllocator::dealloc(size_t start) 132 | { 133 | start = start / kMemoryAlign; 134 | chunk_t* cur = mList.head(); 135 | while (cur) { 136 | if (cur->start == start) { 137 | LOG_FATAL_IF(cur->free, 138 | "block at offset 0x%08lX of size 0x%08lX already freed", 139 | cur->start*kMemoryAlign, cur->size*kMemoryAlign); 140 | 141 | // merge freed blocks together 142 | chunk_t* freed = cur; 143 | cur->free = 1; 144 | do { 145 | chunk_t* const p = cur->prev; 146 | chunk_t* const n = cur->next; 147 | if (p && (p->free || !cur->size)) { 148 | freed = p; 149 | p->size += cur->size; 150 | mList.remove(cur); 151 | delete cur; 152 | } 153 | cur = n; 154 | } while (cur && cur->free); 155 | 156 | LOG_FATAL_IF(!freed->free, 157 | "freed block at offset 0x%08lX of size 0x%08lX is not free!", 158 | freed->start * kMemoryAlign, freed->size * kMemoryAlign); 159 | 160 | return freed; 161 | } 162 | cur = cur->next; 163 | } 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 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 | #ifndef GRALLOC_ALLOCATOR_H_ 19 | #define GRALLOC_ALLOCATOR_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "gr.h" 25 | #include "pmemalloc.h" 26 | 27 | // ---------------------------------------------------------------------------- 28 | 29 | /* 30 | * A simple templatized doubly linked-list implementation 31 | */ 32 | 33 | template 34 | class LinkedList 35 | { 36 | NODE* mFirst; 37 | NODE* mLast; 38 | 39 | public: 40 | LinkedList() : mFirst(0), mLast(0) { } 41 | bool isEmpty() const { return mFirst == 0; } 42 | NODE const* head() const { return mFirst; } 43 | NODE* head() { return mFirst; } 44 | NODE const* tail() const { return mLast; } 45 | NODE* tail() { return mLast; } 46 | 47 | void insertAfter(NODE* node, NODE* newNode) { 48 | newNode->prev = node; 49 | newNode->next = node->next; 50 | if (node->next == 0) mLast = newNode; 51 | else node->next->prev = newNode; 52 | node->next = newNode; 53 | } 54 | 55 | void insertBefore(NODE* node, NODE* newNode) { 56 | newNode->prev = node->prev; 57 | newNode->next = node; 58 | if (node->prev == 0) mFirst = newNode; 59 | else node->prev->next = newNode; 60 | node->prev = newNode; 61 | } 62 | 63 | void insertHead(NODE* newNode) { 64 | if (mFirst == 0) { 65 | mFirst = mLast = newNode; 66 | newNode->prev = newNode->next = 0; 67 | } else { 68 | newNode->prev = 0; 69 | newNode->next = mFirst; 70 | mFirst->prev = newNode; 71 | mFirst = newNode; 72 | } 73 | } 74 | 75 | void insertTail(NODE* newNode) { 76 | if (mLast == 0) { 77 | insertHead(newNode); 78 | } else { 79 | newNode->prev = mLast; 80 | newNode->next = 0; 81 | mLast->next = newNode; 82 | mLast = newNode; 83 | } 84 | } 85 | 86 | NODE* remove(NODE* node) { 87 | if (node->prev == 0) mFirst = node->next; 88 | else node->prev->next = node->next; 89 | if (node->next == 0) mLast = node->prev; 90 | else node->next->prev = node->prev; 91 | return node; 92 | } 93 | }; 94 | 95 | class SimpleBestFitAllocator : public PmemUserspaceAllocator::Deps::Allocator 96 | { 97 | public: 98 | 99 | SimpleBestFitAllocator(); 100 | SimpleBestFitAllocator(size_t size); 101 | virtual ~SimpleBestFitAllocator(); 102 | 103 | virtual ssize_t setSize(size_t size); 104 | 105 | virtual ssize_t allocate(size_t size, uint32_t flags = 0); 106 | virtual ssize_t deallocate(size_t offset); 107 | virtual size_t size() const; 108 | 109 | private: 110 | struct chunk_t { 111 | chunk_t(size_t start, size_t size) 112 | : start(start), size(size), free(1), prev(0), next(0) { 113 | } 114 | size_t start; 115 | size_t size : 28; 116 | int free : 4; 117 | mutable chunk_t* prev; 118 | mutable chunk_t* next; 119 | }; 120 | 121 | ssize_t alloc(size_t size, uint32_t flags); 122 | chunk_t* dealloc(size_t start); 123 | 124 | static const int kMemoryAlign; 125 | mutable Locker mLock; 126 | LinkedList mList; 127 | size_t mHeapSize; 128 | }; 129 | 130 | #endif /* GRALLOC_ALLOCATOR_H_ */ 131 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/gpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 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 | #ifndef GRALLOC_QSD8K_GPU_H_ 18 | #define GRALLOC_QSD8K_GPU_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include "gralloc_priv.h" 29 | #include "pmemalloc.h" 30 | 31 | 32 | class gpu_context_t : public alloc_device_t { 33 | public: 34 | 35 | class Deps { 36 | public: 37 | 38 | virtual ~Deps(); 39 | 40 | // ashmem 41 | virtual int ashmem_create_region(const char *name, size_t size) = 0; 42 | 43 | // POSIX 44 | virtual int close(int fd) = 0; 45 | 46 | // Framebuffer (locally defined) 47 | virtual int mapFrameBufferLocked(struct private_module_t* module) = 0; 48 | virtual int terminateBuffer(gralloc_module_t const* module, 49 | private_handle_t* hnd) = 0; 50 | }; 51 | 52 | gpu_context_t(Deps& deps, PmemAllocator& pmemAllocator, 53 | PmemAllocator& pmemAdspAllocator, const private_module_t* module); 54 | 55 | int gralloc_alloc_framebuffer_locked(size_t size, int usage, 56 | buffer_handle_t* pHandle); 57 | int gralloc_alloc_framebuffer(size_t size, int usage, 58 | buffer_handle_t* pHandle); 59 | int gralloc_alloc_buffer(size_t size, int usage, buffer_handle_t* pHandle, int bufferType, int format, 60 | int width, int height); 61 | int free_impl(private_handle_t const* hnd); 62 | int alloc_impl(int w, int h, int format, int usage, 63 | buffer_handle_t* pHandle, int* pStride, int bufferSize = 0); 64 | 65 | static int gralloc_alloc(alloc_device_t* dev, int w, int h, int format, 66 | int usage, buffer_handle_t* pHandle, int* pStride); 67 | static int gralloc_free(alloc_device_t* dev, buffer_handle_t handle); 68 | static int gralloc_alloc_size(alloc_device_t* dev, int w, int h, int format, 69 | int usage, buffer_handle_t* pHandle, int* pStride, int bufferSize); 70 | static int gralloc_close(struct hw_device_t *dev); 71 | int get_composition_type() const { return compositionType; } 72 | 73 | private: 74 | 75 | Deps& deps; 76 | PmemAllocator& pmemAllocator; 77 | PmemAllocator& pmemAdspAllocator; 78 | int compositionType; 79 | int alloc_ashmem_buffer(size_t size, unsigned int postfix, void** pBase, 80 | int* pOffset, int* pFd); 81 | void getGrallocInformationFromFormat(int inputFormat, int *colorFormat, int *bufferType); 82 | }; 83 | 84 | #endif // GRALLOC_QSD8K_GPU_H 85 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/gr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 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 | #ifndef GR_H_ 18 | #define GR_H_ 19 | 20 | #include 21 | #ifdef HAVE_ANDROID_OS // just want PAGE_SIZE define 22 | # include 23 | #else 24 | # include 25 | #endif 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | #include 35 | 36 | /*****************************************************************************/ 37 | 38 | struct private_module_t; 39 | struct private_handle_t; 40 | 41 | inline size_t roundUpToPageSize(size_t x) { 42 | return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); 43 | } 44 | 45 | int mapFrameBufferLocked(struct private_module_t* module); 46 | int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd); 47 | size_t calculateBufferSize(int width, int height, int format); 48 | int decideBufferHandlingMechanism(int format, const char *compositionUsed, 49 | int hasBlitEngine, int *needConversion, 50 | int *useBufferDirectly); 51 | /*****************************************************************************/ 52 | 53 | class Locker { 54 | pthread_mutex_t mutex; 55 | public: 56 | class Autolock { 57 | Locker& locker; 58 | public: 59 | inline Autolock(Locker& locker) : locker(locker) { locker.lock(); } 60 | inline ~Autolock() { locker.unlock(); } 61 | }; 62 | inline Locker() { pthread_mutex_init(&mutex, 0); } 63 | inline ~Locker() { pthread_mutex_destroy(&mutex); } 64 | inline void lock() { pthread_mutex_lock(&mutex); } 65 | inline void unlock() { pthread_mutex_unlock(&mutex); } 66 | }; 67 | 68 | #endif /* GR_H_ */ 69 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/gralloc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 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 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "allocator.h" 28 | #include "gr.h" 29 | #include "gpu.h" 30 | 31 | /*****************************************************************************/ 32 | 33 | static int gralloc_alloc_buffer(alloc_device_t* dev, 34 | size_t size, int usage, buffer_handle_t* pHandle); 35 | 36 | /*****************************************************************************/ 37 | 38 | int fb_device_open(const hw_module_t* module, const char* name, 39 | hw_device_t** device); 40 | 41 | static int gralloc_device_open(const hw_module_t* module, const char* name, 42 | hw_device_t** device); 43 | 44 | extern int gralloc_lock(gralloc_module_t const* module, 45 | buffer_handle_t handle, int usage, 46 | int l, int t, int w, int h, 47 | void** vaddr); 48 | 49 | extern int gralloc_unlock(gralloc_module_t const* module, 50 | buffer_handle_t handle); 51 | 52 | extern int gralloc_register_buffer(gralloc_module_t const* module, 53 | buffer_handle_t handle); 54 | 55 | extern int gralloc_unregister_buffer(gralloc_module_t const* module, 56 | buffer_handle_t handle); 57 | 58 | extern int gralloc_perform(struct gralloc_module_t const* module, 59 | int operation, ... ); 60 | 61 | /*****************************************************************************/ 62 | 63 | /* On-device dependency implementation */ 64 | class PmemAllocatorDepsDeviceImpl : public PmemUserspaceAllocator::Deps, 65 | public PmemKernelAllocator::Deps { 66 | 67 | const private_module_t* module; 68 | 69 | virtual size_t getPmemTotalSize(int fd, size_t* size) { 70 | int err = 0; 71 | #ifndef TARGET_MSM7x27 72 | pmem_region region; 73 | err = ioctl(fd, PMEM_GET_TOTAL_SIZE, ®ion); 74 | if (err == 0) { 75 | *size = region.len; 76 | } 77 | #else 78 | #ifdef USE_ASHMEM 79 | if(module != NULL) 80 | *size = module->info.xres * module->info.yres * 2 * 2; 81 | else 82 | return -ENOMEM; 83 | #else 84 | *size = 23<<20; //23MB for 7x27 85 | #endif 86 | #endif 87 | return err; 88 | } 89 | 90 | virtual int connectPmem(int fd, int master_fd) { 91 | return ioctl(fd, PMEM_CONNECT, master_fd); 92 | } 93 | 94 | virtual int mapPmem(int fd, int offset, size_t size) { 95 | struct pmem_region sub = { offset, size }; 96 | return ioctl(fd, PMEM_MAP, &sub); 97 | } 98 | 99 | virtual int unmapPmem(int fd, int offset, size_t size) { 100 | struct pmem_region sub = { offset, size }; 101 | return ioctl(fd, PMEM_UNMAP, &sub); 102 | } 103 | 104 | virtual int alignPmem(int fd, size_t size, int align) { 105 | struct pmem_allocation allocation; 106 | allocation.size = size; 107 | allocation.align = align; 108 | return ioctl(fd, PMEM_ALLOCATE_ALIGNED, &allocation); 109 | } 110 | 111 | virtual int cleanPmem(int fd, unsigned long base, int offset, size_t size) { 112 | struct pmem_addr pmem_addr; 113 | pmem_addr.vaddr = base; 114 | pmem_addr.offset = offset; 115 | pmem_addr.length = size; 116 | return ioctl(fd, PMEM_CLEAN_INV_CACHES, &pmem_addr); 117 | } 118 | 119 | virtual int getErrno() { 120 | return errno; 121 | } 122 | 123 | virtual void* mmap(void* start, size_t length, int prot, int flags, int fd, 124 | off_t offset) { 125 | return ::mmap(start, length, prot, flags, fd, offset); 126 | } 127 | 128 | virtual int munmap(void* start, size_t length) { 129 | return ::munmap(start, length); 130 | } 131 | 132 | virtual int open(const char* pathname, int flags, int mode) { 133 | return ::open(pathname, flags, mode); 134 | } 135 | 136 | virtual int close(int fd) { 137 | return ::close(fd); 138 | } 139 | 140 | public: 141 | void setModule(const private_module_t* m) { 142 | module = m; 143 | } 144 | 145 | }; 146 | 147 | class GpuContextDepsDeviceImpl : public gpu_context_t::Deps { 148 | 149 | public: 150 | 151 | virtual int ashmem_create_region(const char *name, size_t size) { 152 | return ::ashmem_create_region(name, size); 153 | } 154 | 155 | virtual int mapFrameBufferLocked(struct private_module_t* module) { 156 | return ::mapFrameBufferLocked(module); 157 | } 158 | 159 | virtual int terminateBuffer(gralloc_module_t const* module, 160 | private_handle_t* hnd) { 161 | return ::terminateBuffer(module, hnd); 162 | } 163 | 164 | virtual int close(int fd) { 165 | return ::close(fd); 166 | } 167 | }; 168 | 169 | static PmemAllocatorDepsDeviceImpl pmemAllocatorDeviceDepsImpl; 170 | static GpuContextDepsDeviceImpl gpuContextDeviceDepsImpl; 171 | 172 | /*****************************************************************************/ 173 | 174 | static SimpleBestFitAllocator pmemAllocMgr; 175 | static PmemUserspaceAllocator pmemAllocator(pmemAllocatorDeviceDepsImpl, pmemAllocMgr, 176 | "/dev/pmem"); 177 | 178 | static PmemKernelAllocator pmemAdspAllocator(pmemAllocatorDeviceDepsImpl); 179 | 180 | /*****************************************************************************/ 181 | 182 | static struct hw_module_methods_t gralloc_module_methods = { 183 | open: gralloc_device_open 184 | }; 185 | 186 | struct private_module_t HAL_MODULE_INFO_SYM = { 187 | base: { 188 | common: { 189 | tag: HARDWARE_MODULE_TAG, 190 | version_major: 1, 191 | version_minor: 0, 192 | id: GRALLOC_HARDWARE_MODULE_ID, 193 | name: "Graphics Memory Allocator Module", 194 | author: "The Android Open Source Project", 195 | methods: &gralloc_module_methods 196 | }, 197 | registerBuffer: gralloc_register_buffer, 198 | unregisterBuffer: gralloc_unregister_buffer, 199 | lock: gralloc_lock, 200 | unlock: gralloc_unlock, 201 | perform: gralloc_perform, 202 | }, 203 | framebuffer: 0, 204 | fbFormat: 0, 205 | flags: 0, 206 | numBuffers: 0, 207 | bufferMask: 0, 208 | lock: PTHREAD_MUTEX_INITIALIZER, 209 | currentBuffer: 0, 210 | }; 211 | 212 | /*****************************************************************************/ 213 | 214 | int gralloc_device_open(const hw_module_t* module, const char* name, 215 | hw_device_t** device) 216 | { 217 | int status = -EINVAL; 218 | if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) { 219 | const private_module_t* m = reinterpret_cast( 220 | module); 221 | pmemAllocatorDeviceDepsImpl.setModule(m); 222 | gpu_context_t *dev; 223 | dev = new gpu_context_t(gpuContextDeviceDepsImpl, pmemAllocator, 224 | pmemAdspAllocator, m); 225 | *device = &dev->common; 226 | status = 0; 227 | } else { 228 | status = fb_device_open(module, name, device); 229 | } 230 | return status; 231 | } 232 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/gralloc_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 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 | #ifndef GRALLOC_PRIV_H_ 18 | #define GRALLOC_PRIV_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | enum { 33 | /* gralloc usage bit indicating a pmem_adsp allocation should be used */ 34 | GRALLOC_USAGE_PRIVATE_PMEM_ADSP = GRALLOC_USAGE_PRIVATE_0, 35 | GRALLOC_USAGE_PRIVATE_PMEM_SMIPOOL = GRALLOC_USAGE_PRIVATE_1, 36 | GRALLOC_USAGE_PRIVATE_PMEM = GRALLOC_USAGE_PRIVATE_2, 37 | }; 38 | 39 | enum { 40 | GPU_COMPOSITION, 41 | C2D_COMPOSITION, 42 | MDP_COMPOSITION, 43 | CPU_COMPOSITION, 44 | }; 45 | 46 | /* numbers of max buffers for page flipping */ 47 | #define NUM_FRAMEBUFFERS_MIN 2 48 | #define NUM_FRAMEBUFFERS_MAX 3 49 | 50 | /* number of default bufers for page flipping */ 51 | #define NUM_DEF_FRAME_BUFFERS 2 52 | #define NO_SURFACEFLINGER_SWAPINTERVAL 53 | #define INTERLACE_MASK 0x80 54 | #define S3D_FORMAT_MASK 0xFF000 55 | #define COLOR_FORMAT(x) (x & 0xFFF) // Max range for colorFormats is 0 - FFF 56 | #define DEVICE_PMEM_ADSP "/dev/pmem_adsp" 57 | #define DEVICE_PMEM_SMIPOOL "/dev/pmem_smipool" 58 | /*****************************************************************************/ 59 | 60 | enum { 61 | /* OEM specific HAL formats */ 62 | //HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x100, // defined in hardware.h 63 | //HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x101, // defined in hardware.h 64 | HAL_PIXEL_FORMAT_YCbCr_422_P = 0x102, 65 | HAL_PIXEL_FORMAT_YCbCr_420_P = 0x103, 66 | //HAL_PIXEL_FORMAT_YCbCr_422_I = 0x104, // defined in hardware.h 67 | HAL_PIXEL_FORMAT_YCbCr_420_I = 0x105, 68 | HAL_PIXEL_FORMAT_CbYCrY_422_I = 0x106, 69 | HAL_PIXEL_FORMAT_CbYCrY_420_I = 0x107, 70 | HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED = 0x108, 71 | HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x109, 72 | HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x10A, 73 | HAL_PIXEL_FORMAT_YCrCb_422_SP = 0x10B, 74 | HAL_PIXEL_FORMAT_YCrCb_420_SP_INTERLACE = 0x10C, 75 | HAL_PIXEL_FORMAT_R_8 = 0x10D, 76 | HAL_PIXEL_FORMAT_RG_88 = 0x10E, 77 | HAL_PIXEL_FORMAT_INTERLACE = 0x180, 78 | }; 79 | 80 | /* possible formats for 3D content*/ 81 | enum { 82 | HAL_NO_3D = 0x0000, 83 | HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000, 84 | HAL_3D_IN_TOP_BOTTOM = 0x20000, 85 | HAL_3D_IN_INTERLEAVE = 0x40000, 86 | HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000, 87 | HAL_3D_OUT_SIDE_BY_SIDE = 0x1000, 88 | HAL_3D_OUT_TOP_BOTTOM = 0x2000, 89 | HAL_3D_OUT_INTERLEAVE = 0x4000, 90 | HAL_3D_OUT_MONOSCOPIC = 0x8000 91 | }; 92 | 93 | enum { 94 | BUFFER_TYPE_UI = 0, 95 | BUFFER_TYPE_VIDEO 96 | }; 97 | /*****************************************************************************/ 98 | 99 | struct private_module_t; 100 | struct private_handle_t; 101 | struct PmemAllocator; 102 | 103 | struct private_module_t { 104 | gralloc_module_t base; 105 | 106 | struct private_handle_t* framebuffer; 107 | uint32_t fbFormat; 108 | uint32_t flags; 109 | uint32_t numBuffers; 110 | uint32_t bufferMask; 111 | pthread_mutex_t lock; 112 | buffer_handle_t currentBuffer; 113 | 114 | struct fb_var_screeninfo info; 115 | struct fb_fix_screeninfo finfo; 116 | float xdpi; 117 | float ydpi; 118 | float fps; 119 | int swapInterval; 120 | 121 | enum { 122 | // flag to indicate we'll post this buffer 123 | PRIV_USAGE_LOCKED_FOR_POST = 0x80000000, 124 | PRIV_MIN_SWAP_INTERVAL = 0, 125 | PRIV_MAX_SWAP_INTERVAL = 1, 126 | }; 127 | 128 | }; 129 | 130 | /*****************************************************************************/ 131 | 132 | #ifdef __cplusplus 133 | struct private_handle_t : public native_handle { 134 | #else 135 | struct private_handle_t { 136 | native_handle_t nativeHandle; 137 | #endif 138 | 139 | enum { 140 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, 141 | PRIV_FLAGS_USES_PMEM = 0x00000002, 142 | PRIV_FLAGS_USES_PMEM_ADSP = 0x00000004, 143 | PRIV_FLAGS_NEEDS_FLUSH = 0x00000008, 144 | PRIV_FLAGS_USES_ASHMEM = 0x00000010, 145 | PRIV_FLAGS_FORMAT_CHANGED = 0x00000020, 146 | }; 147 | 148 | enum { 149 | LOCK_STATE_WRITE = 1<<31, 150 | LOCK_STATE_MAPPED = 1<<30, 151 | LOCK_STATE_READ_MASK = 0x3FFFFFFF 152 | }; 153 | 154 | // file-descriptors 155 | int fd; 156 | // ints 157 | int magic; 158 | int flags; 159 | int size; 160 | int offset; 161 | int bufferType; 162 | 163 | // FIXME: the attributes below should be out-of-line 164 | int base; 165 | int lockState; 166 | int writeOwner; 167 | int gpuaddr; // The gpu address mapped into the mmu. If using ashmem, set to 0 They don't care 168 | int pid; 169 | int format; 170 | int width; 171 | int height; 172 | 173 | #ifdef __cplusplus 174 | static const int sNumInts = 13; 175 | static const int sNumFds = 1; 176 | static const int sMagic = 'gmsm'; 177 | 178 | private_handle_t(int fd, int size, int flags, int bufferType, int format, int width, int height) : 179 | fd(fd), magic(sMagic), flags(flags), size(size), offset(0), bufferType(bufferType), 180 | base(0), lockState(0), writeOwner(0), gpuaddr(0), pid(getpid()), format(format), width(width), 181 | height(height) 182 | { 183 | version = sizeof(native_handle); 184 | numInts = sNumInts; 185 | numFds = sNumFds; 186 | } 187 | ~private_handle_t() { 188 | magic = 0; 189 | } 190 | 191 | bool usesPhysicallyContiguousMemory() { 192 | return (flags & PRIV_FLAGS_USES_PMEM) != 0; 193 | } 194 | 195 | static int validate(const native_handle* h) { 196 | const private_handle_t* hnd = (const private_handle_t*)h; 197 | if (!h || h->version != sizeof(native_handle) || 198 | h->numInts != sNumInts || h->numFds != sNumFds || 199 | hnd->magic != sMagic) 200 | { 201 | ALOGE("invalid gralloc handle (at %p)", h); 202 | return -EINVAL; 203 | } 204 | return 0; 205 | } 206 | 207 | static private_handle_t* dynamicCast(const native_handle* in) { 208 | if (validate(in) == 0) { 209 | return (private_handle_t*) in; 210 | } 211 | return NULL; 212 | } 213 | #endif 214 | }; 215 | 216 | #endif /* GRALLOC_PRIV_H_ */ 217 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/pmemalloc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 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 | //#define LOG_NDEBUG 0 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "gralloc_priv.h" 32 | #include "pmemalloc.h" 33 | 34 | 35 | #define BEGIN_FUNC ALOGV("%s begin", __PRETTY_FUNCTION__) 36 | #define END_FUNC ALOGV("%s end", __PRETTY_FUNCTION__) 37 | 38 | 39 | static int get_open_flags(int usage) { 40 | int openFlags = O_RDWR | O_SYNC; 41 | uint32_t uread = usage & GRALLOC_USAGE_SW_READ_MASK; 42 | uint32_t uwrite = usage & GRALLOC_USAGE_SW_WRITE_MASK; 43 | if (uread == GRALLOC_USAGE_SW_READ_OFTEN || 44 | uwrite == GRALLOC_USAGE_SW_WRITE_OFTEN) { 45 | openFlags &= ~O_SYNC; 46 | } 47 | return openFlags; 48 | } 49 | 50 | PmemAllocator::~PmemAllocator() 51 | { 52 | BEGIN_FUNC; 53 | END_FUNC; 54 | } 55 | 56 | 57 | PmemUserspaceAllocator::PmemUserspaceAllocator(Deps& deps, Deps::Allocator& allocator, const char* pmemdev): 58 | deps(deps), 59 | allocator(allocator), 60 | pmemdev(pmemdev), 61 | master_fd(MASTER_FD_INIT) 62 | { 63 | BEGIN_FUNC; 64 | pthread_mutex_init(&lock, NULL); 65 | END_FUNC; 66 | } 67 | 68 | 69 | PmemUserspaceAllocator::~PmemUserspaceAllocator() 70 | { 71 | BEGIN_FUNC; 72 | END_FUNC; 73 | } 74 | 75 | 76 | void* PmemUserspaceAllocator::get_base_address() { 77 | BEGIN_FUNC; 78 | END_FUNC; 79 | return master_base; 80 | } 81 | 82 | 83 | int PmemUserspaceAllocator::init_pmem_area_locked() 84 | { 85 | BEGIN_FUNC; 86 | int err = 0; 87 | int fd = deps.open(pmemdev, O_RDWR, 0); 88 | if (fd >= 0) { 89 | size_t size = 0; 90 | err = deps.getPmemTotalSize(fd, &size); 91 | if (err < 0) { 92 | ALOGE("%s: PMEM_GET_TOTAL_SIZE failed (%d), limp mode", pmemdev, 93 | err); 94 | size = 8<<20; // 8 MiB 95 | } 96 | allocator.setSize(size); 97 | 98 | void* base = deps.mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 99 | 0); 100 | if (base == MAP_FAILED) { 101 | ALOGE("%s: failed to map pmem master fd: %s", pmemdev, 102 | strerror(deps.getErrno())); 103 | err = -deps.getErrno(); 104 | base = 0; 105 | deps.close(fd); 106 | fd = -1; 107 | } else { 108 | master_fd = fd; 109 | master_base = base; 110 | } 111 | } else { 112 | ALOGE("%s: failed to open pmem device: %s", pmemdev, 113 | strerror(deps.getErrno())); 114 | err = -deps.getErrno(); 115 | } 116 | END_FUNC; 117 | return err; 118 | } 119 | 120 | 121 | int PmemUserspaceAllocator::init_pmem_area() 122 | { 123 | BEGIN_FUNC; 124 | pthread_mutex_lock(&lock); 125 | int err = master_fd; 126 | if (err == MASTER_FD_INIT) { 127 | // first time, try to initialize pmem 128 | err = init_pmem_area_locked(); 129 | if (err) { 130 | ALOGE("%s: failed to initialize pmem area", pmemdev); 131 | master_fd = err; 132 | } 133 | } else if (err < 0) { 134 | // pmem couldn't be initialized, never use it 135 | } else { 136 | // pmem OK 137 | err = 0; 138 | } 139 | pthread_mutex_unlock(&lock); 140 | END_FUNC; 141 | return err; 142 | } 143 | 144 | 145 | int PmemUserspaceAllocator::alloc_pmem_buffer(size_t size, int usage, 146 | void** pBase, int* pOffset, int* pFd, int format) 147 | { 148 | BEGIN_FUNC; 149 | int err = init_pmem_area(); 150 | if (err == 0) { 151 | void* base = master_base; 152 | int offset = allocator.allocate(size); 153 | if (offset < 0) { 154 | // no more pmem memory 155 | ALOGE("%s: no more pmem available", pmemdev); 156 | err = -ENOMEM; 157 | } else { 158 | int openFlags = get_open_flags(usage); 159 | 160 | //ALOGD("%s: allocating pmem at offset 0x%p", pmemdev, offset); 161 | 162 | // now create the "sub-heap" 163 | int fd = deps.open(pmemdev, openFlags, 0); 164 | err = fd < 0 ? fd : 0; 165 | 166 | // and connect to it 167 | if (err == 0) 168 | err = deps.connectPmem(fd, master_fd); 169 | 170 | // and make it available to the client process 171 | if (err == 0) 172 | err = deps.mapPmem(fd, offset, size); 173 | 174 | if (err < 0) { 175 | ALOGE("%s: failed to initialize pmem sub-heap: %d", pmemdev, 176 | err); 177 | err = -deps.getErrno(); 178 | deps.close(fd); 179 | allocator.deallocate(offset); 180 | fd = -1; 181 | } else { 182 | ALOGV("%s: mapped fd %d at offset %d, size %d", pmemdev, fd, offset, size); 183 | memset((char*)base + offset, 0, size); 184 | //Clean cache before flushing to ensure pmem is properly flushed 185 | err = deps.cleanPmem(fd, (unsigned long) base + offset, offset, size); 186 | if (err < 0) { 187 | LOGE("cleanPmem failed: (%s)", strerror(deps.getErrno())); 188 | } 189 | #ifdef HOST 190 | cacheflush(intptr_t(base) + offset, intptr_t(base) + offset + size, 0); 191 | #endif 192 | *pBase = base; 193 | *pOffset = offset; 194 | *pFd = fd; 195 | } 196 | //ALOGD_IF(!err, "%s: allocating pmem size=%d, offset=%d", pmemdev, size, offset); 197 | } 198 | } 199 | END_FUNC; 200 | return err; 201 | } 202 | 203 | 204 | int PmemUserspaceAllocator::free_pmem_buffer(size_t size, void* base, int offset, int fd) 205 | { 206 | BEGIN_FUNC; 207 | int err = 0; 208 | if (fd >= 0) { 209 | int err = deps.unmapPmem(fd, offset, size); 210 | ALOGE_IF(err<0, "PMEM_UNMAP failed (%s), fd=%d, sub.offset=%u, " 211 | "sub.size=%u", strerror(deps.getErrno()), fd, offset, size); 212 | if (err == 0) { 213 | // we can't deallocate the memory in case of UNMAP failure 214 | // because it would give that process access to someone else's 215 | // surfaces, which would be a security breach. 216 | allocator.deallocate(offset); 217 | } 218 | } 219 | END_FUNC; 220 | return err; 221 | } 222 | 223 | PmemUserspaceAllocator::Deps::Allocator::~Allocator() 224 | { 225 | BEGIN_FUNC; 226 | END_FUNC; 227 | } 228 | 229 | PmemUserspaceAllocator::Deps::~Deps() 230 | { 231 | BEGIN_FUNC; 232 | END_FUNC; 233 | } 234 | 235 | PmemKernelAllocator::PmemKernelAllocator(Deps& deps): 236 | deps(deps) 237 | { 238 | BEGIN_FUNC; 239 | END_FUNC; 240 | } 241 | 242 | 243 | PmemKernelAllocator::~PmemKernelAllocator() 244 | { 245 | BEGIN_FUNC; 246 | END_FUNC; 247 | } 248 | 249 | 250 | void* PmemKernelAllocator::get_base_address() { 251 | BEGIN_FUNC; 252 | END_FUNC; 253 | return 0; 254 | } 255 | 256 | 257 | static unsigned clp2(unsigned x) { 258 | x = x - 1; 259 | x = x | (x >> 1); 260 | x = x | (x >> 2); 261 | x = x | (x >> 4); 262 | x = x | (x >> 8); 263 | x = x | (x >>16); 264 | return x + 1; 265 | } 266 | 267 | 268 | int PmemKernelAllocator::alloc_pmem_buffer(size_t size, int usage, 269 | void** pBase,int* pOffset, int* pFd, int format) 270 | { 271 | BEGIN_FUNC; 272 | 273 | *pBase = 0; 274 | *pOffset = 0; 275 | *pFd = -1; 276 | 277 | int err, offset = 0; 278 | int openFlags = get_open_flags(usage); 279 | const char *device; 280 | 281 | if (usage & GRALLOC_USAGE_PRIVATE_PMEM_ADSP) { 282 | device = DEVICE_PMEM_ADSP; 283 | } else if (usage & GRALLOC_USAGE_PRIVATE_PMEM_SMIPOOL) { 284 | device = DEVICE_PMEM_SMIPOOL; 285 | } else if ((usage & GRALLOC_USAGE_EXTERNAL_DISP) || 286 | (usage & GRALLOC_USAGE_PROTECTED)) { 287 | int tempFd = deps.open(DEVICE_PMEM_SMIPOOL, openFlags, 0); 288 | if (tempFd < 0) { 289 | device = DEVICE_PMEM_ADSP; 290 | } else { 291 | close(tempFd); 292 | device = DEVICE_PMEM_SMIPOOL; 293 | } 294 | } else { 295 | LOGE("Invalid device"); 296 | return -EINVAL; 297 | } 298 | 299 | int fd = deps.open(device, openFlags, 0); 300 | if (fd < 0) { 301 | err = -deps.getErrno(); 302 | END_FUNC; 303 | LOGE("Error opening %s", device); 304 | return err; 305 | } 306 | 307 | // The size should already be page aligned, now round it up to a power of 2. 308 | //size = clp2(size); 309 | 310 | if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) { 311 | // Tile format buffers need physical alignment to 8K 312 | err = deps.alignPmem(fd, size, 8192); 313 | if (err < 0) { 314 | LOGE("alignPmem failed"); 315 | } 316 | } 317 | 318 | void* base = deps.mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 319 | if (base == MAP_FAILED) { 320 | ALOGE("%s: failed to map pmem fd: %s", device, 321 | strerror(deps.getErrno())); 322 | err = -deps.getErrno(); 323 | deps.close(fd); 324 | END_FUNC; 325 | return err; 326 | } 327 | 328 | memset(base, 0, size); 329 | 330 | *pBase = base; 331 | *pOffset = 0; 332 | *pFd = fd; 333 | 334 | END_FUNC; 335 | return 0; 336 | } 337 | 338 | 339 | int PmemKernelAllocator::free_pmem_buffer(size_t size, void* base, int offset, int fd) 340 | { 341 | BEGIN_FUNC; 342 | // The size should already be page aligned, now round it up to a power of 2 343 | // like we did when allocating. 344 | //size = clp2(size); 345 | 346 | int err = deps.munmap(base, size); 347 | if (err < 0) { 348 | err = deps.getErrno(); 349 | ALOGW("error unmapping pmem fd: %s", strerror(err)); 350 | return -err; 351 | } 352 | END_FUNC; 353 | return 0; 354 | } 355 | 356 | PmemKernelAllocator::Deps::~Deps() 357 | { 358 | BEGIN_FUNC; 359 | END_FUNC; 360 | } 361 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/pmemalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 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 | #ifndef GRALLOC_QSD8K_PMEMALLOC_H 18 | #define GRALLOC_QSD8K_PMEMALLOC_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | /** 27 | * An interface to the PMEM allocators. 28 | */ 29 | class PmemAllocator { 30 | 31 | public: 32 | 33 | virtual ~PmemAllocator(); 34 | 35 | // Only valid after init_pmem_area() has completed successfully. 36 | virtual void* get_base_address() = 0; 37 | 38 | virtual int alloc_pmem_buffer(size_t size, int usage, void** pBase, 39 | int* pOffset, int* pFd, int format) = 0; 40 | virtual int free_pmem_buffer(size_t size, void* base, int offset, int fd) = 0; 41 | }; 42 | 43 | 44 | /** 45 | * A PMEM allocator that allocates the entire pmem memory from the kernel and 46 | * then uses a user-space allocator to suballocate from that. This requires 47 | * that the PMEM device driver have kernel allocation disabled. 48 | */ 49 | class PmemUserspaceAllocator: public PmemAllocator { 50 | 51 | public: 52 | 53 | class Deps { 54 | public: 55 | 56 | class Allocator { 57 | public: 58 | virtual ~Allocator(); 59 | virtual ssize_t setSize(size_t size) = 0; 60 | virtual size_t size() const = 0; 61 | virtual ssize_t allocate(size_t size, uint32_t flags = 0) = 0; 62 | virtual ssize_t deallocate(size_t offset) = 0; 63 | }; 64 | 65 | virtual ~Deps(); 66 | 67 | // pmem 68 | virtual size_t getPmemTotalSize(int fd, size_t* size) = 0; 69 | virtual int connectPmem(int fd, int master_fd) = 0; 70 | virtual int mapPmem(int fd, int offset, size_t size) = 0; 71 | virtual int unmapPmem(int fd, int offset, size_t size) = 0; 72 | virtual int cleanPmem(int fd, unsigned long base, int offset, size_t size) = 0; 73 | 74 | // C99 75 | virtual int getErrno() = 0; 76 | 77 | // POSIX 78 | virtual void* mmap(void* start, size_t length, int prot, int flags, int fd, 79 | off_t offset) = 0; 80 | virtual int open(const char* pathname, int flags, int mode) = 0; 81 | virtual int close(int fd) = 0; 82 | }; 83 | 84 | PmemUserspaceAllocator(Deps& deps, Deps::Allocator& allocator, const char* pmemdev); 85 | virtual ~PmemUserspaceAllocator(); 86 | 87 | // Only valid after init_pmem_area() has completed successfully. 88 | virtual void* get_base_address(); 89 | 90 | virtual int init_pmem_area_locked(); 91 | virtual int init_pmem_area(); 92 | virtual int alloc_pmem_buffer(size_t size, int usage, void** pBase, 93 | int* pOffset, int* pFd, int format); 94 | virtual int free_pmem_buffer(size_t size, void* base, int offset, int fd); 95 | 96 | #ifndef ANDROID_OS 97 | // DO NOT USE: For testing purposes only. 98 | void set_master_values(int fd, void* base) { 99 | master_fd = fd; 100 | master_base = base; 101 | } 102 | #endif // ANDROID_OS 103 | 104 | private: 105 | 106 | enum { 107 | MASTER_FD_INIT = -1, 108 | }; 109 | 110 | Deps& deps; 111 | Deps::Allocator& allocator; 112 | 113 | pthread_mutex_t lock; 114 | const char* pmemdev; 115 | int master_fd; 116 | void* master_base; 117 | }; 118 | 119 | 120 | /** 121 | * A PMEM allocator that allocates each individual allocation from the kernel 122 | * (using the kernel's allocator). This requires the kernel driver for the 123 | * particular PMEM device being allocated from to support kernel allocation. 124 | */ 125 | class PmemKernelAllocator: public PmemAllocator { 126 | 127 | public: 128 | 129 | class Deps { 130 | public: 131 | 132 | virtual ~Deps(); 133 | 134 | // C99 135 | virtual int getErrno() = 0; 136 | 137 | // POSIX 138 | virtual void* mmap(void* start, size_t length, int prot, int flags, int fd, 139 | off_t offset) = 0; 140 | virtual int munmap(void* start, size_t length) = 0; 141 | virtual int open(const char* pathname, int flags, int mode) = 0; 142 | virtual int close(int fd) = 0; 143 | virtual int alignPmem(int fd, size_t size, int align) = 0; 144 | }; 145 | 146 | PmemKernelAllocator(Deps& deps); 147 | virtual ~PmemKernelAllocator(); 148 | 149 | // Only valid after init_pmem_area() has completed successfully. 150 | virtual void* get_base_address(); 151 | 152 | virtual int alloc_pmem_buffer(size_t size, int usage, void** pBase, 153 | int* pOffset, int* pFd, int format); 154 | virtual int free_pmem_buffer(size_t size, void* base, int offset, int fd); 155 | 156 | private: 157 | 158 | Deps& deps; 159 | }; 160 | 161 | #endif // GRALLOC_QSD8K_PMEMALLOC_H 162 | -------------------------------------------------------------------------------- /libgralloc-qsd8k/tests/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | # you can use EXTRA_CFLAGS to indicate additional CFLAGS to use 18 | # in the build. The variables will be cleaned on exit 19 | # 20 | # 21 | 22 | libgralloc_test_includes:= \ 23 | bionic/libstdc++/include \ 24 | external/astl/include \ 25 | external/gtest/include \ 26 | $(LOCAL_PATH)/.. 27 | 28 | libgralloc_test_static_libs := \ 29 | libgralloc_qsd8k_host \ 30 | libgtest_main_host \ 31 | libgtest_host \ 32 | libastl_host \ 33 | liblog 34 | 35 | define host-test 36 | $(foreach file,$(1), \ 37 | $(eval include $(CLEAR_VARS)) \ 38 | $(eval LOCAL_CPP_EXTENSION := .cpp) \ 39 | $(eval LOCAL_SRC_FILES := $(file)) \ 40 | $(eval LOCAL_C_INCLUDES := $(libgralloc_test_includes)) \ 41 | $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ 42 | $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \ 43 | $(eval LOCAL_LDLIBS += $(EXTRA_LDLIBS)) \ 44 | $(eval LOCAL_STATIC_LIBRARIES := $(libgralloc_test_static_libs)) \ 45 | $(eval include $(BUILD_HOST_EXECUTABLE)) \ 46 | ) \ 47 | $(eval EXTRA_CFLAGS :=) \ 48 | $(eval EXTRA_LDLIBS :=) 49 | endef 50 | 51 | TEST_SRC_FILES := \ 52 | pmemalloc_test.cpp 53 | 54 | $(call host-test, $(TEST_SRC_FILES)) 55 | -------------------------------------------------------------------------------- /libgralloc/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | LOCAL_PATH := $(call my-dir) 17 | 18 | # HAL module implemenation stored in 19 | # hw/..so 20 | include $(CLEAR_VARS) 21 | 22 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 23 | LOCAL_SHARED_LIBRARIES := liblog libcutils 24 | 25 | LOCAL_SRC_FILES := \ 26 | allocator.cpp \ 27 | gralloc.cpp \ 28 | framebuffer.cpp \ 29 | mapper.cpp 30 | 31 | LOCAL_MODULE := gralloc.msm7k 32 | LOCAL_MODULE_TAGS := optional 33 | LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\" 34 | include $(BUILD_SHARED_LIBRARY) 35 | -------------------------------------------------------------------------------- /libgralloc/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/libgralloc/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /libgralloc/allocator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 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 | #include 18 | 19 | #include "allocator.h" 20 | 21 | 22 | // align all the memory blocks on a cache-line boundary 23 | const int SimpleBestFitAllocator::kMemoryAlign = 32; 24 | 25 | SimpleBestFitAllocator::SimpleBestFitAllocator() 26 | : mHeapSize(0) 27 | { 28 | } 29 | 30 | SimpleBestFitAllocator::SimpleBestFitAllocator(size_t size) 31 | : mHeapSize(0) 32 | { 33 | setSize(size); 34 | } 35 | 36 | SimpleBestFitAllocator::~SimpleBestFitAllocator() 37 | { 38 | while(!mList.isEmpty()) { 39 | delete mList.remove(mList.head()); 40 | } 41 | } 42 | 43 | ssize_t SimpleBestFitAllocator::setSize(size_t size) 44 | { 45 | Locker::Autolock _l(mLock); 46 | if (mHeapSize != 0) return -EINVAL; 47 | size_t pagesize = getpagesize(); 48 | mHeapSize = ((size + pagesize-1) & ~(pagesize-1)); 49 | chunk_t* node = new chunk_t(0, mHeapSize / kMemoryAlign); 50 | mList.insertHead(node); 51 | return size; 52 | } 53 | 54 | 55 | size_t SimpleBestFitAllocator::size() const 56 | { 57 | return mHeapSize; 58 | } 59 | 60 | ssize_t SimpleBestFitAllocator::allocate(size_t size, uint32_t flags) 61 | { 62 | Locker::Autolock _l(mLock); 63 | if (mHeapSize == 0) return -EINVAL; 64 | ssize_t offset = alloc(size, flags); 65 | return offset; 66 | } 67 | 68 | ssize_t SimpleBestFitAllocator::deallocate(size_t offset) 69 | { 70 | Locker::Autolock _l(mLock); 71 | if (mHeapSize == 0) return -EINVAL; 72 | chunk_t const * const freed = dealloc(offset); 73 | if (freed) { 74 | return 0; 75 | } 76 | return -ENOENT; 77 | } 78 | 79 | ssize_t SimpleBestFitAllocator::alloc(size_t size, uint32_t flags) 80 | { 81 | if (size == 0) { 82 | return 0; 83 | } 84 | size = (size + kMemoryAlign-1) / kMemoryAlign; 85 | chunk_t* free_chunk = 0; 86 | chunk_t* cur = mList.head(); 87 | 88 | size_t pagesize = getpagesize(); 89 | while (cur) { 90 | int extra = ( -cur->start & ((pagesize/kMemoryAlign)-1) ) ; 91 | 92 | // best fit 93 | if (cur->free && (cur->size >= (size+extra))) { 94 | if ((!free_chunk) || (cur->size < free_chunk->size)) { 95 | free_chunk = cur; 96 | } 97 | if (cur->size == size) { 98 | break; 99 | } 100 | } 101 | cur = cur->next; 102 | } 103 | 104 | if (free_chunk) { 105 | const size_t free_size = free_chunk->size; 106 | free_chunk->free = 0; 107 | free_chunk->size = size; 108 | if (free_size > size) { 109 | int extra = ( -free_chunk->start & ((pagesize/kMemoryAlign)-1) ) ; 110 | if (extra) { 111 | chunk_t* split = new chunk_t(free_chunk->start, extra); 112 | free_chunk->start += extra; 113 | mList.insertBefore(free_chunk, split); 114 | } 115 | 116 | ALOGE_IF(((free_chunk->start*kMemoryAlign)&(pagesize-1)), 117 | "page is not aligned!!!"); 118 | 119 | const ssize_t tail_free = free_size - (size+extra); 120 | if (tail_free > 0) { 121 | chunk_t* split = new chunk_t( 122 | free_chunk->start + free_chunk->size, tail_free); 123 | mList.insertAfter(free_chunk, split); 124 | } 125 | } 126 | return (free_chunk->start)*kMemoryAlign; 127 | } 128 | return -ENOMEM; 129 | } 130 | 131 | SimpleBestFitAllocator::chunk_t* SimpleBestFitAllocator::dealloc(size_t start) 132 | { 133 | start = start / kMemoryAlign; 134 | chunk_t* cur = mList.head(); 135 | while (cur) { 136 | if (cur->start == start) { 137 | LOG_FATAL_IF(cur->free, 138 | "block at offset 0x%08lX of size 0x%08lX already freed", 139 | cur->start*kMemoryAlign, cur->size*kMemoryAlign); 140 | 141 | // merge freed blocks together 142 | chunk_t* freed = cur; 143 | cur->free = 1; 144 | do { 145 | chunk_t* const p = cur->prev; 146 | chunk_t* const n = cur->next; 147 | if (p && (p->free || !cur->size)) { 148 | freed = p; 149 | p->size += cur->size; 150 | mList.remove(cur); 151 | delete cur; 152 | } 153 | cur = n; 154 | } while (cur && cur->free); 155 | 156 | LOG_FATAL_IF(!freed->free, 157 | "freed block at offset 0x%08lX of size 0x%08lX is not free!", 158 | freed->start * kMemoryAlign, freed->size * kMemoryAlign); 159 | 160 | return freed; 161 | } 162 | cur = cur->next; 163 | } 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /libgralloc/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 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 | #ifndef GRALLOC_ALLOCATOR_H_ 19 | #define GRALLOC_ALLOCATOR_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "gr.h" 25 | 26 | // ---------------------------------------------------------------------------- 27 | 28 | /* 29 | * A simple templatized doubly linked-list implementation 30 | */ 31 | 32 | template 33 | class LinkedList 34 | { 35 | NODE* mFirst; 36 | NODE* mLast; 37 | 38 | public: 39 | LinkedList() : mFirst(0), mLast(0) { } 40 | bool isEmpty() const { return mFirst == 0; } 41 | NODE const* head() const { return mFirst; } 42 | NODE* head() { return mFirst; } 43 | NODE const* tail() const { return mLast; } 44 | NODE* tail() { return mLast; } 45 | 46 | void insertAfter(NODE* node, NODE* newNode) { 47 | newNode->prev = node; 48 | newNode->next = node->next; 49 | if (node->next == 0) mLast = newNode; 50 | else node->next->prev = newNode; 51 | node->next = newNode; 52 | } 53 | 54 | void insertBefore(NODE* node, NODE* newNode) { 55 | newNode->prev = node->prev; 56 | newNode->next = node; 57 | if (node->prev == 0) mFirst = newNode; 58 | else node->prev->next = newNode; 59 | node->prev = newNode; 60 | } 61 | 62 | void insertHead(NODE* newNode) { 63 | if (mFirst == 0) { 64 | mFirst = mLast = newNode; 65 | newNode->prev = newNode->next = 0; 66 | } else { 67 | newNode->prev = 0; 68 | newNode->next = mFirst; 69 | mFirst->prev = newNode; 70 | mFirst = newNode; 71 | } 72 | } 73 | 74 | void insertTail(NODE* newNode) { 75 | if (mLast == 0) { 76 | insertHead(newNode); 77 | } else { 78 | newNode->prev = mLast; 79 | newNode->next = 0; 80 | mLast->next = newNode; 81 | mLast = newNode; 82 | } 83 | } 84 | 85 | NODE* remove(NODE* node) { 86 | if (node->prev == 0) mFirst = node->next; 87 | else node->prev->next = node->next; 88 | if (node->next == 0) mLast = node->prev; 89 | else node->next->prev = node->prev; 90 | return node; 91 | } 92 | }; 93 | 94 | class SimpleBestFitAllocator 95 | { 96 | public: 97 | 98 | SimpleBestFitAllocator(); 99 | SimpleBestFitAllocator(size_t size); 100 | ~SimpleBestFitAllocator(); 101 | 102 | ssize_t setSize(size_t size); 103 | 104 | ssize_t allocate(size_t size, uint32_t flags = 0); 105 | ssize_t deallocate(size_t offset); 106 | size_t size() const; 107 | 108 | private: 109 | struct chunk_t { 110 | chunk_t(size_t start, size_t size) 111 | : start(start), size(size), free(1), prev(0), next(0) { 112 | } 113 | size_t start; 114 | size_t size : 28; 115 | int free : 4; 116 | mutable chunk_t* prev; 117 | mutable chunk_t* next; 118 | }; 119 | 120 | ssize_t alloc(size_t size, uint32_t flags); 121 | chunk_t* dealloc(size_t start); 122 | 123 | static const int kMemoryAlign; 124 | mutable Locker mLock; 125 | LinkedList mList; 126 | size_t mHeapSize; 127 | }; 128 | 129 | #endif /* GRALLOC_ALLOCATOR_H_ */ 130 | -------------------------------------------------------------------------------- /libgralloc/gr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 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 | #ifndef GR_H_ 18 | #define GR_H_ 19 | 20 | #include 21 | #ifdef HAVE_ANDROID_OS // just want PAGE_SIZE define 22 | # include 23 | #else 24 | # include 25 | #endif 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | /*****************************************************************************/ 35 | 36 | struct private_module_t; 37 | struct private_handle_t; 38 | 39 | inline size_t roundUpToPageSize(size_t x) { 40 | return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); 41 | } 42 | 43 | int mapFrameBufferLocked(struct private_module_t* module); 44 | int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd); 45 | int mapBuffer(gralloc_module_t const* module, private_handle_t* hnd); 46 | 47 | /*****************************************************************************/ 48 | 49 | class Locker { 50 | pthread_mutex_t mutex; 51 | public: 52 | class Autolock { 53 | Locker& locker; 54 | public: 55 | inline Autolock(Locker& locker) : locker(locker) { locker.lock(); } 56 | inline ~Autolock() { locker.unlock(); } 57 | }; 58 | inline Locker() { pthread_mutex_init(&mutex, 0); } 59 | inline ~Locker() { pthread_mutex_destroy(&mutex); } 60 | inline void lock() { pthread_mutex_lock(&mutex); } 61 | inline void unlock() { pthread_mutex_unlock(&mutex); } 62 | }; 63 | 64 | #endif /* GR_H_ */ 65 | -------------------------------------------------------------------------------- /libgralloc/gralloc_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 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 | #ifndef GRALLOC_PRIV_H_ 18 | #define GRALLOC_PRIV_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | /*****************************************************************************/ 33 | 34 | struct private_module_t; 35 | struct private_handle_t; 36 | 37 | struct private_module_t { 38 | gralloc_module_t base; 39 | 40 | struct private_handle_t* framebuffer; 41 | uint32_t flags; 42 | uint32_t numBuffers; 43 | uint32_t bufferMask; 44 | pthread_mutex_t lock; 45 | buffer_handle_t currentBuffer; 46 | int pmem_master; 47 | void* pmem_master_base; 48 | unsigned long master_phys; 49 | int gpu; 50 | void* gpu_base; 51 | int fb_map_offset; 52 | 53 | struct fb_var_screeninfo info; 54 | struct fb_fix_screeninfo finfo; 55 | float xdpi; 56 | float ydpi; 57 | float fps; 58 | }; 59 | 60 | /*****************************************************************************/ 61 | 62 | #ifdef __cplusplus 63 | struct private_handle_t : public native_handle { 64 | #else 65 | struct private_handle_t { 66 | native_handle_t nativeHandle; 67 | #endif 68 | 69 | enum { 70 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, 71 | PRIV_FLAGS_USES_PMEM = 0x00000002, 72 | PRIV_FLAGS_USES_GPU = 0x00000004, 73 | }; 74 | 75 | // file-descriptors 76 | int fd; 77 | // ints 78 | int magic; 79 | int flags; 80 | int size; 81 | int offset; 82 | int gpu_fd; // stored as an int, b/c we don't want it marshalled 83 | 84 | // FIXME: the attributes below should be out-of-line 85 | int base; 86 | int map_offset; 87 | int pid; 88 | 89 | #ifdef __cplusplus 90 | static const int sNumInts = 8; 91 | static const int sNumFds = 1; 92 | static const int sMagic = 'gmsm'; 93 | 94 | private_handle_t(int fd, int size, int flags) : 95 | fd(fd), magic(sMagic), flags(flags), size(size), offset(0), 96 | base(0), pid(getpid()) 97 | { 98 | version = sizeof(native_handle); 99 | numInts = sNumInts; 100 | numFds = sNumFds; 101 | } 102 | ~private_handle_t() { 103 | magic = 0; 104 | } 105 | 106 | static int validate(const native_handle* h) { 107 | const private_handle_t* hnd = (const private_handle_t*)h; 108 | if (!h || h->version != sizeof(native_handle) || 109 | h->numInts != sNumInts || h->numFds != sNumFds || 110 | hnd->magic != sMagic) 111 | { 112 | ALOGE("invalid gralloc handle (at %p)", h); 113 | return -EINVAL; 114 | } 115 | return 0; 116 | } 117 | #endif 118 | }; 119 | 120 | #endif /* GRALLOC_PRIV_H_ */ 121 | -------------------------------------------------------------------------------- /libgralloc/mapper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 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 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | #include "gralloc_priv.h" 38 | 39 | 40 | // we need this for now because pmem cannot mmap at an offset 41 | #define PMEM_HACK 1 42 | 43 | /* desktop Linux needs a little help with gettid() */ 44 | #if defined(ARCH_X86) && !defined(HAVE_ANDROID_OS) 45 | #define __KERNEL__ 46 | # include 47 | pid_t gettid() { return syscall(__NR_gettid);} 48 | #undef __KERNEL__ 49 | #endif 50 | 51 | /*****************************************************************************/ 52 | 53 | static int gralloc_map(gralloc_module_t const* module, 54 | buffer_handle_t handle, 55 | void** vaddr) 56 | { 57 | private_handle_t* hnd = (private_handle_t*)handle; 58 | if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) { 59 | size_t size = hnd->size; 60 | #if PMEM_HACK 61 | size += hnd->offset; 62 | #endif 63 | void* mappedAddress = mmap(0, size, 64 | PROT_READ|PROT_WRITE, MAP_SHARED, hnd->fd, 0); 65 | if (mappedAddress == MAP_FAILED) { 66 | ALOGE("Could not mmap handle %p, fd=%d (%s)", 67 | handle, hnd->fd, strerror(errno)); 68 | hnd->base = 0; 69 | return -errno; 70 | } 71 | hnd->base = intptr_t(mappedAddress) + hnd->offset; 72 | //ALOGD("gralloc_map() succeeded fd=%d, off=%d, size=%d, vaddr=%p", 73 | // hnd->fd, hnd->offset, hnd->size, mappedAddress); 74 | } 75 | *vaddr = (void*)hnd->base; 76 | return 0; 77 | } 78 | 79 | static int gralloc_unmap(gralloc_module_t const* module, 80 | buffer_handle_t handle) 81 | { 82 | private_handle_t* hnd = (private_handle_t*)handle; 83 | if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) { 84 | void* base = (void*)hnd->base; 85 | size_t size = hnd->size; 86 | #if PMEM_HACK 87 | base = (void*)(intptr_t(base) - hnd->offset); 88 | size += hnd->offset; 89 | #endif 90 | //ALOGD("unmapping from %p, size=%d, flags=%08x", base, size, hnd->flags); 91 | if (munmap(base, size) < 0) { 92 | ALOGE("Could not unmap %s", strerror(errno)); 93 | } 94 | } 95 | hnd->base = 0; 96 | return 0; 97 | } 98 | 99 | /*****************************************************************************/ 100 | 101 | static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER; 102 | 103 | /*****************************************************************************/ 104 | 105 | int gralloc_register_buffer(gralloc_module_t const* module, 106 | buffer_handle_t handle) 107 | { 108 | if (private_handle_t::validate(handle) < 0) 109 | return -EINVAL; 110 | 111 | // if this handle was created in this process, then we keep it as is. 112 | int err = 0; 113 | private_handle_t* hnd = (private_handle_t*)handle; 114 | if (hnd->pid != getpid()) { 115 | hnd->base = NULL; 116 | if (!(hnd->flags & private_handle_t::PRIV_FLAGS_USES_GPU)) { 117 | void *vaddr; 118 | err = gralloc_map(module, handle, &vaddr); 119 | } 120 | } 121 | return err; 122 | } 123 | 124 | int gralloc_unregister_buffer(gralloc_module_t const* module, 125 | buffer_handle_t handle) 126 | { 127 | if (private_handle_t::validate(handle) < 0) 128 | return -EINVAL; 129 | 130 | // never unmap buffers that were created in this process 131 | private_handle_t* hnd = (private_handle_t*)handle; 132 | if (hnd->pid != getpid()) { 133 | if (hnd->base) { 134 | gralloc_unmap(module, handle); 135 | } 136 | } 137 | return 0; 138 | } 139 | 140 | int mapBuffer(gralloc_module_t const* module, 141 | private_handle_t* hnd) 142 | { 143 | void* vaddr; 144 | return gralloc_map(module, hnd, &vaddr); 145 | } 146 | 147 | int terminateBuffer(gralloc_module_t const* module, 148 | private_handle_t* hnd) 149 | { 150 | if (hnd->base) { 151 | // this buffer was mapped, unmap it now 152 | if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_PMEM) { 153 | if (hnd->pid != getpid()) { 154 | // ... unless it's a "master" pmem buffer, that is a buffer 155 | // mapped in the process it's been allocated. 156 | // (see gralloc_alloc_buffer()) 157 | gralloc_unmap(module, hnd); 158 | } 159 | } else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_GPU) { 160 | // XXX: for now do nothing here 161 | } else { 162 | gralloc_unmap(module, hnd); 163 | } 164 | } 165 | 166 | return 0; 167 | } 168 | 169 | int gralloc_lock(gralloc_module_t const* module, 170 | buffer_handle_t handle, int usage, 171 | int l, int t, int w, int h, 172 | void** vaddr) 173 | { 174 | // this is called when a buffer is being locked for software 175 | // access. in thin implementation we have nothing to do since 176 | // not synchronization with the h/w is needed. 177 | // typically this is used to wait for the h/w to finish with 178 | // this buffer if relevant. the data cache may need to be 179 | // flushed or invalidated depending on the usage bits and the 180 | // hardware. 181 | 182 | if (private_handle_t::validate(handle) < 0) 183 | return -EINVAL; 184 | 185 | private_handle_t* hnd = (private_handle_t*)handle; 186 | *vaddr = (void*)hnd->base; 187 | return 0; 188 | } 189 | 190 | int gralloc_unlock(gralloc_module_t const* module, 191 | buffer_handle_t handle) 192 | { 193 | // we're done with a software buffer. nothing to do in this 194 | // implementation. typically this is used to flush the data cache. 195 | 196 | if (private_handle_t::validate(handle) < 0) 197 | return -EINVAL; 198 | return 0; 199 | } 200 | 201 | 202 | /*****************************************************************************/ 203 | 204 | int gralloc_perform(struct gralloc_module_t const* module, 205 | int operation, ... ) 206 | { 207 | int res = -EINVAL; 208 | return res; 209 | } 210 | -------------------------------------------------------------------------------- /liblights/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | LOCAL_PATH:= $(call my-dir) 17 | # HAL module implemenation stored in 18 | # hw/..so 19 | include $(CLEAR_VARS) 20 | 21 | LOCAL_SRC_FILES := lights.c 22 | 23 | 24 | LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw 25 | 26 | LOCAL_SHARED_LIBRARIES := liblog 27 | 28 | LOCAL_MODULE := lights.$(TARGET_BOARD_PLATFORM) 29 | 30 | LOCAL_MODULE_TAGS := optional 31 | 32 | include $(BUILD_SHARED_LIBRARY) 33 | -------------------------------------------------------------------------------- /liblights/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/liblights/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /liblights/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2008, The Android Open Source Project 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 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | 13 | 14 | Apache License 15 | Version 2.0, January 2004 16 | http://www.apache.org/licenses/ 17 | 18 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 19 | 20 | 1. Definitions. 21 | 22 | "License" shall mean the terms and conditions for use, reproduction, 23 | and distribution as defined by Sections 1 through 9 of this document. 24 | 25 | "Licensor" shall mean the copyright owner or entity authorized by 26 | the copyright owner that is granting the License. 27 | 28 | "Legal Entity" shall mean the union of the acting entity and all 29 | other entities that control, are controlled by, or are under common 30 | control with that entity. For the purposes of this definition, 31 | "control" means (i) the power, direct or indirect, to cause the 32 | direction or management of such entity, whether by contract or 33 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 34 | outstanding shares, or (iii) beneficial ownership of such entity. 35 | 36 | "You" (or "Your") shall mean an individual or Legal Entity 37 | exercising permissions granted by this License. 38 | 39 | "Source" form shall mean the preferred form for making modifications, 40 | including but not limited to software source code, documentation 41 | source, and configuration files. 42 | 43 | "Object" form shall mean any form resulting from mechanical 44 | transformation or translation of a Source form, including but 45 | not limited to compiled object code, generated documentation, 46 | and conversions to other media types. 47 | 48 | "Work" shall mean the work of authorship, whether in Source or 49 | Object form, made available under the License, as indicated by a 50 | copyright notice that is included in or attached to the work 51 | (an example is provided in the Appendix below). 52 | 53 | "Derivative Works" shall mean any work, whether in Source or Object 54 | form, that is based on (or derived from) the Work and for which the 55 | editorial revisions, annotations, elaborations, or other modifications 56 | represent, as a whole, an original work of authorship. For the purposes 57 | of this License, Derivative Works shall not include works that remain 58 | separable from, or merely link (or bind by name) to the interfaces of, 59 | the Work and Derivative Works thereof. 60 | 61 | "Contribution" shall mean any work of authorship, including 62 | the original version of the Work and any modifications or additions 63 | to that Work or Derivative Works thereof, that is intentionally 64 | submitted to Licensor for inclusion in the Work by the copyright owner 65 | or by an individual or Legal Entity authorized to submit on behalf of 66 | the copyright owner. For the purposes of this definition, "submitted" 67 | means any form of electronic, verbal, or written communication sent 68 | to the Licensor or its representatives, including but not limited to 69 | communication on electronic mailing lists, source code control systems, 70 | and issue tracking systems that are managed by, or on behalf of, the 71 | Licensor for the purpose of discussing and improving the Work, but 72 | excluding communication that is conspicuously marked or otherwise 73 | designated in writing by the copyright owner as "Not a Contribution." 74 | 75 | "Contributor" shall mean Licensor and any individual or Legal Entity 76 | on behalf of whom a Contribution has been received by Licensor and 77 | subsequently incorporated within the Work. 78 | 79 | 2. Grant of Copyright License. Subject to the terms and conditions of 80 | this License, each Contributor hereby grants to You a perpetual, 81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 82 | copyright license to reproduce, prepare Derivative Works of, 83 | publicly display, publicly perform, sublicense, and distribute the 84 | Work and such Derivative Works in Source or Object form. 85 | 86 | 3. Grant of Patent License. Subject to the terms and conditions of 87 | this License, each Contributor hereby grants to You a perpetual, 88 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 89 | (except as stated in this section) patent license to make, have made, 90 | use, offer to sell, sell, import, and otherwise transfer the Work, 91 | where such license applies only to those patent claims licensable 92 | by such Contributor that are necessarily infringed by their 93 | Contribution(s) alone or by combination of their Contribution(s) 94 | with the Work to which such Contribution(s) was submitted. If You 95 | institute patent litigation against any entity (including a 96 | cross-claim or counterclaim in a lawsuit) alleging that the Work 97 | or a Contribution incorporated within the Work constitutes direct 98 | or contributory patent infringement, then any patent licenses 99 | granted to You under this License for that Work shall terminate 100 | as of the date such litigation is filed. 101 | 102 | 4. Redistribution. You may reproduce and distribute copies of the 103 | Work or Derivative Works thereof in any medium, with or without 104 | modifications, and in Source or Object form, provided that You 105 | meet the following conditions: 106 | 107 | (a) You must give any other recipients of the Work or 108 | Derivative Works a copy of this License; and 109 | 110 | (b) You must cause any modified files to carry prominent notices 111 | stating that You changed the files; and 112 | 113 | (c) You must retain, in the Source form of any Derivative Works 114 | that You distribute, all copyright, patent, trademark, and 115 | attribution notices from the Source form of the Work, 116 | excluding those notices that do not pertain to any part of 117 | the Derivative Works; and 118 | 119 | (d) If the Work includes a "NOTICE" text file as part of its 120 | distribution, then any Derivative Works that You distribute must 121 | include a readable copy of the attribution notices contained 122 | within such NOTICE file, excluding those notices that do not 123 | pertain to any part of the Derivative Works, in at least one 124 | of the following places: within a NOTICE text file distributed 125 | as part of the Derivative Works; within the Source form or 126 | documentation, if provided along with the Derivative Works; or, 127 | within a display generated by the Derivative Works, if and 128 | wherever such third-party notices normally appear. The contents 129 | of the NOTICE file are for informational purposes only and 130 | do not modify the License. You may add Your own attribution 131 | notices within Derivative Works that You distribute, alongside 132 | or as an addendum to the NOTICE text from the Work, provided 133 | that such additional attribution notices cannot be construed 134 | as modifying the License. 135 | 136 | You may add Your own copyright statement to Your modifications and 137 | may provide additional or different license terms and conditions 138 | for use, reproduction, or distribution of Your modifications, or 139 | for any such Derivative Works as a whole, provided Your use, 140 | reproduction, and distribution of the Work otherwise complies with 141 | the conditions stated in this License. 142 | 143 | 5. Submission of Contributions. Unless You explicitly state otherwise, 144 | any Contribution intentionally submitted for inclusion in the Work 145 | by You to the Licensor shall be under the terms and conditions of 146 | this License, without any additional terms or conditions. 147 | Notwithstanding the above, nothing herein shall supersede or modify 148 | the terms of any separate license agreement you may have executed 149 | with Licensor regarding such Contributions. 150 | 151 | 6. Trademarks. This License does not grant permission to use the trade 152 | names, trademarks, service marks, or product names of the Licensor, 153 | except as required for reasonable and customary use in describing the 154 | origin of the Work and reproducing the content of the NOTICE file. 155 | 156 | 7. Disclaimer of Warranty. Unless required by applicable law or 157 | agreed to in writing, Licensor provides the Work (and each 158 | Contributor provides its Contributions) on an "AS IS" BASIS, 159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 160 | implied, including, without limitation, any warranties or conditions 161 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 162 | PARTICULAR PURPOSE. You are solely responsible for determining the 163 | appropriateness of using or redistributing the Work and assume any 164 | risks associated with Your exercise of permissions under this License. 165 | 166 | 8. Limitation of Liability. In no event and under no legal theory, 167 | whether in tort (including negligence), contract, or otherwise, 168 | unless required by applicable law (such as deliberate and grossly 169 | negligent acts) or agreed to in writing, shall any Contributor be 170 | liable to You for damages, including any direct, indirect, special, 171 | incidental, or consequential damages of any character arising as a 172 | result of this License or out of the use or inability to use the 173 | Work (including but not limited to damages for loss of goodwill, 174 | work stoppage, computer failure or malfunction, or any and all 175 | other commercial damages or losses), even if such Contributor 176 | has been advised of the possibility of such damages. 177 | 178 | 9. Accepting Warranty or Additional Liability. While redistributing 179 | the Work or Derivative Works thereof, You may choose to offer, 180 | and charge a fee for, acceptance of support, warranty, indemnity, 181 | or other liability obligations and/or rights consistent with this 182 | License. However, in accepting such obligations, You may act only 183 | on Your own behalf and on Your sole responsibility, not on behalf 184 | of any other Contributor, and only if You agree to indemnify, 185 | defend, and hold each Contributor harmless for any liability 186 | incurred by, or claims asserted against, such Contributor by reason 187 | of your accepting any such warranty or additional liability. 188 | 189 | END OF TERMS AND CONDITIONS 190 | 191 | -------------------------------------------------------------------------------- /librpc/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_SRC_FILES:= xdr.c rpc.c svc.c clnt.c ops.c svc_clnt_common.c 6 | 7 | LOCAL_C_INCLUDES:=$(LOCAL_PATH) 8 | 9 | LOCAL_CFLAGS:= -fno-short-enums 10 | 11 | LOCAL_CFLAGS+=-DRPC_OFFSET=0 12 | #LOCAL_CFLAGS+=-DDEBUG -DVERBOSE 13 | 14 | LOCAL_COPY_HEADERS_TO:= librpc/rpc 15 | LOCAL_COPY_HEADERS:= \ 16 | rpc/clnt.h \ 17 | rpc/pmap_clnt.h \ 18 | rpc/rpc.h \ 19 | rpc/rpc_router_ioctl.h \ 20 | rpc/svc.h \ 21 | rpc/types.h \ 22 | rpc/xdr.h 23 | 24 | LOCAL_MODULE:= librpc 25 | 26 | include $(BUILD_STATIC_LIBRARY) 27 | 28 | include $(CLEAR_VARS) 29 | LOCAL_MODULE := librpc 30 | LOCAL_SHARED_LIBRARIES := liblog libcutils 31 | LOCAL_STATIC_LIBRARIES := libpower 32 | LOCAL_WHOLE_STATIC_LIBRARIES := librpc 33 | # LOCAL_PRELINK_MODULE := false 34 | include $(BUILD_SHARED_LIBRARY) 35 | -------------------------------------------------------------------------------- /librpc/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyanogenMod/android_hardware_msm7k/82b8164aad76c45db5a0ace0c380ad220c5f0081/librpc/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /librpc/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2008, The Android Open-Source Project 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 | #ifndef DEBUG_H 18 | #define DEBUG_H 19 | 20 | #include 21 | 22 | #define LOG_TAG "RPC" 23 | #include 24 | 25 | #ifdef RPC_LOG_TO_STDOUT_ONLY 26 | #define PRINT(x...) do { \ 27 | fprintf(stdout, "%s(%d) ", __FUNCTION__, __LINE__); \ 28 | fprintf(stdout, ##x); \ 29 | } while(0) 30 | #elif defined(RPC_LOG_TO_STDOUT_AND_LOG) 31 | #define PRINT(x...) do { \ 32 | fprintf(stdout, "%s(%d) ", __FUNCTION__, __LINE__); \ 33 | fprintf(stdout, ##x); \ 34 | ALOGI(x); \ 35 | } while(0) 36 | #else 37 | #define PRINT(x...) ALOGI(x) 38 | #endif 39 | 40 | #ifdef DEBUG 41 | #define D(x...) PRINT(x...) 42 | #define LIBRPC_DEBUG(x...) do { SLOGD(x); } while(0) 43 | #else 44 | #define D(x...) do { } while(0) 45 | #define LIBRPC_DEBUG(x...) do { } while(0) 46 | #endif 47 | 48 | #ifdef VERBOSE 49 | #define V(x...) PRINT(x...) 50 | #else 51 | #define V(x...) do { } while(0) 52 | #endif 53 | 54 | #define E(x...) do { \ 55 | fprintf(stderr, "%s(%d) ", __FUNCTION__, __LINE__); \ 56 | fprintf(stderr, ##x); \ 57 | ALOGE(x); \ 58 | } while(0) 59 | 60 | #define FAILIF(cond, msg...) do { \ 61 | if (__builtin_expect (cond, 0)) { \ 62 | fprintf(stderr, "%s:%s:(%d): ", __FILE__, __FUNCTION__, __LINE__); \ 63 | fprintf(stderr, ##msg); \ 64 | ALOGE(msg); \ 65 | } \ 66 | } while(0) 67 | 68 | #endif/*DEBUG_H*/ 69 | -------------------------------------------------------------------------------- /librpc/librpc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009, 2011, Code Aurora Forum. All rights reserved. 2 | * 3 | * Redistribution and use in source and binary forms, with or without 4 | * modification, are permitted provided that the following conditions are met: 5 | * * Redistributions of source code must retain the above copyright 6 | * notice, this list of conditions and the following disclaimer. 7 | * * Redistributions in binary form must reproduce the above copyright 8 | * notice, this list of conditions and the following disclaimer in the 9 | * documentation and/or other materials provided with the distribution. 10 | * * Neither the name of Code Aurora nor 11 | * the names of its contributors may be used to endorse or promote 12 | * products derived from this software without specific prior written 13 | * permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | * 27 | */ 28 | #include "rpc/rpc.h" 29 | 30 | /* When defined, subsystem restart support is available. */ 31 | #define LIBRPC_HAS_RESTART_SUPPORT 1 32 | -------------------------------------------------------------------------------- /librpc/ops.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010, Code Aurora Forum. */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define DUMP_DATA 0 15 | /* Wait for server in seconds, 0 - no wait, -ve - infinite wait */ 16 | #define SERVER_WAIT_DURATION 15 17 | #define POLL_INTERVAL_MS 500 18 | 19 | int r_open(const char *router) 20 | { 21 | char name[32]; 22 | struct stat statbuf; 23 | int handle; 24 | struct timespec polling_timer; 25 | int poll_count; 26 | 27 | if (stat("/dev/oncrpc", &statbuf) == 0) 28 | snprintf(name, sizeof(name), "/dev/oncrpc/%s", router); 29 | else 30 | snprintf(name, sizeof(name), "/dev/%s", router); 31 | 32 | polling_timer.tv_sec = 0; 33 | polling_timer.tv_nsec = (POLL_INTERVAL_MS * 1000000); 34 | poll_count = SERVER_WAIT_DURATION * (1000 / POLL_INTERVAL_MS); 35 | 36 | while (stat(name, &statbuf) && poll_count) { 37 | nanosleep(&polling_timer, NULL); 38 | if (poll_count > 0) 39 | poll_count--; 40 | } 41 | 42 | handle = open(name, O_RDWR, 0); 43 | 44 | if(handle < 0) 45 | E("error opening %s: %s\n", name, strerror(errno)); 46 | return handle; 47 | } 48 | 49 | void r_close(int handle) 50 | { 51 | if(close(handle) < 0) E("error: %s\n", strerror(errno)); 52 | } 53 | 54 | int r_read(int handle, char *buf, uint32 size) 55 | { 56 | int rc = read((int) handle, (void *)buf, size); 57 | if (rc < 0) 58 | E("error reading RPC packet: %d (%s)\n", errno, strerror(errno)); 59 | #if DUMP_DATA 60 | else { 61 | int len = rc / 4; 62 | uint32_t *data = (uint32_t *)buf; 63 | fprintf(stdout, "RPC in %02d:", rc); 64 | while (len--) 65 | fprintf(stdout, " %08x", *data++); 66 | fprintf(stdout, "\n"); 67 | } 68 | #endif 69 | return rc; 70 | } 71 | 72 | int r_write (int handle, const char *buf, uint32 size) 73 | { 74 | int rc = write(handle, (void *)buf, size); 75 | if (rc < 0) 76 | E("error writing RPC packet: %d (%s)\n", errno, strerror(errno)); 77 | #if DUMP_DATA 78 | else { 79 | int len = rc / 4; 80 | uint32_t *data = (uint32_t *)buf; 81 | fprintf(stdout, "RPC out %02d:", rc); 82 | while (len--) 83 | fprintf(stdout, " %08x", *data++); 84 | fprintf(stdout, "\n"); 85 | } 86 | #endif 87 | return rc; 88 | } 89 | 90 | int r_control(int handle, const uint32 cmd, void *arg) 91 | { 92 | return ioctl(handle, cmd, arg); 93 | } 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /librpc/rpc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * Functions to compose RPC messages from XDR primitives 5 | */ 6 | 7 | bool_t xdr_call_msg_start( 8 | xdr_s_type *xdr, 9 | uint32 prog, 10 | uint32 ver, 11 | uint32 proc, 12 | opaque_auth *cred, 13 | opaque_auth *verf) 14 | { 15 | uint32 vers = RPC_MSG_VERSION; 16 | 17 | xdr->x_prog = prog; 18 | xdr->x_proc = proc; 19 | 20 | return (XDR_MSG_START(xdr, RPC_MSG_CALL) && 21 | XDR_SEND_UINT32(xdr, &vers) && 22 | XDR_SEND_UINT32(xdr, &prog) && 23 | XDR_SEND_UINT32(xdr, &ver) && 24 | XDR_SEND_UINT32(xdr, &proc) && 25 | xdr_send_auth(xdr, cred) && 26 | xdr_send_auth(xdr, verf)); 27 | } // xdr_call_msg_start 28 | 29 | bool_t xdr_reply_msg_start( 30 | xdr_s_type *xdr, 31 | opaque_auth *verf) 32 | { 33 | int32 stat = (int32) RPC_MSG_ACCEPTED; 34 | int32 accept = (int32) RPC_ACCEPT_SUCCESS; 35 | 36 | return(XDR_MSG_START(xdr, RPC_MSG_REPLY) && 37 | XDR_SEND_INT32(xdr, &stat) && 38 | xdr_send_auth(xdr, verf) && 39 | XDR_SEND_INT32(xdr, &accept)); 40 | } // xdr_reply_msg_start 41 | 42 | static bool_t xdr_send_accepted_reply_header( 43 | xdr_s_type *xdr, 44 | struct rpc_accepted_reply_header const *accreply) 45 | { 46 | if (!xdr_send_auth(xdr, &accreply->verf)) 47 | return FALSE; 48 | 49 | if (!XDR_SEND_ENUM(xdr, &accreply->stat)) 50 | return FALSE; 51 | 52 | switch ((*accreply).stat){ 53 | case RPC_PROG_MISMATCH: 54 | if (!XDR_SEND_UINT32(xdr, &accreply->u.versions.low)) 55 | return FALSE; 56 | 57 | if (!XDR_SEND_UINT32(xdr, &accreply->u.versions.high)) 58 | return FALSE; 59 | break; 60 | 61 | case RPC_ACCEPT_SUCCESS: 62 | case RPC_PROG_UNAVAIL: 63 | case RPC_PROC_UNAVAIL: 64 | case RPC_GARBAGE_ARGS: 65 | case RPC_SYSTEM_ERR: 66 | case RPC_PROG_LOCKED: 67 | // case ignored 68 | break; 69 | 70 | default: 71 | return FALSE; 72 | } 73 | 74 | return TRUE; 75 | } /* xdr_send_accepted_reply_header */ 76 | 77 | static bool_t xdr_send_denied_reply( 78 | xdr_s_type *xdr, 79 | struct rpc_denied_reply const *rejreply) 80 | { 81 | if (!XDR_SEND_ENUM(xdr, &rejreply->stat)) 82 | return FALSE; 83 | 84 | switch ((*rejreply).stat){ 85 | case RPC_MISMATCH: 86 | if (!XDR_SEND_UINT32(xdr, &rejreply->u.versions.low)) 87 | return FALSE; 88 | if (!XDR_SEND_UINT32(xdr, &rejreply->u.versions.high)) 89 | return FALSE; 90 | break; 91 | case RPC_AUTH_ERROR: 92 | if (!XDR_SEND_ENUM(xdr, &rejreply->u.why)) 93 | return FALSE; 94 | break; 95 | default: 96 | return FALSE; 97 | } 98 | 99 | return TRUE; 100 | } /* xdr_send_denied_reply */ 101 | 102 | bool_t xdr_send_reply_header( 103 | xdr_s_type *xdr, 104 | rpc_reply_header const *reply) 105 | { 106 | if (!XDR_SEND_ENUM(xdr, &reply->stat)) 107 | return FALSE; 108 | 109 | switch ((*reply).stat) { 110 | case RPC_MSG_ACCEPTED: 111 | if (!xdr_send_accepted_reply_header(xdr, &reply->u.ar)) 112 | return FALSE; 113 | break; 114 | case RPC_MSG_DENIED: 115 | if (!xdr_send_denied_reply(xdr, &reply->u.dr)) 116 | return FALSE; 117 | break; 118 | default: 119 | return FALSE; 120 | } 121 | 122 | return TRUE; 123 | } /* xdr_send_reply_header */ 124 | 125 | #include 126 | 127 | bool_t 128 | xdr_send_auth(xdr_s_type *xdr, const opaque_auth *auth) 129 | { 130 | #define FAILIF(x) do { if (x) return FALSE; } while(0) 131 | 132 | switch (sizeof(auth->oa_flavor)) { 133 | case 1: 134 | FAILIF(!XDR_SEND_INT8(xdr, (int8_t *)&auth->oa_flavor)); 135 | break; 136 | case 2: 137 | FAILIF(!XDR_SEND_INT16(xdr, (int16_t *)&auth->oa_flavor)); 138 | break; 139 | case 4: 140 | FAILIF(!XDR_SEND_INT32(xdr, (int32_t *)&auth->oa_flavor)); 141 | break; 142 | default: 143 | return FALSE; 144 | } 145 | 146 | return (XDR_SEND_UINT(xdr, (uint32_t *)&auth->oa_length) && 147 | (auth->oa_length == 0 || 148 | XDR_SEND_BYTES(xdr, (uint8_t *)auth->oa_base, auth->oa_length))); 149 | } 150 | 151 | void xdr_free(xdrproc_t proc, char *objp) 152 | { 153 | XDR x; 154 | x.x_op = XDR_FREE; 155 | (*proc)(&x, objp); 156 | } 157 | -------------------------------------------------------------------------------- /librpc/rpc/clnt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 | * unrestricted use provided that this legend is included on all tape 4 | * media and as a part of the software program in whole or part. Users 5 | * may copy or modify Sun RPC without charge, but are not authorized 6 | * to license or distribute it to anyone else except as part of a product or 7 | * program developed by the user. 8 | * 9 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 | * 13 | * Sun RPC is provided with no support and without any obligation on the 14 | * part of Sun Microsystems, Inc. to assist in its use, correction, 15 | * modification or enhancement. 16 | * 17 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 | * OR ANY PART THEREOF. 20 | * 21 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 | * or profits or other special, indirect and consequential damages, even if 23 | * Sun has been advised of the possibility of such damages. 24 | * 25 | * Sun Microsystems, Inc. 26 | * 2550 Garcia Avenue 27 | * Mountain View, California 94043 28 | */ 29 | 30 | /* 31 | * clnt.h - Client side remote procedure call interface. 32 | * 33 | * Copyright (C) 1984, Sun Microsystems, Inc. 34 | * Copyright (c) 2011, Code Aurora Forum. 35 | */ 36 | 37 | #ifndef _RPC_CLNT_H 38 | #define _RPC_CLNT_H 1 39 | 40 | 41 | /* 42 | * By convention, procedure 0 takes null arguments and returns them 43 | */ 44 | #define NULLPROC ((u_long)0) 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | #include 51 | 52 | /* 53 | * Rpc calls return an enum clnt_stat. This should be looked at more, 54 | * since each implementation is required to live with this (implementation 55 | * independent) list of errors. 56 | */ 57 | enum clnt_stat { 58 | RPC_SUCCESS=0, /* call succeeded */ 59 | /* 60 | * local errors 61 | */ 62 | RPC_CANTENCODEARGS=1, /* can't encode arguments */ 63 | RPC_CANTDECODERES=2, /* can't decode results */ 64 | RPC_CANTSEND=3, /* failure in sending call */ 65 | RPC_CANTRECV=4, /* failure in receiving result */ 66 | RPC_TIMEDOUT=5, /* call timed out */ 67 | /* 68 | * remote errors 69 | */ 70 | RPC_VERSMISMATCH=6, /* rpc versions not compatible */ 71 | RPC_AUTHERROR=7, /* authentication error */ 72 | RPC_PROGUNAVAIL=8, /* program not available */ 73 | RPC_PROGVERSMISMATCH=9, /* program version mismatched */ 74 | RPC_PROCUNAVAIL=10, /* procedure unavailable */ 75 | RPC_CANTDECODEARGS=11, /* decode arguments error */ 76 | RPC_SYSTEMERROR=12, /* generic "other problem" */ 77 | RPC_NOBROADCAST = 21, /* Broadcasting not supported */ 78 | /* 79 | * callrpc & clnt_create errors 80 | */ 81 | RPC_UNKNOWNHOST=13, /* unknown host name */ 82 | RPC_UNKNOWNPROTO=17, /* unknown protocol */ 83 | RPC_UNKNOWNADDR = 19, /* Remote address unknown */ 84 | 85 | /* 86 | * rpcbind errors 87 | */ 88 | RPC_RPCBFAILURE=14, /* portmapper failed in its call */ 89 | #define RPC_PMAPFAILURE RPC_RPCBFAILURE 90 | RPC_PROGNOTREGISTERED=15, /* remote program is not registered */ 91 | RPC_N2AXLATEFAILURE = 22, /* Name to addr translation failed */ 92 | /* 93 | * unspecified error 94 | */ 95 | RPC_FAILED=16, 96 | RPC_INTR=18, 97 | RPC_TLIERROR=20, 98 | RPC_UDERROR=23, 99 | /* 100 | * asynchronous errors 101 | */ 102 | RPC_INPROGRESS = 24, 103 | RPC_STALERACHANDLE = 25, 104 | RPC_SUBSYSTEM_RESTART = 26 105 | }; 106 | 107 | struct CLIENT; 108 | typedef struct CLIENT CLIENT; 109 | 110 | /* Reset notifiction callback. 111 | * 112 | * Called when the reset state changes for the client. 113 | */ 114 | typedef void (*clnt_reset_notif_cb) 115 | ( 116 | CLIENT* clnt, 117 | enum rpc_reset_event event 118 | ); 119 | 120 | /* client call callback. 121 | * Callback called when the reply is recieved or there is an error in 122 | * getting reply. 123 | */ 124 | typedef void (*clnt_call_cb) 125 | ( 126 | CLIENT * clnt, 127 | void * cookie, 128 | caddr_t results, 129 | rpc_reply_header error 130 | ); 131 | 132 | typedef void (*clnt_call_non_blocking_cb) 133 | ( 134 | CLIENT * clnt, 135 | void * cookie, 136 | caddr_t results, 137 | rpc_reply_header error 138 | ); 139 | 140 | /*=========================================================================== 141 | FUNCTION CLNT_CALL 142 | 143 | DESCRIPTION 144 | RPCGEN support routine. This routine is called by client routines generated 145 | by RPCGEN. It generates and sends an RPC message to a server. 146 | 147 | This is a blocking call. 148 | 149 | DEPENDENCIES 150 | None. 151 | 152 | ARGUMENTS 153 | xdr - the XDR to use to send the RPC message 154 | proc - the server procedure to call 155 | xdr_args - function pointer for encoding the RPC message args 156 | args_ptr - pointer to args data structure 157 | xdr_results - function pointer for decoding the RPC response 158 | rets_ptr - pointer to results data structure 159 | timeout - return after timeout (ignored) 160 | 161 | RETURN VALUE 162 | RPC_SUCCESS - if successful 163 | error code otherwise 164 | 165 | SIDE EFFECTS 166 | None. 167 | ===========================================================================*/ 168 | extern enum clnt_stat 169 | clnt_call 170 | ( 171 | CLIENT *h, 172 | u_long proc, 173 | xdrproc_t xdr_args, 174 | caddr_t args_ptr, 175 | xdrproc_t xdr_results, 176 | caddr_t rets_ptr, 177 | struct timeval timeout 178 | ); 179 | 180 | /*=========================================================================== 181 | FUNCTION CLNT_CALL_NON_BLOCKING 182 | 183 | DESCRIPTION 184 | RPCGEN support routine. This routine is called by client routines generated 185 | by RPCGEN. It generates and sends an RPC message to a server. 186 | 187 | This is a non-blocking call. It registers clnt_call_callback to be called 188 | when the RPC response is received. 189 | 190 | DEPENDENCIES 191 | None. 192 | 193 | ARGUMENTS 194 | xdr - the XDR to use to send the RPC message 195 | proc - the server procedure to call 196 | xdr_args - function pointer for encoding the RPC message args 197 | args_ptr - pointer to args data structure 198 | xdr_results - function pointer for decoding the RPC response 199 | results_size - size of the results data structure 200 | result_cb - function pointer to be called with the results 201 | cb_data - cookie for results call back function 202 | 203 | RETURN VALUE 204 | RPC_SUCCESS - if successful 205 | error code otherwise 206 | 207 | SIDE EFFECTS 208 | None. 209 | ===========================================================================*/ 210 | extern enum clnt_stat 211 | clnt_call_non_blocking 212 | ( 213 | CLIENT *h, 214 | u_long proc, 215 | xdrproc_t xdr_args, 216 | caddr_t args_ptr, 217 | xdrproc_t xdr_results, 218 | int results_size, 219 | clnt_call_cb result_cb, 220 | void * cb_data 221 | ); 222 | 223 | extern bool_t clnt_freeres( CLIENT *xdr, xdrproc_t xdr_res, caddr_t res_ptr ); 224 | extern void clnt_destroy( CLIENT *xdr ); 225 | extern CLIENT * clnt_create ( char * host, uint32 prog, uint32 vers, 226 | char * proto); 227 | 228 | /*=========================================================================== 229 | FUNCTION clnt_register_reset_notification_cb 230 | 231 | DESCRIPTION 232 | Registers a callback that is called if a subsystem restart (modem restart) 233 | is encountered. If a callback already exists, it will be replaced with the 234 | new function. 235 | 236 | Note that this callback is made on the context of the 237 | receive thread, so blocking calls cannot be made. 238 | 239 | Two calls will be generated. The first will be with an event type of 240 | RPC_SUBSYSTEM_RESTART_BEGIN which signals that the modem has started its 241 | reset. Once the modem comes out of reset, another call will be generated 242 | with the event type of RPC_SUBSYSTEM_RESTART_END. 243 | 244 | DEPENDENCIES 245 | None. 246 | 247 | ARGUMENTS 248 | client - pointer to the client 249 | cb - callback function of type clnt_reset_notif_cb 250 | 251 | RETURN VALUE 252 | 0 - if successful 253 | error code otherwise 254 | 255 | SIDE EFFECTS 256 | None. 257 | ===========================================================================*/ 258 | extern int clnt_register_reset_notification_cb(CLIENT *client, clnt_reset_notif_cb cb); 259 | 260 | /*=========================================================================== 261 | FUNCTION clnt_unregister_reset_notification_cb 262 | 263 | DESCRIPTION 264 | Unregisters any callback registered by clnt_register_reset_notification_cb. 265 | 266 | The previous callback function is returned. 267 | 268 | DEPENDENCIES 269 | None. 270 | 271 | ARGUMENTS 272 | client - pointer to the client 273 | 274 | RETURN VALUE 275 | Pointer to previous callback (NULL if no previous callback registered). 276 | NULL if client is NULL 277 | 278 | SIDE EFFECTS 279 | None. 280 | ===========================================================================*/ 281 | extern clnt_reset_notif_cb clnt_unregister_reset_notification_cb(CLIENT *client); 282 | 283 | 284 | #ifdef __cplusplus 285 | } 286 | #endif 287 | 288 | #endif /* rpc/clnt.h */ 289 | -------------------------------------------------------------------------------- /librpc/rpc/pmap_clnt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 | * unrestricted use provided that this legend is included on all tape 4 | * media and as a part of the software program in whole or part. Users 5 | * may copy or modify Sun RPC without charge, but are not authorized 6 | * to license or distribute it to anyone else except as part of a product or 7 | * program developed by the user. 8 | * 9 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 | * 13 | * Sun RPC is provided with no support and without any obligation on the 14 | * part of Sun Microsystems, Inc. to assist in its use, correction, 15 | * modification or enhancement. 16 | * 17 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 | * OR ANY PART THEREOF. 20 | * 21 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 | * or profits or other special, indirect and consequential damages, even if 23 | * Sun has been advised of the possibility of such damages. 24 | * 25 | * Sun Microsystems, Inc. 26 | * 2550 Garcia Avenue 27 | * Mountain View, California 94043 28 | */ 29 | 30 | /* 31 | * pmap_clnt.h 32 | * Supplies C routines to get to portmap services. 33 | * 34 | * Copyright (C) 1984, Sun Microsystems, Inc. 35 | */ 36 | 37 | #ifndef PMAP_CLIENT_H 38 | #define PMAP_CLIENT_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /*PMAP_CLIENT_H*/ 54 | -------------------------------------------------------------------------------- /librpc/rpc/rpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 | * unrestricted use provided that this legend is included on all tape 4 | * media and as a part of the software program in whole or part. Users 5 | * may copy or modify Sun RPC without charge, but are not authorized 6 | * to license or distribute it to anyone else except as part of a product or 7 | * program developed by the user. 8 | * 9 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 | * 13 | * Sun RPC is provided with no support and without any obligation on the 14 | * part of Sun Microsystems, Inc. to assist in its use, correction, 15 | * modification or enhancement. 16 | * 17 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 | * OR ANY PART THEREOF. 20 | * 21 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 | * or profits or other special, indirect and consequential damages, even if 23 | * Sun has been advised of the possibility of such damages. 24 | * 25 | * Sun Microsystems, Inc. 26 | * 2550 Garcia Avenue 27 | * Mountain View, California 94043 28 | */ 29 | 30 | /* 31 | * rpc.h, Just includes the billions of rpc header files necessary to 32 | * do remote procedure calling. 33 | * 34 | * Copyright (C) 1984, Sun Microsystems, Inc. 35 | */ 36 | 37 | #ifndef RPC_H 38 | #define RPC_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* RPC_H */ 54 | -------------------------------------------------------------------------------- /librpc/rpc/rpc_router_ioctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2008, Google Inc. 3 | ** Copyright (c) 2009, Code Aurora Forum.All rights reserved. 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | #ifndef RPC_IOCTL_H 19 | #define RPC_IOCTL_H 20 | 21 | #include 22 | 23 | struct rpcrouter_ioctl_server_args { 24 | uint32_t prog; 25 | uint32_t vers; 26 | }; 27 | 28 | #define RPC_ROUTER_IOCTL_MAGIC (0xC1) 29 | 30 | #define RPC_ROUTER_IOCTL_GET_VERSION \ 31 | _IOR(RPC_ROUTER_IOCTL_MAGIC, 0, unsigned int) 32 | 33 | #define RPC_ROUTER_IOCTL_GET_MTU \ 34 | _IOR(RPC_ROUTER_IOCTL_MAGIC, 1, unsigned int) 35 | 36 | #define RPC_ROUTER_IOCTL_REGISTER_SERVER \ 37 | _IOWR(RPC_ROUTER_IOCTL_MAGIC, 2, unsigned int) 38 | 39 | #define RPC_ROUTER_IOCTL_UNREGISTER_SERVER \ 40 | _IOWR(RPC_ROUTER_IOCTL_MAGIC, 3, unsigned int) 41 | 42 | #define RPC_ROUTER_IOCTL_CLEAR_NETRESET \ 43 | _IOWR(RPC_ROUTER_IOCTL_MAGIC, 4, unsigned int) 44 | 45 | #endif /* RPC_IOCTL_H */ 46 | -------------------------------------------------------------------------------- /librpc/rpc/svc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 | * unrestricted use provided that this legend is included on all tape 4 | * media and as a part of the software program in whole or part. Users 5 | * may copy or modify Sun RPC without charge, but are not authorized 6 | * to license or distribute it to anyone else except as part of a product or 7 | * program developed by the user. 8 | * 9 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 | * 13 | * Sun RPC is provided with no support and without any obligation on the 14 | * part of Sun Microsystems, Inc. to assist in its use, correction, 15 | * modification or enhancement. 16 | * 17 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 | * OR ANY PART THEREOF. 20 | * 21 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 | * or profits or other special, indirect and consequential damages, even if 23 | * Sun has been advised of the possibility of such damages. 24 | * 25 | * Sun Microsystems, Inc. 26 | * 2550 Garcia Avenue 27 | * Mountain View, California 94043 28 | */ 29 | 30 | /* 31 | * svc.h, Server-side remote procedure call interface. 32 | * 33 | * Copyright (C) 1984, Sun Microsystems, Inc. 34 | * Copyright (c) 2011, Code Aurora Forum. 35 | */ 36 | 37 | #ifndef _RPC_SVC_H 38 | #define _RPC_SVC_H 1 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include 45 | 46 | /* 47 | * This interface must manage two items concerning remote procedure calling: 48 | * 49 | * 1) An arbitrary number of transport connections upon which rpc requests 50 | * are received. The two most notable transports are TCP and UDP; they are 51 | * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; 52 | * they in turn call xprt_register and xprt_unregister. 53 | * 54 | * 2) An arbitrary number of locally registered services. Services are 55 | * described by the following four data: program number, version number, 56 | * "service dispatch" function, a transport handle, and a bool_t that 57 | * indicates whether or not the exported program should be registered with a 58 | * local binder service; if true the program's number and version and the 59 | * port number from the transport handle are registered with the binder. 60 | * These data are registered with the rpc svc system via svc_register. 61 | * 62 | * A service's dispatch function is called whenever an rpc request comes in 63 | * on a transport. The request's program and version numbers must match 64 | * those of the registered service. The dispatch function is passed two 65 | * parameters, struct svc_req * and SVCXPRT *, defined below. 66 | */ 67 | 68 | /* 69 | * Server side transport handle 70 | */ 71 | struct SVCXPRT; 72 | typedef struct SVCXPRT SVCXPRT; 73 | 74 | /* 75 | * Service request 76 | */ 77 | struct svc_req { 78 | rpcprog_t rq_prog; /* service program number */ 79 | rpcvers_t rq_vers; /* service protocol version */ 80 | rpcproc_t rq_proc; /* the desired procedure */ 81 | SVCXPRT *rq_xprt; /* associated transport */ 82 | }; 83 | 84 | #ifndef __DISPATCH_FN_T 85 | #define __DISPATCH_FN_T 86 | typedef void (*__dispatch_fn_t) (struct svc_req*, SVCXPRT*); 87 | #endif 88 | 89 | 90 | /* Reset notifiction callback. 91 | * 92 | * Called when the reset state changes for the client. 93 | */ 94 | typedef void (*svc_reset_notif_cb) 95 | ( 96 | SVCXPRT* xprt, 97 | enum rpc_reset_event event 98 | ); 99 | 100 | /* 101 | * Transport registration. 102 | * 103 | * xprt_register(xprt) 104 | * SVCXPRT *xprt; 105 | */ 106 | extern void xprt_register (SVCXPRT *__xprt); 107 | 108 | /* 109 | * Transport un-register 110 | * 111 | * xprt_unregister(xprt) 112 | * SVCXPRT *xprt; 113 | */ 114 | extern void xprt_unregister (SVCXPRT *__xprt); 115 | 116 | /* 117 | * Service registration (registers only with plugger module) 118 | * 119 | * svc_register_with_plugger(xprt, prog, vers, dispatch, protocol) 120 | * SVCXPRT *xprt; 121 | * rpcprog_t prog; 122 | * rpcvers_t vers; 123 | * void (*dispatch)(struct svc_req*, SVCXPRT*); 124 | * rpcprot_t protocol; like TCP or UDP, zero means do not register 125 | */ 126 | extern bool_t svc_register_with_plugger (SVCXPRT *__xprt, rpcprog_t __prog, 127 | rpcvers_t __vers, 128 | __dispatch_fn_t __dispatch, 129 | rpcprot_t __protocol); 130 | 131 | /* 132 | * Service registration (registers with plugger module and lower layers) 133 | * 134 | * svc_register(xprt, prog, vers, dispatch, protocol) 135 | * SVCXPRT *xprt; 136 | * rpcprog_t prog; 137 | * rpcvers_t vers; 138 | * void (*dispatch)(struct svc_req*, SVCXPRT*); 139 | * rpcprot_t protocol; like TCP or UDP, zero means do not register 140 | */ 141 | extern bool_t svc_register (SVCXPRT *__xprt, rpcprog_t __prog, 142 | rpcvers_t __vers, __dispatch_fn_t __dispatch, 143 | rpcprot_t __protocol); 144 | 145 | extern void svc_destroy(SVCXPRT *xprt); 146 | 147 | /* 148 | * Service un-registration 149 | * 150 | * svc_unregister(xprt, prog, vers) 151 | * SVCXPRT *xprt 152 | * rpcprog_t prog; 153 | * rpcvers_t vers; 154 | */ 155 | void 156 | svc_unregister (SVCXPRT *__xprt, rpcprog_t prog, rpcvers_t vers); 157 | 158 | /* 159 | * Service Enable 160 | * 161 | * svc_enable( prog, vers ) 162 | * rpcprog_t prog; 163 | * rpcvers_t vers; 164 | */ 165 | #define svc_enable(prog, vers) svc_lock(prog, vers, FALSE) 166 | 167 | /* 168 | * Service Disable 169 | * 170 | * svc_disable( prog, vers ) 171 | * rpcprog_t prog; 172 | * rpcvers_t vers; 173 | */ 174 | #define svc_disable(prog, vers) svc_lock(prog, vers, TRUE) 175 | 176 | extern void svc_lock(rpcprog_t __prog, rpcvers_t __vers, bool_t __lock); 177 | 178 | /* 179 | * When the service routine is called, it must first check to see if it 180 | * knows about the procedure; if not, it should call svcerr_noproc 181 | * and return. If so, it should deserialize its arguments via 182 | * SVC_GETARGS (defined above). If the deserialization does not work, 183 | * svcerr_decode should be called followed by a return. Successful 184 | * decoding of the arguments should be followed the execution of the 185 | * procedure's code and a call to svc_sendreply. 186 | * 187 | * Also, if the service refuses to execute the procedure due to too- 188 | * weak authentication parameters, svcerr_weakauth should be called. 189 | * Note: do not confuse access-control failure with weak authentication! 190 | * 191 | * NB: In pure implementations of rpc, the caller always waits for a reply 192 | * msg. This message is sent when svc_sendreply is called. 193 | * Therefore pure service implementations should always call 194 | * svc_sendreply even if the function logically returns void; use 195 | * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows 196 | * for the abuse of pure rpc via batched calling or pipelining. In the 197 | * case of a batched call, svc_sendreply should NOT be called since 198 | * this would send a return message, which is what batching tries to avoid. 199 | * It is the service/protocol writer's responsibility to know which calls are 200 | * batched and which are not. Warning: responding to batch calls may 201 | * deadlock the caller and server processes! 202 | */ 203 | 204 | extern bool_t svc_getargs(SVCXPRT *xdr, xdrproc_t xdr_args, caddr_t args_ptr); 205 | extern bool_t svc_freeargs(SVCXPRT *xdr, xdrproc_t xdr_args, caddr_t args_ptr); 206 | 207 | extern bool_t svc_sendreply (SVCXPRT *xprt, xdrproc_t __xdr_results, 208 | caddr_t __xdr_location); 209 | 210 | /*=========================================================================== 211 | FUNCTION svc_register_reset_notification_cb 212 | 213 | DESCRIPTION 214 | Registers a callback that is called if a subsystem restart (modem restart) 215 | is encountered. Note that this callback is made on the context of the 216 | servers callback or server thread, so blocking calls cannot be made. 217 | 218 | Two calls will be generated. The first will be with an event type of 219 | RPC_SUBSYSTEM_RESTART_BEGIN which signals that the modem has started its 220 | reset. Once the modem comes out of reset, another call will be generated 221 | with the event type of RPC_SUBSYSTEM_RESTART_END. 222 | 223 | DEPENDENCIES 224 | None. 225 | 226 | ARGUMENTS 227 | xprt - pointer to the client 228 | cb - callback function of type svc_reset_notif_cb 229 | 230 | RETURN VALUE 231 | 0 - if successful 232 | error code otherwise 233 | 234 | SIDE EFFECTS 235 | None. 236 | ===========================================================================*/ 237 | extern int svc_register_reset_notification_cb(SVCXPRT *xprt, svc_reset_notif_cb cb); 238 | 239 | /*=========================================================================== 240 | FUNCTION svc_unregister_reset_notification_cb 241 | 242 | DESCRIPTION 243 | Unregisters any callback registered by svc_register_reset_notification_cb. 244 | 245 | The previous callback function is returned. 246 | 247 | DEPENDENCIES 248 | None. 249 | 250 | ARGUMENTS 251 | xprt - pointer to the server transport 252 | 253 | RETURN VALUE 254 | Pointer to previous callback (NULL if no previous callback registered). 255 | NULL if xprt is NULL 256 | 257 | SIDE EFFECTS 258 | None. 259 | ===========================================================================*/ 260 | extern svc_reset_notif_cb svc_unregister_reset_notification_cb(SVCXPRT *xprt); 261 | 262 | /* 263 | * Socket to use on svcxxx_create call to get default socket 264 | */ 265 | #define RPC_ANYSOCK -1 266 | 267 | /* 268 | * Router based rpc. 269 | */ 270 | extern SVCXPRT *svcrtr_create (void); 271 | 272 | extern void svcerr_decode (SVCXPRT *); 273 | extern void svcerr_weakauth (SVCXPRT *); 274 | extern void svcerr_noproc (SVCXPRT *); 275 | extern void svcerr_noprog (SVCXPRT *); 276 | extern void svcerr_systemerr (SVCXPRT *); 277 | extern void svcerr_progvers (SVCXPRT *, rpcvers_t __low_vers, rpcvers_t __high_vers); 278 | extern void svcerr_auth (SVCXPRT *, auth_stat __why); 279 | 280 | #ifdef __cplusplus 281 | } 282 | #endif 283 | 284 | #endif /* rpc/svc.h */ 285 | -------------------------------------------------------------------------------- /librpc/rpc/xdr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 | * unrestricted use provided that this legend is included on all tape 4 | * media and as a part of the software program in whole or part. Users 5 | * may copy or modify Sun RPC without charge, but are not authorized 6 | * to license or distribute it to anyone else except as part of a product or 7 | * program developed by the user. 8 | * 9 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 | * 13 | * Sun RPC is provided with no support and without any obligation on the 14 | * part of Sun Microsystems, Inc. to assist in its use, correction, 15 | * modification or enhancement. 16 | * 17 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 | * OR ANY PART THEREOF. 20 | * 21 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 | * or profits or other special, indirect and consequential damages, even if 23 | * Sun has been advised of the possibility of such damages. 24 | * 25 | * Sun Microsystems, Inc. 26 | * 2550 Garcia Avenue 27 | * Mountain View, California 94043 28 | */ 29 | 30 | /* 31 | * xdr.h, External Data Representation Serialization Routines. 32 | * 33 | * Copyright (C) 1984, Sun Microsystems, Inc. 34 | */ 35 | 36 | #ifndef XDR_H 37 | #define XDR_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /*=========================================================================== 44 | Macros for calling primitive XDR routines (this is independent of RPC) 45 | ===========================================================================*/ 46 | 47 | #define XDR_RECV_BYTES(XDR, BUF, LEN) (XDR)->xops->recv_bytes(XDR, BUF, LEN) 48 | #define XDR_RECV_INT16(XDR, VALUE) (XDR)->xops->recv_int16(XDR, VALUE) 49 | #define XDR_RECV_INT32(XDR, VALUE) (XDR)->xops->recv_int32(XDR, VALUE) 50 | #define XDR_RECV_INT8(XDR, VALUE) (XDR)->xops->recv_int8(XDR, VALUE) 51 | #define XDR_RECV_UINT(XDR, VALUE) (XDR)->xops->recv_uint32(XDR, (uint32 *)(VALUE)) 52 | #define XDR_RECV_UINT32(XDR, VALUE) (XDR)->xops->recv_uint32(XDR, VALUE) 53 | #define XDR_SEND_BYTES(XDR, BUF, LEN) (XDR)->xops->send_bytes(XDR, BUF, LEN) 54 | #define XDR_SEND_INT16(XDR, VALUE) (XDR)->xops->send_int16(XDR, VALUE) 55 | #define XDR_SEND_INT32(XDR, VALUE) (XDR)->xops->send_int32(XDR, VALUE) 56 | #define XDR_SEND_INT8(XDR, VALUE) (XDR)->xops->send_int8(XDR, VALUE) 57 | #define XDR_SEND_UINT(XDR, VALUE) (XDR)->xops->send_uint32(XDR, (uint32 *)(VALUE)) 58 | #define XDR_SEND_UINT32(XDR, VALUE) (XDR)->xops->send_uint32(XDR, VALUE) 59 | 60 | /*=========================================================================== 61 | Macros for sending and receiving an RPC message through the transport 62 | ===========================================================================*/ 63 | 64 | #define XDR_MSG_START(XDR, TYPE) (XDR)->xops->msg_start(XDR, TYPE) 65 | #define XDR_MSG_SEND(XDR) (XDR)->xops->msg_send(XDR) 66 | #define XDR_MSG_DONE(XDR) (XDR)->xops->msg_done(XDR) 67 | #define XDR_MSG_ABORT(XDR) (XDR)->xops->msg_abort(XDR) 68 | 69 | extern bool_t xdr_call_msg_start (XDR *xdr, uint32 prog, uint32 ver, uint32 proc, opaque_auth *cred, opaque_auth *verf); 70 | extern bool_t xdr_reply_msg_start (XDR *xdr, opaque_auth *verf); 71 | extern bool_t xdr_send_auth (XDR *xdr, const opaque_auth *auth); 72 | extern bool_t xdr_send_reply_header (XDR *xdr, rpc_reply_header const *reply); 73 | extern void xdr_free (xdrproc_t proc, char *objp); 74 | 75 | /*********************************************************************** 76 | Support for rpcgen 77 | ***********************************************************************/ 78 | 79 | #define XDR_SEND_ENUM(XDR, VALUE) xdr_send_enum(XDR, (void *) (VALUE), sizeof(*(VALUE))) 80 | #define XDR_RECV_ENUM(XDR, VALUE) xdr_recv_enum(XDR, (void *) (VALUE), sizeof(*(VALUE))) 81 | extern bool_t xdr_send_enum (XDR *xdr, const void *value, uint32 size); 82 | extern bool_t xdr_recv_enum (XDR *xdr, void *value, uint32 size); 83 | 84 | extern bool_t xdr_bytes (XDR *xdr, char **cpp, u_int *sizep, u_int maxsize); 85 | extern bool_t xdr_enum (XDR *xdr, enum_t *ep); 86 | extern bool_t xdr_pointer (XDR *xdrs, char **_objpp, u_int obj_size, xdrproc_t xdr_obj); 87 | extern bool_t xdr_int (XDR *xdr, int *ip); 88 | extern bool_t xdr_u_int (XDR *xdr, u_int *ip); 89 | extern bool_t xdr_char (XDR *xdr, char *cp); 90 | extern bool_t xdr_u_char (XDR *xdr, u_char *cp); 91 | extern bool_t xdr_long (XDR *xdr, long *ulp); 92 | extern bool_t xdr_u_long (XDR *xdr, u_long *ulp); 93 | #define xdr_uint32 xdr_u_long 94 | extern bool_t xdr_quad_t (XDR *xdrs, quad_t *llp); 95 | extern bool_t xdr_u_quad_t (XDR *__xdrs, u_quad_t *__ullp); 96 | extern bool_t xdr_short (XDR *xdr, short *sp); 97 | extern bool_t xdr_u_short (XDR *xdr, u_short *usp); 98 | extern bool_t xdr_vector (XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_elem); 99 | extern bool_t xdr_void (void); 100 | extern bool_t xdr_opaque (XDR *xdr, caddr_t cp, u_int cnt); 101 | extern bool_t xdr_string (XDR *xdr, char **cpp, u_int maxsize); 102 | 103 | extern bool_t xdr_array ( 104 | XDR *xdrs, 105 | caddr_t *addrp,/* array pointer */ 106 | u_int *sizep, /* number of elements */ 107 | u_int maxsize, /* max numberof elements */ 108 | u_int elsize, /* size in bytes of each element */ 109 | xdrproc_t elproc); /* xdr routine to handle each element */ 110 | 111 | #ifdef __cplusplus 112 | } 113 | #endif 114 | 115 | #endif /* rpc/xdr.h */ 116 | -------------------------------------------------------------------------------- /librpc/svc_clnt_common.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | extern int r_open(const char *router); 7 | extern void r_close(int handle); 8 | extern int r_read(int handle, char *buf, uint32 size); 9 | extern int r_write(int handle, const char *buf, uint32 size); 10 | extern int r_control(int handle, const uint32 cmd, void *arg); 11 | 12 | static void xdr_std_destroy(xdr_s_type *xdr) 13 | { 14 | /* whatever */ 15 | } 16 | 17 | static bool_t xdr_std_control(xdr_s_type *xdr, int request, void *info) 18 | { 19 | return r_control(xdr->fd, request, info); 20 | } 21 | 22 | static bool_t xdr_std_msg_done(xdr_s_type *xdr) 23 | { 24 | /* whatever */ 25 | return TRUE; 26 | } 27 | 28 | /* Outgoing message control functions */ 29 | static bool_t xdr_std_msg_start(xdr_s_type *xdr, 30 | rpc_msg_e_type rpc_msg_type) 31 | { 32 | 33 | /* xid is does not matter under our set of assumptions: that for a single 34 | * program/version channel, communication is synchronous. If several 35 | * processes attempt to call functions on a program, then the rpcrouter 36 | * driver will ensure that the calls are properly muxed, because the 37 | * processes will have separate PIDs, and the rpcrouter driver uses PIDs to 38 | * keep track of RPC transactions. For multiple threads in the same 39 | * process accessing the same program, we serialize access in clnt_call() 40 | * by locking a mutex around the RPC call. If threads in the same process 41 | * call into different programs, then there is no issue, again because of 42 | * the use of a mutex in clnt_call(). 43 | * 44 | * NOTE: This comment assumes that the only way we talk to the RPC router 45 | * from a client is by using clnt_call(), which is the case for all 46 | * client code generated by rpcgen(). 47 | * 48 | * NOTE: The RPC router driver will soon be able to open a separate device 49 | * file for each program/version channel. This will allow for 50 | * natural multiplexing among clients, as we won't have to rely on 51 | * the mutex for the case where different programs are being called 52 | * into by separate threads in the same process. When this happens, 53 | * we'll need to optimize the RPC library to add a separate mutex for 54 | * each program/version channel, which will require some sort of 55 | * registry. 56 | */ 57 | 58 | if (rpc_msg_type == RPC_MSG_CALL) xdr->xid++; 59 | 60 | /* We start writing into the outgoing-message buffer at index 32, because 61 | we need to write header information before we send the message. The 62 | header information includes the destination address and the pacmark 63 | header. 64 | */ 65 | xdr->out_next = (RPC_OFFSET+2)*sizeof(uint32); 66 | 67 | /* we write the pacmark header when we send the message. */ 68 | ((uint32 *)xdr->out_msg)[RPC_OFFSET] = htonl(xdr->xid); 69 | /* rpc call or reply? */ 70 | ((uint32 *)xdr->out_msg)[RPC_OFFSET+1] = htonl(rpc_msg_type); 71 | 72 | return TRUE; 73 | } 74 | 75 | static bool_t xdr_std_msg_abort(xdr_s_type *xdr) 76 | { 77 | /* dummy */ 78 | return TRUE; 79 | } 80 | 81 | /* Can be used to send both calls and replies. */ 82 | 83 | extern bool_t xdr_recv_reply_header(xdr_s_type *xdr, rpc_reply_header *reply); 84 | 85 | #include 86 | 87 | static bool_t xdr_std_msg_send(xdr_s_type *xdr) 88 | { 89 | int ret; 90 | 91 | /* Send the RPC packet. */ 92 | ret = r_write(xdr->fd, (void *)xdr->out_msg, xdr->out_next); 93 | xdr->xdr_err = ret; 94 | if ( ret != xdr->out_next) 95 | return FALSE; 96 | 97 | return TRUE; 98 | } 99 | 100 | static bool_t xdr_std_read(xdr_s_type *xdr) 101 | { 102 | xdr->in_len = r_read(xdr->fd, (void *)xdr->in_msg, RPCROUTER_MSGSIZE_MAX); 103 | if (xdr->in_len < 0) return FALSE; 104 | 105 | if (xdr->in_len < (RPC_OFFSET+2)*4) { 106 | xdr->in_len = -1; 107 | return FALSE; 108 | } 109 | 110 | xdr->in_next = (RPC_OFFSET+2)*4; 111 | return TRUE; 112 | } 113 | 114 | /* Message data functions */ 115 | static bool_t xdr_std_send_uint32(xdr_s_type *xdr, const uint32 *value) 116 | { 117 | if (xdr->out_next >= RPCROUTER_MSGSIZE_MAX - 3) return FALSE; 118 | *(int32 *)(xdr->out_msg + xdr->out_next) = htonl(*value); 119 | xdr->out_next += 4; 120 | return TRUE; 121 | } 122 | 123 | static bool_t xdr_std_send_int8(xdr_s_type *xdr, const int8 *value) 124 | { 125 | uint32 val = *value; 126 | return xdr_std_send_uint32(xdr, &val); 127 | } 128 | 129 | static bool_t xdr_std_send_uint8(xdr_s_type *xdr, const uint8 *value) 130 | { 131 | uint32 val = *value; 132 | return xdr_std_send_uint32(xdr, &val); 133 | } 134 | 135 | static bool_t xdr_std_send_int16(xdr_s_type *xdr, const int16 *value) 136 | { 137 | uint32 val = *value; 138 | return xdr_std_send_uint32(xdr, &val); 139 | } 140 | 141 | static bool_t xdr_std_send_uint16(xdr_s_type *xdr, const uint16 *value) 142 | { 143 | uint32 val = *value; 144 | return xdr_std_send_uint32(xdr, &val); 145 | } 146 | 147 | static bool_t xdr_std_send_int32(xdr_s_type *xdr, const int32 *value) 148 | { 149 | return xdr_std_send_uint32(xdr, (uint32_t *)value); 150 | } 151 | 152 | static bool_t xdr_std_send_bytes(xdr_s_type *xdr, const uint8 *buf, 153 | uint32 len) 154 | { 155 | if (xdr->out_next + len > RPCROUTER_MSGSIZE_MAX) return FALSE; 156 | while(len--) 157 | xdr->out_msg[xdr->out_next++] = *buf++; 158 | while(xdr->out_next % 4) 159 | xdr->out_msg[xdr->out_next++] = 0; 160 | return TRUE; 161 | } 162 | 163 | #if 0 164 | #include 165 | typedef struct 166 | { 167 | size_t count; 168 | intptr_t* addrs; 169 | } stack_crawl_state_t; 170 | 171 | static _Unwind_Reason_Code trace_function(_Unwind_Context *context, void *arg) 172 | { 173 | stack_crawl_state_t* state = (stack_crawl_state_t*)arg; 174 | if (state->count) { 175 | intptr_t ip = (intptr_t)_Unwind_GetIP(context); 176 | if (ip) { 177 | state->addrs[0] = ip; 178 | state->addrs++; 179 | state->count--; 180 | } 181 | } 182 | return _URC_NO_REASON; 183 | } 184 | 185 | static inline 186 | int get_backtrace(intptr_t* addrs, size_t max_entries) 187 | { 188 | stack_crawl_state_t state; 189 | state.count = max_entries; 190 | state.addrs = (intptr_t*)addrs; 191 | _Unwind_Backtrace(trace_function, (void*)&state); 192 | return max_entries - state.count; 193 | } 194 | #endif 195 | 196 | static bool_t xdr_std_recv_uint32(xdr_s_type *xdr, uint32 *value) 197 | { 198 | #if 0 199 | intptr_t *trace[20], *tr; 200 | int nc = get_backtrace(trace, 20); 201 | tr = trace; 202 | while(nc--) 203 | D("\t%02d: %p\n", nc, *tr++); 204 | #endif 205 | 206 | if (xdr->in_next + 4 > xdr->in_len) { return FALSE; } 207 | if (value) *value = ntohl(*(uint32 *)(xdr->in_msg + xdr->in_next)); 208 | xdr->in_next += 4; 209 | return TRUE; 210 | } 211 | 212 | #define RECEIVE \ 213 | uint32 val; \ 214 | if (xdr_std_recv_uint32(xdr, &val)) { \ 215 | *value = val; \ 216 | return TRUE; \ 217 | } \ 218 | return FALSE 219 | 220 | static bool_t xdr_std_recv_int8(xdr_s_type *xdr, int8 *value) 221 | { 222 | RECEIVE; 223 | } 224 | 225 | static bool_t xdr_std_recv_uint8(xdr_s_type *xdr, uint8 *value) 226 | { 227 | RECEIVE; 228 | } 229 | 230 | static bool_t xdr_std_recv_int16(xdr_s_type *xdr, int16 *value) 231 | { 232 | RECEIVE; 233 | } 234 | 235 | static bool_t xdr_std_recv_uint16(xdr_s_type *xdr, uint16 *value) 236 | { 237 | RECEIVE; 238 | } 239 | 240 | #undef RECEIVE 241 | 242 | static bool_t xdr_std_recv_int32(xdr_s_type *xdr, int32 *value) 243 | { 244 | return xdr_std_recv_uint32(xdr, (uint32 * )value); 245 | } 246 | 247 | static bool_t xdr_std_recv_bytes(xdr_s_type *xdr, uint8 *buf, uint32 len) 248 | { 249 | if (xdr->in_next + (int)len > xdr->in_len) return FALSE; 250 | if (buf) memcpy(buf, &xdr->in_msg[xdr->in_next], len); 251 | xdr->in_next += len; 252 | xdr->in_next = (xdr->in_next + 3) & ~3; 253 | return TRUE; 254 | } 255 | 256 | const xdr_ops_s_type xdr_std_xops = { 257 | 258 | xdr_std_destroy, 259 | xdr_std_control, 260 | xdr_std_read, 261 | xdr_std_msg_done, 262 | xdr_std_msg_start, 263 | xdr_std_msg_abort, 264 | xdr_std_msg_send, 265 | 266 | xdr_std_send_int8, 267 | xdr_std_send_uint8, 268 | xdr_std_send_int16, 269 | xdr_std_send_uint16, 270 | xdr_std_send_int32, 271 | xdr_std_send_uint32, 272 | xdr_std_send_bytes, 273 | xdr_std_recv_int8, 274 | xdr_std_recv_uint8, 275 | xdr_std_recv_int16, 276 | xdr_std_recv_uint16, 277 | xdr_std_recv_int32, 278 | xdr_std_recv_uint32, 279 | xdr_std_recv_bytes, 280 | }; 281 | 282 | xdr_s_type *xdr_init_common(const char *router, int is_client) 283 | { 284 | xdr_s_type *xdr = (xdr_s_type *)calloc(1, sizeof(xdr_s_type)); 285 | 286 | xdr->xops = &xdr_std_xops; 287 | 288 | xdr->fd = r_open(router); 289 | if (xdr->fd < 0) { 290 | E("ERROR OPENING [%s]: %s\n", router, strerror(errno)); 291 | free(xdr); 292 | return NULL; 293 | } 294 | xdr->is_client = is_client; 295 | 296 | D("OPENED [%s] fd %d\n", router, xdr->fd); 297 | return xdr; 298 | } 299 | 300 | xdr_s_type *xdr_clone(xdr_s_type *other) 301 | { 302 | xdr_s_type *xdr = (xdr_s_type *)calloc(1, sizeof(xdr_s_type)); 303 | 304 | xdr->xops = &xdr_std_xops; 305 | 306 | xdr->fd = dup(other->fd); 307 | if (xdr->fd < 0) { 308 | E("ERROR DUPLICATING FD %d: %s\n", other->fd, strerror(errno)); 309 | free(xdr); 310 | return NULL; 311 | } 312 | 313 | xdr->xid = xdr->xid; 314 | xdr->x_prog = other->x_prog; 315 | xdr->x_vers = other->x_vers; 316 | xdr->is_client = other->is_client; 317 | 318 | D("CLONED fd %d --> %d\n", other->fd, xdr->fd); 319 | return xdr; 320 | } 321 | 322 | void xdr_destroy_common(xdr_s_type *xdr) 323 | { 324 | D("CLOSING fd %d\n", xdr->fd); 325 | r_close(xdr->fd); 326 | free(xdr); 327 | } 328 | --------------------------------------------------------------------------------