Arun Kumar K.R | f6f49a1 | 2012-11-27 11:46:50 -0800 | [diff] [blame] | 1 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010 The Android Open Source Project |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 4 | * Copyright (C) 2012-14, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 5 | * |
| 6 | * Not a Contribution, Apache license notifications and license are |
| 7 | * retained for attribution purposes only. |
| 8 | |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | */ |
Saurabh Shah | 649cda6 | 2012-09-16 16:05:58 -0700 | [diff] [blame] | 21 | #define UEVENT_DEBUG 0 |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 22 | #include <hardware_legacy/uevent.h> |
| 23 | #include <utils/Log.h> |
| 24 | #include <sys/resource.h> |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 25 | #include <sys/prctl.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | #include "hwc_utils.h" |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 29 | #include "hwc_fbupdate.h" |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 30 | #include "hwc_mdpcomp.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 31 | #include "hwc_copybit.h" |
| 32 | #include "comptype.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 33 | #include "external.h" |
Tatenda Chipeperekwa | 8f1b9d7 | 2014-02-11 16:20:50 -0800 | [diff] [blame] | 34 | #include "hwc_virtual.h" |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 35 | #include "mdp_version.h" |
Amara Venkata Mastan Manoj Kumar | 5cbac94 | 2013-08-13 19:00:14 -0700 | [diff] [blame] | 36 | using namespace overlay; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 37 | namespace qhwc { |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 38 | #define HWC_UEVENT_SWITCH_STR "change@/devices/virtual/switch/" |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 39 | #define HWC_UEVENT_THREAD_NAME "hwcUeventThread" |
| 40 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 41 | static void setup(hwc_context_t* ctx, int dpy) |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 42 | { |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 43 | ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy); |
| 44 | ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy); |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void clear(hwc_context_t* ctx, int dpy) |
| 48 | { |
| 49 | if(ctx->mFBUpdate[dpy]) { |
| 50 | delete ctx->mFBUpdate[dpy]; |
| 51 | ctx->mFBUpdate[dpy] = NULL; |
| 52 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 53 | if(ctx->mMDPComp[dpy]) { |
| 54 | delete ctx->mMDPComp[dpy]; |
| 55 | ctx->mMDPComp[dpy] = NULL; |
Amara Venkata Mastan Manoj Kumar | b156a2f | 2013-02-07 16:42:50 -0800 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 59 | /* Parse uevent data for devices which we are interested */ |
| 60 | static int getConnectedDisplay(const char* strUdata) |
| 61 | { |
| 62 | if(strcasestr("change@/devices/virtual/switch/hdmi", strUdata)) |
| 63 | return HWC_DISPLAY_EXTERNAL; |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 64 | return -1; |
| 65 | } |
| 66 | |
Veera Sankaran | 0dadfb3 | 2013-07-22 16:07:48 -0700 | [diff] [blame] | 67 | static bool getPanelResetStatus(hwc_context_t* ctx, const char* strUdata, int len) |
| 68 | { |
| 69 | const char* iter_str = strUdata; |
| 70 | if (strcasestr("change@/devices/virtual/graphics/fb0", strUdata)) { |
| 71 | while(((iter_str - strUdata) <= len) && (*iter_str)) { |
| 72 | char* pstr = strstr(iter_str, "PANEL_ALIVE=0"); |
| 73 | if (pstr != NULL) { |
Arpita Banerjee | d896598 | 2013-11-08 17:27:33 -0800 | [diff] [blame] | 74 | ALOGI("%s: got change event in fb0 with PANEL_ALIVE=0", |
Veera Sankaran | 0dadfb3 | 2013-07-22 16:07:48 -0700 | [diff] [blame] | 75 | __FUNCTION__); |
| 76 | ctx->mPanelResetStatus = true; |
| 77 | return true; |
| 78 | } |
| 79 | iter_str += strlen(iter_str)+1; |
| 80 | } |
| 81 | } |
| 82 | return false; |
| 83 | } |
| 84 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 85 | /* Parse uevent data for action requested for the display */ |
| 86 | static int getConnectedState(const char* strUdata, int len) |
| 87 | { |
| 88 | const char* iter_str = strUdata; |
| 89 | while(((iter_str - strUdata) <= len) && (*iter_str)) { |
| 90 | char* pstr = strstr(iter_str, "SWITCH_STATE="); |
| 91 | if (pstr != NULL) { |
| 92 | return (atoi(pstr + strlen("SWITCH_STATE="))); |
| 93 | } |
| 94 | iter_str += strlen(iter_str)+1; |
| 95 | } |
| 96 | return -1; |
| 97 | } |
| 98 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 99 | static void handle_uevent(hwc_context_t* ctx, const char* udata, int len) |
| 100 | { |
Veera Sankaran | 0dadfb3 | 2013-07-22 16:07:48 -0700 | [diff] [blame] | 101 | bool bpanelReset = getPanelResetStatus(ctx, udata, len); |
| 102 | if (bpanelReset) { |
radhakrishna | 5d24c25 | 2013-12-19 18:03:56 +0530 | [diff] [blame] | 103 | ctx->proc->invalidate(ctx->proc); |
Veera Sankaran | 0dadfb3 | 2013-07-22 16:07:48 -0700 | [diff] [blame] | 104 | return; |
| 105 | } |
| 106 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 107 | int dpy = getConnectedDisplay(udata); |
| 108 | if(dpy < 0) { |
| 109 | ALOGD_IF(UEVENT_DEBUG, "%s: Not disp Event ", __FUNCTION__); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 110 | return; |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 111 | } |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 112 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 113 | int switch_state = getConnectedState(udata, len); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 114 | |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 115 | ALOGE_IF(UEVENT_DEBUG,"%s: uevent received: %s switch state: %d", |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 116 | __FUNCTION__,udata, switch_state); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 117 | |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 118 | switch(switch_state) { |
| 119 | case EXTERNAL_OFFLINE: |
| 120 | { |
| 121 | /* Display not connected */ |
| 122 | if(!ctx->dpyAttr[dpy].connected){ |
| 123 | ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_OFFLINE event" |
| 124 | "for display: %d", __FUNCTION__, dpy); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 125 | break; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 126 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 127 | |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 128 | Locker::Autolock _l(ctx->mDrawLock); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 129 | clear(ctx, dpy); |
| 130 | ctx->dpyAttr[dpy].connected = false; |
| 131 | ctx->dpyAttr[dpy].isActive = false; |
| 132 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 133 | ctx->mExtDisplay->teardown(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 134 | |
| 135 | /* We need to send hotplug to SF only when we are disconnecting |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 136 | * HDMI */ |
| 137 | ALOGE_IF(UEVENT_DEBUG,"%s:Sending EXTERNAL OFFLINE hotplug" |
| 138 | "event", __FUNCTION__); |
| 139 | ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_OFFLINE); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 140 | break; |
| 141 | } |
| 142 | case EXTERNAL_ONLINE: |
| 143 | { |
| 144 | /* Display already connected */ |
| 145 | if(ctx->dpyAttr[dpy].connected) { |
| 146 | ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_ONLINE event" |
| 147 | "for display: %d", __FUNCTION__, dpy); |
| 148 | break; |
| 149 | } |
| 150 | { |
| 151 | //Force composition to give up resources like pipes and |
| 152 | //close fb. For example if assertive display is going on, |
| 153 | //fb2 could be open, thus connecting Layer Mixer#0 to |
| 154 | //WriteBack module. If HDMI attempts to open fb1, the driver |
| 155 | //will try to attach Layer Mixer#0 to HDMI INT, which will |
| 156 | //fail, since Layer Mixer#0 is still connected to WriteBack. |
| 157 | //This block will force composition to close fb2 in above |
| 158 | //example. |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 159 | Locker::Autolock _l(ctx->mDrawLock); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 160 | ctx->dpyAttr[dpy].isConfiguring = true; |
| 161 | ctx->proc->invalidate(ctx->proc); |
| 162 | } |
| 163 | //2 cycles for slower content |
| 164 | usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period |
| 165 | * 2 / 1000); |
| 166 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 167 | if(isVDConnected(ctx)) { |
| 168 | // Do not initiate WFD teardown if WFD architecture is based |
| 169 | // on VDS mechanism. |
| 170 | // WFD Stack listens to HDMI intent and initiates virtual |
| 171 | // display teardown. |
| 172 | // ToDo: Currently non-WFD Virtual display clients do not |
| 173 | // involve HWC. If there is a change, we need to come up |
| 174 | // with mechanism of how to address non-WFD Virtual display |
| 175 | // clients + HDMI |
| 176 | ctx->mWfdSyncLock.lock(); |
| 177 | ALOGD_IF(HWC_WFDDISPSYNC_LOG, |
| 178 | "%s: Waiting for wfd-teardown to be signalled", |
| 179 | __FUNCTION__); |
| 180 | ctx->mWfdSyncLock.wait(); |
| 181 | ALOGD_IF(HWC_WFDDISPSYNC_LOG, |
| 182 | "%s: Teardown signalled. Completed waiting in" |
| 183 | "uevent thread", __FUNCTION__); |
| 184 | ctx->mWfdSyncLock.unlock(); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 185 | } |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 186 | ctx->mExtDisplay->configure(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 187 | |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 188 | Locker::Autolock _l(ctx->mDrawLock); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 189 | setup(ctx, dpy); |
| 190 | ctx->dpyAttr[dpy].isPause = false; |
| 191 | ctx->dpyAttr[dpy].connected = true; |
| 192 | ctx->dpyAttr[dpy].isConfiguring = true; |
| 193 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 194 | /* External display is HDMI */ |
| 195 | ALOGE_IF(UEVENT_DEBUG, "%s: Sending EXTERNAL ONLINE" |
| 196 | "hotplug event", __FUNCTION__); |
| 197 | ctx->proc->hotplug(ctx->proc, dpy, EXTERNAL_ONLINE); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 198 | break; |
| 199 | } |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 200 | default: |
| 201 | { |
| 202 | ALOGE("%s: Invalid state to swtich:%d", __FUNCTION__, switch_state); |
| 203 | break; |
| 204 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 205 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void *uevent_loop(void *param) |
| 209 | { |
| 210 | int len = 0; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 211 | static char udata[PAGE_SIZE]; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 212 | hwc_context_t * ctx = reinterpret_cast<hwc_context_t *>(param); |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 213 | char thread_name[64] = HWC_UEVENT_THREAD_NAME; |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 214 | prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 215 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
Sravan Kumar D.V.N | 04ce9ad | 2013-10-23 15:57:57 +0530 | [diff] [blame] | 216 | if(!uevent_init()) { |
| 217 | ALOGE("%s: failed to init uevent ",__FUNCTION__); |
| 218 | return NULL; |
| 219 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 220 | |
| 221 | while(1) { |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 222 | len = uevent_next_event(udata, (int)sizeof(udata) - 2); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 223 | handle_uevent(ctx, udata, len); |
| 224 | } |
| 225 | |
| 226 | return NULL; |
| 227 | } |
| 228 | |
| 229 | void init_uevent_thread(hwc_context_t* ctx) |
| 230 | { |
| 231 | pthread_t uevent_thread; |
Iliyan Malchev | 0f9c397 | 2012-10-11 15:16:15 -0700 | [diff] [blame] | 232 | int ret; |
| 233 | |
| 234 | ALOGI("Initializing UEVENT Thread"); |
| 235 | ret = pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); |
| 236 | if (ret) { |
| 237 | ALOGE("%s: failed to create %s: %s", __FUNCTION__, |
| 238 | HWC_UEVENT_THREAD_NAME, strerror(ret)); |
| 239 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | }; //namespace |