/arch/arm/mach-msm/rpc_server_time_remote.c

https://bitbucket.org/sammyz/iscream_thunderc-2.6.35-rebase · C · 167 lines · 126 code · 22 blank · 19 comment · 11 complexity · 9863dfc31605e78af150661802e5761b MD5 · raw file

  1. /* arch/arm/mach-msm/rpc_server_time_remote.c
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. * Copyright (c) 2009-2010 Code Aurora Forum. All rights reserved.
  5. * Author: Iliyan Malchev <ibm@android.com>
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/err.h>
  20. #include <mach/msm_rpcrouter.h>
  21. #include "rpc_server_time_remote.h"
  22. #include <linux/rtc.h>
  23. #include <linux/android_alarm.h>
  24. /* time_remote_mtoa server definitions. */
  25. #define TIME_REMOTE_MTOA_PROG 0x3000005d
  26. #define TIME_REMOTE_MTOA_VERS_OLD 0
  27. #define TIME_REMOTE_MTOA_VERS 0x9202a8e4
  28. #define TIME_REMOTE_MTOA_VERS_COMP 0x00010002
  29. #define RPC_TIME_REMOTE_MTOA_NULL 0
  30. #define RPC_TIME_TOD_SET_APPS_BASES 2
  31. #define RPC_TIME_GET_APPS_USER_TIME 3
  32. struct rpc_time_tod_set_apps_bases_args {
  33. uint32_t tick;
  34. uint64_t stamp;
  35. };
  36. static int read_rtc0_time(struct msm_rpc_server *server,
  37. struct rpc_request_hdr *req,
  38. unsigned len)
  39. {
  40. int err;
  41. unsigned long tm_sec;
  42. uint32_t size = 0;
  43. void *reply;
  44. uint32_t output_valid;
  45. uint32_t rpc_status = RPC_ACCEPTSTAT_SYSTEM_ERR;
  46. struct rtc_time tm;
  47. struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
  48. if (rtc == NULL) {
  49. pr_err("%s: unable to open rtc device (%s)\n",
  50. __FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
  51. goto send_reply;
  52. }
  53. err = rtc_read_time(rtc, &tm);
  54. if (err) {
  55. pr_err("%s: Error reading rtc device (%s) : %d\n",
  56. __FILE__, CONFIG_RTC_HCTOSYS_DEVICE, err);
  57. goto close_dev;
  58. }
  59. err = rtc_valid_tm(&tm);
  60. if (err) {
  61. pr_err("%s: Invalid RTC time (%s)\n",
  62. __FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
  63. goto close_dev;
  64. }
  65. rtc_tm_to_time(&tm, &tm_sec);
  66. rpc_status = RPC_ACCEPTSTAT_SUCCESS;
  67. close_dev:
  68. rtc_class_close(rtc);
  69. send_reply:
  70. reply = msm_rpc_server_start_accepted_reply(server, req->xid,
  71. rpc_status);
  72. if (rpc_status == RPC_ACCEPTSTAT_SUCCESS) {
  73. output_valid = *((uint32_t *)(req + 1));
  74. *(uint32_t *)reply = output_valid;
  75. size = sizeof(uint32_t);
  76. if (be32_to_cpu(output_valid)) {
  77. reply += sizeof(uint32_t);
  78. *(uint32_t *)reply = cpu_to_be32(tm_sec);
  79. size += sizeof(uint32_t);
  80. }
  81. }
  82. err = msm_rpc_server_send_accepted_reply(server, size);
  83. if (err)
  84. pr_err("%s: send accepted reply failed: %d\n", __func__, err);
  85. return 1;
  86. }
  87. static int handle_rpc_call(struct msm_rpc_server *server,
  88. struct rpc_request_hdr *req, unsigned len)
  89. {
  90. struct timespec ts, tv;
  91. switch (req->procedure) {
  92. case RPC_TIME_REMOTE_MTOA_NULL:
  93. return 0;
  94. case RPC_TIME_TOD_SET_APPS_BASES: {
  95. struct rpc_time_tod_set_apps_bases_args *args;
  96. args = (struct rpc_time_tod_set_apps_bases_args *)(req + 1);
  97. args->tick = be32_to_cpu(args->tick);
  98. args->stamp = be64_to_cpu(args->stamp);
  99. printk(KERN_INFO "RPC_TIME_TOD_SET_APPS_BASES:\n"
  100. "\ttick = %d\n"
  101. "\tstamp = %lld\n",
  102. args->tick, args->stamp);
  103. getnstimeofday(&ts);
  104. rtc_hctosys();
  105. getnstimeofday(&tv);
  106. /* Update the alarm information with the new time info. */
  107. alarm_update_timedelta(ts, tv);
  108. return 0;
  109. }
  110. case RPC_TIME_GET_APPS_USER_TIME:
  111. return read_rtc0_time(server, req, len);
  112. default:
  113. return -ENODEV;
  114. }
  115. }
  116. static struct msm_rpc_server rpc_server[] = {
  117. {
  118. .prog = TIME_REMOTE_MTOA_PROG,
  119. .vers = TIME_REMOTE_MTOA_VERS_OLD,
  120. .rpc_call = handle_rpc_call,
  121. },
  122. {
  123. .prog = TIME_REMOTE_MTOA_PROG,
  124. .vers = TIME_REMOTE_MTOA_VERS,
  125. .rpc_call = handle_rpc_call,
  126. },
  127. {
  128. .prog = TIME_REMOTE_MTOA_PROG,
  129. .vers = TIME_REMOTE_MTOA_VERS_COMP,
  130. .rpc_call = handle_rpc_call,
  131. },
  132. };
  133. static int __init rpc_server_init(void)
  134. {
  135. /* Dual server registration to support backwards compatibility vers */
  136. int ret;
  137. ret = msm_rpc_create_server(&rpc_server[2]);
  138. if (ret < 0)
  139. return ret;
  140. ret = msm_rpc_create_server(&rpc_server[1]);
  141. if (ret < 0)
  142. return ret;
  143. return msm_rpc_create_server(&rpc_server[0]);
  144. }
  145. module_init(rpc_server_init);