camera_sysram_D1.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. #include <linux/uaccess.h>
  2. #include <linux/module.h>
  3. #include <linux/types.h>
  4. #include <linux/device.h>
  5. #include <linux/fs.h>
  6. #include <linux/platform_device.h>
  7. #include <linux/cdev.h>
  8. #include <linux/io.h>
  9. #include <linux/slab.h>
  10. #include <linux/proc_fs.h> /* proc file use */
  11. #include <linux/spinlock.h>
  12. #include <linux/mm.h>
  13. #include <linux/sched.h>
  14. #include <linux/delay.h>
  15. #include <linux/ioctl.h>
  16. #include "inc/mt_typedefs.h"
  17. #include <mach/mt_clkmgr.h>
  18. #include <mt-plat/sync_write.h>
  19. #include "inc/camera_sysram_D1.h"
  20. #include "inc/camera_sysram_imp_D1.h"
  21. /* ----------------------------------------------------------------------------- */
  22. #define ISP_VALID_REG_RANGE 0x10000
  23. #define IMGSYS_BASE_ADDR 0x15000000
  24. static SYSRAM_STRUCT Sysram;
  25. /* ------------------------------------------------------------------------------ */
  26. static void SYSRAM_GetTime(MUINT64 *pUS64, MUINT32 *pSec, MUINT32 *pUSec)
  27. {
  28. ktime_t Time;
  29. MUINT64 TimeSec;
  30. Time = ktime_get();/* ns */
  31. TimeSec = Time.tv64;
  32. do_div(TimeSec, 1000);
  33. *pUS64 = TimeSec;
  34. *pUSec = do_div(TimeSec, 1000000);
  35. *pSec = (MUINT64)TimeSec;
  36. }
  37. /* ------------------------------------------------------------------------------ */
  38. static void SYSRAM_CheckClock(void)
  39. {
  40. /* LOG_MSG("AllocatedTbl(0x%08X), EnableClk(%d)", Sysram.AllocatedTbl, Sysram.EnableClk); */
  41. if (Sysram.AllocatedTbl) {
  42. if (!(Sysram.EnableClk)) {
  43. Sysram.EnableClk = true;
  44. /*
  45. LOG_MSG("AllocatedTbl(0x%08lX), EnableClk(%d)",
  46. Sysram.AllocatedTbl,
  47. Sysram.EnableClk);
  48. */
  49. }
  50. } else{
  51. if (Sysram.EnableClk) {
  52. Sysram.EnableClk = false;
  53. /*
  54. LOG_MSG("AllocatedTbl(0x%08lX), EnableClk(%d)",
  55. Sysram.AllocatedTbl,
  56. Sysram.EnableClk);
  57. */
  58. }
  59. }
  60. }
  61. /* ------------------------------------------------------------------------------ */
  62. static void SYSRAM_DumpResMgr(void)
  63. {
  64. unsigned int u4Idx = 0;
  65. LOG_MSG("TotalUserCount(%ld), AllocatedTbl(0x%lX)",
  66. Sysram.TotalUserCount,
  67. Sysram.AllocatedTbl);
  68. for (u4Idx = 0; u4Idx < SYSRAM_USER_AMOUNT; u4Idx++) {
  69. if (0 < Sysram.AllocatedSize[u4Idx]) {
  70. SYSRAM_USER_STRUCT * const pUserInfo = &Sysram.UserInfo[u4Idx];
  71. LOG_MSG("[id:%u][%s][size:0x%lX][pid:%d][tgid:%d][%s][%5lu.%06lu]",
  72. u4Idx,
  73. SysramUserName[u4Idx],
  74. Sysram.AllocatedSize[u4Idx],
  75. pUserInfo->pid,
  76. pUserInfo->tgid,
  77. pUserInfo->ProcName,
  78. pUserInfo->TimeS,
  79. pUserInfo->TimeUS);
  80. }
  81. }
  82. LOG_MSG("End");
  83. }
  84. /* ------------------------------------------------------------------------------ */
  85. static inline MBOOL SYSRAM_IsBadOwner(SYSRAM_USER_ENUM const User)
  86. {
  87. if (SYSRAM_USER_AMOUNT <= User || User < 0)
  88. return MTRUE;
  89. else
  90. return MFALSE;
  91. }
  92. /* ------------------------------------------------------------------------------ */
  93. static void SYSRAM_SetUserTaskInfo(SYSRAM_USER_ENUM const User)
  94. {
  95. if (!SYSRAM_IsBadOwner(User)) {
  96. SYSRAM_USER_STRUCT * const pUserInfo = &Sysram.UserInfo[User];
  97. pUserInfo->pid = current->pid;
  98. pUserInfo->tgid = current->tgid;
  99. memcpy(pUserInfo->ProcName, current->comm, sizeof(pUserInfo->ProcName));
  100. SYSRAM_GetTime(&(pUserInfo->Time64), &(pUserInfo->TimeS), &(pUserInfo->TimeUS));
  101. }
  102. }
  103. /* ------------------------------------------------------------------------------ */
  104. static void SYSRAM_ResetUserTaskInfo(SYSRAM_USER_ENUM const User)
  105. {
  106. if (!SYSRAM_IsBadOwner(User)) {
  107. SYSRAM_USER_STRUCT * const pUserInfo = &Sysram.UserInfo[User];
  108. memset(pUserInfo, 0, sizeof(*pUserInfo));
  109. }
  110. }
  111. /* ------------------------------------------------------------------------------ */
  112. static inline void SYSRAM_SpinLock(void)
  113. {
  114. spin_lock(&Sysram.SpinLock);
  115. }
  116. /* ------------------------------------------------------------------------------ */
  117. static inline void SYSRAM_SpinUnlock(void)
  118. {
  119. spin_unlock(&Sysram.SpinLock);
  120. }
  121. /* ------------------------------------------------------------------------------ */
  122. static inline MBOOL SYSRAM_UserIsLocked(SYSRAM_USER_ENUM const User)
  123. {
  124. if ((1 << User) & Sysram.AllocatedTbl)
  125. return MTRUE;
  126. else
  127. return MFALSE;
  128. }
  129. /* ------------------------------------------------------------------------------ */
  130. static inline MBOOL SYSRAM_UserIsUnlocked(SYSRAM_USER_ENUM const User)
  131. {
  132. if (SYSRAM_UserIsLocked(User) == 0)
  133. return MTRUE;
  134. else
  135. return MFALSE;
  136. }
  137. /* ------------------------------------------------------------------------------ */
  138. static void SYSRAM_LockUser(SYSRAM_USER_ENUM const User, MUINT32 const Size)
  139. {
  140. if (SYSRAM_UserIsLocked(User))
  141. return;
  142. Sysram.TotalUserCount++;
  143. Sysram.AllocatedTbl |= (1 << User);
  144. Sysram.AllocatedSize[User] = Size;
  145. SYSRAM_SetUserTaskInfo(User);
  146. /* Debug Log. */
  147. if ((1<<User) & SysramLogUserMask) {
  148. SYSRAM_USER_STRUCT * const pUserInfo = &Sysram.UserInfo[User];
  149. LOG_MSG("[%s][%lu bytes]OK, Time(%lu.%06lu)",
  150. SysramUserName[User],
  151. Sysram.AllocatedSize[User],
  152. pUserInfo->TimeS,
  153. pUserInfo->TimeUS);
  154. }
  155. }
  156. /* ------------------------------------------------------------------------------ */
  157. static void SYSRAM_UnlockUser(SYSRAM_USER_ENUM const User)
  158. {
  159. if (SYSRAM_UserIsUnlocked(User))
  160. return;
  161. /* Debug Log. */
  162. if ((1<<User) & SysramLogUserMask) {
  163. SYSRAM_USER_STRUCT * const pUserInfo = &Sysram.UserInfo[User];
  164. MUINT32 Sec, USec;
  165. MUINT64 Time64 = 0;
  166. SYSRAM_GetTime(&Time64, &Sec, &USec);
  167. LOG_MSG("[%s][%lu bytes]Time(%lu.%06lu - %lu.%06lu)(%lu.%06lu)",
  168. SysramUserName[User],
  169. Sysram.AllocatedSize[User],
  170. pUserInfo->TimeS,
  171. pUserInfo->TimeUS,
  172. Sec,
  173. USec,
  174. ((MUINT32)(Time64-pUserInfo->Time64))/1000,
  175. ((MUINT32)(Time64-pUserInfo->Time64))%1000);
  176. }
  177. if (Sysram.TotalUserCount > 0)
  178. Sysram.TotalUserCount--;
  179. Sysram.AllocatedTbl &= (~(1 << User));
  180. Sysram.AllocatedSize[User] = 0;
  181. SYSRAM_ResetUserTaskInfo(User);
  182. }
  183. /* ------------------------------------------------------------------------------ */
  184. static void SYSRAM_DumpLayout(void)
  185. {
  186. MUINT32 Index = 0;
  187. SYSRAM_MEM_NODE_STRUCT *pCurrNode = NULL;
  188. LOG_DMP("[SYSRAM_DumpLayout]\n");
  189. LOG_DMP("AllocatedTbl = 0x%08lX\n", Sysram.AllocatedTbl);
  190. LOG_DMP("=========================================\n");
  191. for (Index = 0; Index < SYSRAM_MEM_BANK_AMOUNT; Index++) {
  192. LOG_DMP("\n [Mem Pool %ld] (IndexTbl, UserCount)=(%lX, %ld)\n",
  193. Index,
  194. SysramMemPoolInfo[Index].IndexTbl,
  195. SysramMemPoolInfo[Index].UserCount);
  196. LOG_DMP("[Locked Time] [Owner Offset Size Index pCurrent pPrevious pNext] [pid tgid] [Proc Name / Owner Name]\n");
  197. pCurrNode = &SysramMemPoolInfo[Index].pMemNode[0];
  198. while (NULL != pCurrNode) {
  199. SYSRAM_USER_ENUM const User = pCurrNode->User;
  200. if (SYSRAM_IsBadOwner(User)) {
  201. LOG_DMP(
  202. "------------ -------- "
  203. " %2d\t0x%05lX 0x%05lX %ld %p %p\t%p\n",
  204. pCurrNode->User,
  205. pCurrNode->Offset,
  206. pCurrNode->Length,
  207. pCurrNode->Index,
  208. pCurrNode,
  209. pCurrNode->pPrev,
  210. pCurrNode->pNext);
  211. } else{
  212. SYSRAM_USER_STRUCT * const pUserInfo = &Sysram.UserInfo[User];
  213. LOG_DMP("%5lu.%06lu "
  214. " %2d\t0x%05lX 0x%05lX %ld %p %p\t%p "
  215. " %-4d %-4d \"%s\" / \"%s\"\n",
  216. pUserInfo->TimeS,
  217. pUserInfo->TimeUS,
  218. User,
  219. pCurrNode->Offset,
  220. pCurrNode->Length,
  221. pCurrNode->Index,
  222. pCurrNode,
  223. pCurrNode->pPrev,
  224. pCurrNode->pNext,
  225. pUserInfo->pid,
  226. pUserInfo->tgid,
  227. pUserInfo->ProcName,
  228. SysramUserName[User]);
  229. }
  230. pCurrNode = pCurrNode->pNext;
  231. };
  232. }
  233. LOG_DMP("\n");
  234. SYSRAM_DumpResMgr();
  235. }
  236. /* ------------------------------------------------------------------------------ */
  237. static SYSRAM_MEM_NODE_STRUCT *SYSRAM_AllocNode(SYSRAM_MEM_POOL_STRUCT * const pMemPoolInfo)
  238. {
  239. SYSRAM_MEM_NODE_STRUCT *pNode = NULL;
  240. MUINT32 Index = 0;
  241. for (Index = 0; Index < pMemPoolInfo->UserAmount; Index += 1) {
  242. if ((pMemPoolInfo->IndexTbl) & (1 << Index)) {
  243. pMemPoolInfo->IndexTbl &= (~(1 << Index));
  244. /* A free node is found. */
  245. pNode = &pMemPoolInfo->pMemNode[Index];
  246. pNode->User = SYSRAM_USER_NONE;
  247. pNode->Offset = 0;
  248. pNode->Length = 0;
  249. pNode->pPrev = NULL;
  250. pNode->pNext = NULL;
  251. pNode->Index = Index;
  252. break;
  253. }
  254. }
  255. /* Shouldn't happen. */
  256. if (!pNode)
  257. LOG_ERR("returns NULL - pMemPoolInfo->IndexTbl(%lX)", pMemPoolInfo->IndexTbl);
  258. return pNode;
  259. }
  260. /* ------------------------------------------------------------------------------ */
  261. static void SYSRAM_FreeNode(
  262. SYSRAM_MEM_POOL_STRUCT * const pMemPoolInfo,
  263. SYSRAM_MEM_NODE_STRUCT * const pNode)
  264. {
  265. pMemPoolInfo->IndexTbl |= (1<<pNode->Index);
  266. pNode->User = SYSRAM_USER_NONE;
  267. pNode->Offset = 0;
  268. pNode->Length = 0;
  269. pNode->pPrev = NULL;
  270. pNode->pNext = NULL;
  271. pNode->Index = 0;
  272. }
  273. /* ------------------------------------------------------------------------------ */
  274. static MBOOL SYSRAM_IsLegalSizeToAlloc(
  275. SYSRAM_MEM_BANK_ENUM const MemBankNo,
  276. SYSRAM_USER_ENUM const User,
  277. MUINT32 const Size)
  278. {
  279. MUINT32 MaxSize = 0;
  280. /* (1) Check the memory pool. */
  281. switch (MemBankNo) {
  282. case SYSRAM_MEM_BANK_BAD:
  283. case SYSRAM_MEM_BANK_AMOUNT:
  284. {
  285. /* Illegal Memory Pool: return "illegal" */
  286. /* Shouldn't happen. */
  287. goto EXIT;
  288. }
  289. default:
  290. break;
  291. }
  292. /* (2) */
  293. /* Here we use the dynamic memory pools. */
  294. MaxSize = SysramUserSize[User];
  295. EXIT:
  296. if (MaxSize < Size) {
  297. LOG_ERR("[User:%s]requested size(0x%lX) > max size(0x%lX)",
  298. SysramUserName[User],
  299. Size,
  300. MaxSize);
  301. SYSRAM_DumpLayout();
  302. return MFALSE;
  303. }
  304. return MTRUE;
  305. }
  306. /* ------------------------------------------------------------------------------ */
  307. /*
  308. Alignment should be 2^N, 4/8/2048 bytes alignment only
  309. First fit algorithm
  310. */
  311. static MUINT32 SYSRAM_AllocUserPhy(
  312. SYSRAM_USER_ENUM const User,
  313. MUINT32 const Size,
  314. MUINT32 const Alignment,
  315. SYSRAM_MEM_BANK_ENUM const MemBankNo
  316. )
  317. {
  318. SYSRAM_MEM_NODE_STRUCT *pSplitNode = NULL;
  319. SYSRAM_MEM_NODE_STRUCT *pCurrNode = NULL;
  320. MUINT32 AlingnedAddr = 0;
  321. MUINT32 ActualSize = 0;
  322. SYSRAM_MEM_POOL_STRUCT * const pMemPoolInfo = SYSRAM_GetMemPoolInfo(MemBankNo);
  323. if (!pMemPoolInfo)
  324. return 0;
  325. pCurrNode = &pMemPoolInfo->pMemNode[0];
  326. for (; pCurrNode && pCurrNode->Offset < pMemPoolInfo->Size; pCurrNode = pCurrNode->pNext) {
  327. if (SYSRAM_USER_NONE == pCurrNode->User) {
  328. /* Free space */
  329. AlingnedAddr = (pCurrNode->Offset + Alignment - 1)&(~(Alignment - 1));
  330. ActualSize = Size + AlingnedAddr - pCurrNode->Offset;
  331. if (ActualSize <= pCurrNode->Length) {
  332. /* Hit!! Split into 2 */
  333. /* pSplitNode pointers to the next available (free) node. */
  334. pSplitNode = SYSRAM_AllocNode(pMemPoolInfo);
  335. pSplitNode->Offset = pCurrNode->Offset + ActualSize;
  336. pSplitNode->Length = pCurrNode->Length - ActualSize;
  337. pSplitNode->pPrev = pCurrNode;
  338. pSplitNode->pNext = pCurrNode->pNext;
  339. pCurrNode->User = User;
  340. pCurrNode->Length = ActualSize;
  341. pCurrNode->pNext = pSplitNode;
  342. if (NULL != pSplitNode->pNext)
  343. pSplitNode->pNext->pPrev = pSplitNode;
  344. pMemPoolInfo->UserCount++;
  345. break;
  346. }
  347. /* Not hit */
  348. ActualSize = 0;
  349. }
  350. };
  351. return ActualSize ? (AlingnedAddr + pMemPoolInfo->Addr) : 0;
  352. }
  353. /* ------------------------------------------------------------------------------ */
  354. static MBOOL SYSRAM_FreeUserPhy(
  355. SYSRAM_USER_ENUM const User,
  356. SYSRAM_MEM_BANK_ENUM const MemBankNo)
  357. {
  358. MBOOL Ret = MFALSE;
  359. SYSRAM_MEM_NODE_STRUCT *pPrevOrNextNode = NULL;
  360. SYSRAM_MEM_NODE_STRUCT *pCurrNode = NULL;
  361. SYSRAM_MEM_NODE_STRUCT *pTempNode = NULL;
  362. SYSRAM_MEM_POOL_STRUCT * const pMemPoolInfo = SYSRAM_GetMemPoolInfo(MemBankNo);
  363. if (!pMemPoolInfo) {
  364. LOG_ERR("pMemPoolInfo==NULL, User(%d), MemBankNo(%d)", User, MemBankNo);
  365. return MFALSE;
  366. }
  367. pCurrNode = &pMemPoolInfo->pMemNode[0];
  368. for (; pCurrNode; pCurrNode = pCurrNode->pNext) {
  369. if (User == pCurrNode->User) {
  370. Ret = MTRUE; /* user is found. */
  371. if (pMemPoolInfo->UserCount > 0)
  372. pMemPoolInfo->UserCount--;
  373. pCurrNode->User = SYSRAM_USER_NONE;
  374. if (NULL != pCurrNode->pPrev) {
  375. pPrevOrNextNode = pCurrNode->pPrev;
  376. if (SYSRAM_USER_NONE == pPrevOrNextNode->User) {
  377. /* Merge previous: prev(o) + curr(x) */
  378. pTempNode = pCurrNode;
  379. pCurrNode = pPrevOrNextNode;
  380. pCurrNode->Length += pTempNode->Length;
  381. pCurrNode->pNext = pTempNode->pNext;
  382. if (NULL != pTempNode->pNext)
  383. pTempNode->pNext->pPrev = pCurrNode;
  384. SYSRAM_FreeNode(pMemPoolInfo, pTempNode);
  385. }
  386. }
  387. if (NULL != pCurrNode->pNext) {
  388. pPrevOrNextNode = pCurrNode->pNext;
  389. if (SYSRAM_USER_NONE == pPrevOrNextNode->User) {
  390. /* Merge next: curr(o) + next(x) */
  391. pTempNode = pPrevOrNextNode;
  392. pCurrNode->Length += pTempNode->Length;
  393. pCurrNode->pNext = pTempNode->pNext;
  394. if (NULL != pCurrNode->pNext)
  395. pCurrNode->pNext->pPrev = pCurrNode;
  396. SYSRAM_FreeNode(pMemPoolInfo, pTempNode);
  397. }
  398. }
  399. break;
  400. }
  401. }
  402. return Ret;
  403. }
  404. /* ------------------------------------------------------------------------------ */
  405. static MUINT32 SYSRAM_AllocUser(
  406. SYSRAM_USER_ENUM const User,
  407. MUINT32 Size,
  408. MUINT32 const Alignment)
  409. {
  410. MUINT32 Addr = 0;
  411. SYSRAM_MEM_BANK_ENUM const MemBankNo = SYSRAM_GetMemBankNo(User);
  412. if (SYSRAM_IsBadOwner(User)) {
  413. LOG_ERR("User(%d) out of range(%d)", User, SYSRAM_USER_AMOUNT);
  414. return 0;
  415. }
  416. if (!SYSRAM_IsLegalSizeToAlloc(MemBankNo, User, Size))
  417. return 0;
  418. switch (MemBankNo) {
  419. case SYSRAM_MEM_BANK_BAD:
  420. case SYSRAM_MEM_BANK_AMOUNT:
  421. {
  422. /* Do nothing. */
  423. break;
  424. }
  425. default:
  426. {
  427. Addr = SYSRAM_AllocUserPhy(
  428. User,
  429. Size,
  430. Alignment,
  431. MemBankNo);
  432. break;
  433. }
  434. }
  435. if (0 < Addr)
  436. SYSRAM_LockUser(User, Size);
  437. return Addr;
  438. }
  439. /* ------------------------------------------------------------------------------ */
  440. static void SYSRAM_FreeUser(SYSRAM_USER_ENUM const User)
  441. {
  442. SYSRAM_MEM_BANK_ENUM const MemBankNo = SYSRAM_GetMemBankNo(User);
  443. switch (MemBankNo) {
  444. case SYSRAM_MEM_BANK_BAD:
  445. case SYSRAM_MEM_BANK_AMOUNT:
  446. {
  447. /* Do nothing. */
  448. break;
  449. }
  450. default:
  451. {
  452. if (SYSRAM_FreeUserPhy(User, MemBankNo)) {
  453. SYSRAM_UnlockUser(User);
  454. } else{
  455. LOG_ERR("Cannot free User(%d)", User);
  456. SYSRAM_DumpLayout();
  457. }
  458. break;
  459. }
  460. }
  461. }
  462. /* ------------------------------------------------------------------------------ */
  463. static MUINT32 SYSRAM_MsToJiffies(MUINT32 TimeMs)
  464. {
  465. return (TimeMs*HZ + 512) >> 10;
  466. }
  467. /* ------------------------------------------------------------------------------ */
  468. static MUINT32 SYSRAM_TryAllocUser(
  469. SYSRAM_USER_ENUM const User,
  470. MUINT32 const Size,
  471. MUINT32 const Alignment)
  472. {
  473. MUINT32 Addr = 0;
  474. SYSRAM_SpinLock();
  475. if (SYSRAM_UserIsLocked(User)) {
  476. SYSRAM_SpinUnlock();
  477. LOG_ERR("[User:%s]has been already allocated!", SysramUserName[User]);
  478. return 0;
  479. }
  480. Addr = SYSRAM_AllocUser(User, Size, Alignment);
  481. if (Addr != 0)
  482. SYSRAM_CheckClock();
  483. SYSRAM_SpinUnlock();
  484. return Addr;
  485. }
  486. /* ------------------------------------------------------------------------------ */
  487. static MUINT32 SYSRAM_IOC_Alloc(
  488. SYSRAM_USER_ENUM const User,
  489. MUINT32 const Size,
  490. MUINT32 Alignment,
  491. MUINT32 const TimeoutMS)
  492. {
  493. MUINT32 Addr = 0;
  494. INT32 TimeOut = 0;
  495. if (SYSRAM_IsBadOwner(User)) {
  496. LOG_ERR("User(%d) out of range(%d)", User, SYSRAM_USER_AMOUNT);
  497. return 0;
  498. }
  499. if (0 == Size) {
  500. LOG_ERR("[User:%s]allocates 0 size!", SysramUserName[User]);
  501. return 0;
  502. }
  503. Addr = SYSRAM_TryAllocUser(User, Size, Alignment);
  504. if (0 != Addr /* success */
  505. || 0 == TimeoutMS /* failure without a timeout specified */)
  506. goto EXIT;
  507. TimeOut = wait_event_interruptible_timeout(
  508. Sysram.WaitQueueHead,
  509. 0 != (Addr = SYSRAM_TryAllocUser(User, Size, Alignment)),
  510. SYSRAM_MsToJiffies(TimeoutMS));
  511. if (0 == TimeOut && 0 == Addr)
  512. LOG_ERR("[User:%s]allocate timeout", SysramUserName[User]);
  513. EXIT:
  514. if (0 == Addr) { /* Failure */
  515. LOG_ERR("[User:%s]fails to allocate.Size(%lu), Alignment(%lu), TimeoutMS(%lu)",
  516. SysramUserName[User],
  517. Size,
  518. Alignment,
  519. TimeoutMS);
  520. SYSRAM_DumpLayout();
  521. } else{ /* Success */
  522. if ((1<<User) & SysramLogUserMask) {
  523. LOG_MSG("[User:%s]%lu bytes OK",
  524. SysramUserName[User],
  525. Size);
  526. }
  527. }
  528. return Addr;
  529. }
  530. /* ------------------------------------------------------------------------------ */
  531. static void SYSRAM_IOC_Free(SYSRAM_USER_ENUM User)
  532. {
  533. if (SYSRAM_IsBadOwner(User)) {
  534. LOG_ERR("User(%d) out of range(%d)", User, SYSRAM_USER_AMOUNT);
  535. return;
  536. }
  537. SYSRAM_SpinLock();
  538. SYSRAM_FreeUser(User);
  539. wake_up_interruptible(&Sysram.WaitQueueHead);
  540. SYSRAM_CheckClock();
  541. SYSRAM_SpinUnlock();
  542. if ((1<<User) & SysramLogUserMask)
  543. LOG_MSG("[User:%s]Done", SysramUserName[User]);
  544. }
  545. /* ------------------------------------------------------------------------------ */
  546. static int SYSRAM_Open(
  547. struct inode *pInode,
  548. struct file *pFile)
  549. {
  550. int Ret = 0;
  551. MUINT32 Sec = 0, USec = 0;
  552. MUINT64 Time64 = 0;
  553. SYSRAM_PROC_STRUCT *pProc;
  554. SYSRAM_GetTime(&Time64, &Sec, &USec);
  555. LOG_MSG("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  556. current->comm,
  557. current->pid,
  558. current->tgid,
  559. Sec,
  560. USec);
  561. SYSRAM_SpinLock();
  562. pFile->private_data = kmalloc(sizeof(SYSRAM_PROC_STRUCT) , GFP_ATOMIC);
  563. if (pFile->private_data == NULL) {
  564. Ret = -ENOMEM;
  565. } else{
  566. pProc = (SYSRAM_PROC_STRUCT *)(pFile->private_data);
  567. pProc->Pid = 0;
  568. pProc->Tgid = 0;
  569. strcpy(pProc->ProcName, SYSRAM_PROC_NAME);
  570. pProc->Table = 0;
  571. pProc->Time64 = Time64;
  572. pProc->TimeS = Sec;
  573. pProc->TimeUS = USec;
  574. }
  575. SYSRAM_SpinUnlock();
  576. if (Ret == (-ENOMEM)) {
  577. LOG_ERR("No enough memory");
  578. /*
  579. LOG_ERR("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  580. current->comm,
  581. current->pid,
  582. current->tgid,
  583. Sec,
  584. USec);
  585. */
  586. }
  587. return Ret;
  588. }
  589. /* ------------------------------------------------------------------------------ */
  590. static int SYSRAM_Release(
  591. struct inode *pInode,
  592. struct file *pFile)
  593. {
  594. MUINT32 Index = 0;
  595. MUINT32 Sec = 0, USec = 0;
  596. MUINT64 Time64 = 0;
  597. SYSRAM_PROC_STRUCT *pProc;
  598. SYSRAM_GetTime(&Time64, &Sec, &USec);
  599. LOG_MSG("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  600. current->comm,
  601. current->pid,
  602. current->tgid,
  603. Sec,
  604. USec);
  605. if (pFile->private_data != NULL) {
  606. pProc = (SYSRAM_PROC_STRUCT *)(pFile->private_data);
  607. if (pProc->Pid != 0 ||
  608. pProc->Tgid != 0 ||
  609. pProc->Table != 0) {
  610. /* */
  611. LOG_WRN("Proc:Name(%s), pid(%d), tgid(%d), Table(0x%08lX), Time(%ld.%06ld)",
  612. pProc->ProcName,
  613. pProc->Pid,
  614. pProc->Tgid,
  615. pProc->Table,
  616. pProc->TimeS,
  617. pProc->TimeUS);
  618. if (pProc->Table) {
  619. LOG_WRN("Force to release");
  620. /*
  621. LOG_WRN("Proc:Name(%s), pid(%d), tgid(%d), Table(0x%08lX), Time(%ld.%06ld)",
  622. pProc->ProcName,
  623. pProc->Pid,
  624. pProc->Tgid,
  625. pProc->Table,
  626. pProc->TimeS,
  627. pProc->TimeUS);
  628. */
  629. SYSRAM_DumpLayout();
  630. for (Index = 0; Index < SYSRAM_USER_AMOUNT; Index++) {
  631. if (pProc->Table & (1 << Index))
  632. SYSRAM_IOC_Free((SYSRAM_USER_ENUM)Index);
  633. }
  634. }
  635. }
  636. kfree(pFile->private_data);
  637. pFile->private_data = NULL;
  638. } else{
  639. LOG_WRN("private_data is NULL");
  640. /*
  641. LOG_WRN("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  642. current->comm,
  643. current->pid,
  644. current->tgid,
  645. Sec,
  646. USec);
  647. */
  648. }
  649. return 0;
  650. }
  651. /* ------------------------------------------------------------------------------ */
  652. static int SYSRAM_Flush(
  653. struct file *pFile,
  654. fl_owner_t Id)
  655. {
  656. MUINT32 Index = 0;
  657. MUINT32 Sec = 0, USec = 0;
  658. MUINT64 Time64 = 0;
  659. SYSRAM_PROC_STRUCT *pProc;
  660. SYSRAM_GetTime(&Time64, &Sec, &USec);
  661. LOG_MSG("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  662. current->comm,
  663. current->pid,
  664. current->tgid,
  665. Sec,
  666. USec);
  667. if (pFile->private_data != NULL) {
  668. pProc = (SYSRAM_PROC_STRUCT *)pFile->private_data;
  669. if (pProc->Pid != 0 ||
  670. pProc->Tgid != 0 ||
  671. pProc->Table != 0) {
  672. /* */
  673. LOG_WRN("Proc:Name(%s), pid(%d), tgid(%d), Table(0x%08lX), Time(%ld.%06ld)",
  674. pProc->ProcName,
  675. pProc->Pid,
  676. pProc->Tgid,
  677. pProc->Table,
  678. pProc->TimeS,
  679. pProc->TimeUS);
  680. if (pProc->Tgid == 0 && pProc->Table != 0) {
  681. LOG_ERR("No Tgid info");
  682. /*
  683. LOG_ERR("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  684. current->comm,
  685. current->pid,
  686. current->tgid,
  687. Sec,
  688. USec);
  689. LOG_ERR("Proc:Name(%s), pid(%d), tgid(%d), Table(0x%08lX), Time(%ld.%06ld)",
  690. pProc->ProcName,
  691. pProc->Pid,
  692. pProc->Tgid,
  693. pProc->Table,
  694. pProc->TimeS,
  695. pProc->TimeUS);
  696. */
  697. } else{
  698. if ((pProc->Tgid == current->tgid) ||
  699. ((pProc->Tgid != current->tgid) && (strcmp(current->comm, "binder") == 0))) {
  700. /* */
  701. if (pProc->Table) {
  702. LOG_WRN("Force to release");
  703. /*
  704. LOG_WRN("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  705. current->comm,
  706. current->pid,
  707. current->tgid,
  708. Sec,
  709. USec);
  710. */
  711. SYSRAM_DumpLayout();
  712. for (Index = 0; Index < SYSRAM_USER_AMOUNT; Index++) {
  713. if (pProc->Table & (1 << Index))
  714. SYSRAM_IOC_Free((SYSRAM_USER_ENUM)Index);
  715. }
  716. pProc->Table = 0;
  717. }
  718. }
  719. }
  720. }
  721. } else{
  722. LOG_WRN("private_data is NULL");
  723. /*
  724. LOG_WRN("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  725. current->comm,
  726. current->pid,
  727. current->tgid,
  728. Sec,
  729. USec);
  730. */
  731. }
  732. return 0;
  733. }
  734. /* ------------------------------------------------------------------------------ */
  735. static int SYSRAM_mmap(
  736. struct file *pFile,
  737. struct vm_area_struct *pVma)
  738. {
  739. long length = 0;
  740. MUINT32 pfn = 0x0;
  741. /* LOG_MSG(""); */
  742. pVma->vm_page_prot = pgprot_noncached(pVma->vm_page_prot);
  743. length = pVma->vm_end - pVma->vm_start;
  744. pfn = pVma->vm_pgoff<<PAGE_SHIFT;/* page from number, physical address of kernel memory */
  745. LOG_WRN("pVma->vm_pgoff(0x%lx), phy(0x%lx), pVmapVma->vm_start(0x%lx), pVma->vm_end(0x%lx), length(%lx)",
  746. pVma->vm_pgoff, pVma->vm_pgoff<<PAGE_SHIFT, pVma->vm_start, pVma->vm_end, length);
  747. if ((length > ISP_VALID_REG_RANGE) ||
  748. (pfn < IMGSYS_BASE_ADDR) ||
  749. (pfn > (IMGSYS_BASE_ADDR+ISP_VALID_REG_RANGE))) {
  750. LOG_ERR("mmap range error : vm_start(0x%lx), vm_end(0x%lx), length(%lx), pfn(%u)!",
  751. pVma->vm_start, pVma->vm_end, length, (unsigned int)pfn);
  752. return -EAGAIN;
  753. }
  754. if (remap_pfn_range(
  755. pVma,
  756. pVma->vm_start,
  757. pVma->vm_pgoff,
  758. pVma->vm_end - pVma->vm_start,
  759. pVma->vm_page_prot)) {
  760. /* */
  761. LOG_ERR("fail");
  762. return -EAGAIN;
  763. }
  764. return 0;
  765. }
  766. /* ------------------------------------------------------------------------------ */
  767. static long SYSRAM_Ioctl(
  768. struct file *pFile,
  769. unsigned int Cmd,
  770. unsigned long Param)
  771. {
  772. MINT32 Ret = 0;
  773. MUINT32 Sec = 0, USec = 0;
  774. MUINT64 Time64 = 0;
  775. SYSRAM_PROC_STRUCT *pProc = (SYSRAM_PROC_STRUCT *)pFile->private_data;
  776. SYSRAM_ALLOC_STRUCT Alloc;
  777. SYSRAM_USER_ENUM User;
  778. SYSRAM_GetTime(&Time64, &Sec, &USec);
  779. /*
  780. LOG_MSG("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  781. current->comm,
  782. current->pid,
  783. current->tgid,
  784. Sec,
  785. USec);
  786. */
  787. if (pFile->private_data == NULL) {
  788. LOG_WRN("private_data is NULL.");
  789. Ret = -EFAULT;
  790. goto EXIT;
  791. }
  792. switch (Cmd) {
  793. case SYSRAM_ALLOC:
  794. {
  795. if (copy_from_user(&Alloc, (void *)Param, sizeof(SYSRAM_ALLOC_STRUCT)) == 0) {
  796. Alloc.Addr = SYSRAM_IOC_Alloc(
  797. Alloc.User,
  798. Alloc.Size,
  799. Alloc.Alignment,
  800. Alloc.TimeoutMS);
  801. if (Alloc.Addr != 0) {
  802. SYSRAM_SpinLock();
  803. pProc->Table |= (1 << Alloc.User);
  804. if (pProc->Tgid == 0) {
  805. pProc->Pid = current->pid;
  806. pProc->Tgid = current->tgid;
  807. strcpy(pProc->ProcName, current->comm);
  808. SYSRAM_SpinUnlock();
  809. } else{
  810. SYSRAM_SpinUnlock();
  811. if (pProc->Tgid != current->tgid) {
  812. LOG_ERR("Tgid is inconsistent");
  813. Ret = -EFAULT;
  814. }
  815. }
  816. } else{
  817. Ret = -EFAULT;
  818. }
  819. if (copy_to_user((void *)Param, &Alloc, sizeof(SYSRAM_ALLOC_STRUCT))) {
  820. LOG_ERR("copy to user failed");
  821. Ret = -EFAULT;
  822. }
  823. } else{
  824. LOG_ERR("copy_from_user fail");
  825. Ret = -EFAULT;
  826. }
  827. break;
  828. }
  829. case SYSRAM_FREE:
  830. {
  831. if (copy_from_user(&User, (void *)Param, sizeof(SYSRAM_USER_ENUM)) == 0) {
  832. SYSRAM_SpinLock();
  833. if ((pProc->Table) & (1 << User)) {
  834. SYSRAM_SpinUnlock();
  835. SYSRAM_IOC_Free(User);
  836. SYSRAM_SpinLock();
  837. pProc->Table &= (~(1 << User));
  838. if (pProc->Table == 0) {
  839. pProc->Pid = 0;
  840. pProc->Tgid = 0;
  841. strcpy(pProc->ProcName, SYSRAM_PROC_NAME);
  842. }
  843. SYSRAM_SpinUnlock();
  844. } else{
  845. SYSRAM_SpinUnlock();
  846. LOG_WRN("Freeing unallocated buffer user(%d)", User);
  847. Ret = -EFAULT;
  848. }
  849. } else{
  850. LOG_ERR("copy_from_user fail");
  851. Ret = -EFAULT;
  852. }
  853. break;
  854. }
  855. case SYSRAM_DUMP:
  856. {
  857. SYSRAM_DumpLayout();
  858. break;
  859. }
  860. default:
  861. {
  862. LOG_WRN("No such command");
  863. Ret = -EINVAL;
  864. break;
  865. }
  866. }
  867. EXIT:
  868. if (Ret != 0) {
  869. LOG_ERR("Fail");
  870. LOG_ERR("Cur:Name(%s), pid(%d), tgid(%d), Time(%ld.%06ld)",
  871. current->comm,
  872. current->pid,
  873. current->tgid,
  874. Sec,
  875. USec);
  876. if (pFile->private_data != NULL) {
  877. LOG_ERR("Proc:Name(%s), pid(%d), tgid(%d), Table(0x%08lX), Time(%ld.%06ld)",
  878. pProc->ProcName,
  879. pProc->Pid,
  880. pProc->Tgid,
  881. pProc->Table,
  882. Sec,
  883. USec);
  884. }
  885. }
  886. return Ret;
  887. }
  888. /* ------------------------------------------------------------------------------ */
  889. static const struct file_operations SysramFileOper = {
  890. .owner = THIS_MODULE,
  891. .open = SYSRAM_Open,
  892. .release = SYSRAM_Release,
  893. .flush = SYSRAM_Flush,
  894. .unlocked_ioctl = SYSRAM_Ioctl,
  895. .mmap = SYSRAM_mmap,
  896. };
  897. /* ------------------------------------------------------------------------------ */
  898. static inline int SYSRAM_RegCharDrv(void)
  899. {
  900. LOG_MSG("E");
  901. if (alloc_chrdev_region(&Sysram.DevNo, 0, 1, SYSRAM_DEV_NAME)) {
  902. LOG_ERR("allocate device no failed");
  903. return -EAGAIN;
  904. }
  905. /* allocate driver */
  906. Sysram.pCharDrv = cdev_alloc();
  907. if (Sysram.pCharDrv == NULL) {
  908. unregister_chrdev_region(Sysram.DevNo, 1);
  909. LOG_ERR("allocate mem for kobject failed");
  910. return -ENOMEM;
  911. }
  912. /* Attatch file operation. */
  913. cdev_init(Sysram.pCharDrv, &SysramFileOper);
  914. Sysram.pCharDrv->owner = THIS_MODULE;
  915. /* Add to system */
  916. if (cdev_add(Sysram.pCharDrv, Sysram.DevNo, 1)) {
  917. LOG_ERR("Attatch file operation failed");
  918. unregister_chrdev_region(Sysram.DevNo, 1);
  919. return -EAGAIN;
  920. }
  921. LOG_MSG("X");
  922. return 0;
  923. }
  924. /* ------------------------------------------------------------------------------ */
  925. static inline void SYSRAM_UnregCharDrv(void)
  926. {
  927. LOG_MSG("E");
  928. /* Release char driver */
  929. cdev_del(Sysram.pCharDrv);
  930. unregister_chrdev_region(Sysram.DevNo, 1);
  931. LOG_MSG("X");
  932. }
  933. /* ------------------------------------------------------------------------------ */
  934. static int SYSRAM_Probe(struct platform_device *pDev)
  935. {
  936. MINT32 Ret = 0;
  937. MUINT32 Index = 0;
  938. struct device *sysram_device = NULL;
  939. LOG_MSG("E");
  940. /* register char driver */
  941. /* allocate major no */
  942. if (SYSRAM_RegCharDrv()) {
  943. LOG_ERR("register char failed");
  944. return -EAGAIN;
  945. }
  946. Sysram.pClass = class_create(THIS_MODULE, "SysramDrv");
  947. if (IS_ERR(Sysram.pClass)) {
  948. Ret = PTR_ERR(Sysram.pClass);
  949. LOG_ERR("Unable to create class, err(%ld)", Ret);
  950. return Ret;
  951. }
  952. sysram_device = device_create(
  953. Sysram.pClass,
  954. NULL,
  955. Sysram.DevNo,
  956. NULL,
  957. SYSRAM_DEV_NAME);
  958. /* Initialize variables */
  959. spin_lock_init(&Sysram.SpinLock);
  960. Sysram.TotalUserCount = 0;
  961. Sysram.AllocatedTbl = 0;
  962. memset(Sysram.AllocatedSize, 0, sizeof(Sysram.AllocatedSize));
  963. memset(Sysram.UserInfo, 0, sizeof(Sysram.UserInfo));
  964. init_waitqueue_head(&Sysram.WaitQueueHead);
  965. Sysram.EnableClk = MFALSE;
  966. for (Index = 0; Index < SYSRAM_MEM_BANK_AMOUNT; Index++) {
  967. SysramMemPoolInfo[Index].pMemNode[0].User = SYSRAM_USER_NONE;
  968. SysramMemPoolInfo[Index].pMemNode[0].Offset = 0;
  969. SysramMemPoolInfo[Index].pMemNode[0].Length = SysramMemPoolInfo[Index].Size;
  970. SysramMemPoolInfo[Index].pMemNode[0].Index = 0;
  971. SysramMemPoolInfo[Index].pMemNode[0].pNext = NULL;
  972. SysramMemPoolInfo[Index].pMemNode[0].pPrev = NULL;
  973. SysramMemPoolInfo[Index].IndexTbl = (~0x1);
  974. SysramMemPoolInfo[Index].UserCount = 0;
  975. }
  976. for (Index = 0; Index < SYSRAM_USER_AMOUNT; Index++)
  977. Sysram.AllocatedSize[Index] = 0;
  978. Sysram.DebugFlag = SYSRAM_DEBUG_DEFAULT;
  979. LOG_MSG("X");
  980. return Ret;
  981. }
  982. /* ------------------------------------------------------------------------------ */
  983. static int SYSRAM_Remove(struct platform_device *pDev)
  984. {
  985. LOG_MSG("E");
  986. /* unregister char driver. */
  987. SYSRAM_UnregCharDrv();
  988. device_destroy(Sysram.pClass, Sysram.DevNo);
  989. class_destroy(Sysram.pClass);
  990. LOG_MSG("X");
  991. return 0;
  992. }
  993. /* ------------------------------------------------------------------------------ */
  994. static int SYSRAM_Suspend(
  995. struct platform_device *pDev,
  996. pm_message_t Mesg)
  997. {
  998. LOG_MSG("");
  999. return 0;
  1000. }
  1001. /* ------------------------------------------------------------------------------ */
  1002. static int SYSRAM_Resume(struct platform_device *pDev)
  1003. {
  1004. LOG_MSG("");
  1005. return 0;
  1006. }
  1007. /* ------------------------------------------------------------------------------ */
  1008. static struct platform_driver SysramPlatformDriver = {
  1009. .probe = SYSRAM_Probe,
  1010. .remove = SYSRAM_Remove,
  1011. .suspend = SYSRAM_Suspend,
  1012. .resume = SYSRAM_Resume,
  1013. .driver = {
  1014. .name = SYSRAM_DEV_NAME,
  1015. .owner = THIS_MODULE,
  1016. }
  1017. };
  1018. /* ------------------------------------------------------------------------------ */
  1019. /*
  1020. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *)
  1021. */
  1022. static ssize_t SYSRAM_DumpLayoutToProc(
  1023. struct file *pFile,
  1024. char *pStart,
  1025. size_t Off,
  1026. loff_t *Count)
  1027. {
  1028. LOG_ERR("SYSRAM_DumpLayoutToProc: Not implement");
  1029. return 0;
  1030. }
  1031. /* ------------------------------------------------------------------------------ */
  1032. /*
  1033. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *)
  1034. */
  1035. static ssize_t SYSRAM_ReadFlag(
  1036. struct file *pFile,
  1037. char *pStart,
  1038. size_t Off,
  1039. loff_t *Count)
  1040. {
  1041. LOG_ERR("SYSRAM_ReadFlag: Not implement");
  1042. return 0;
  1043. }
  1044. /* ------------------------------------------------------------------------------ */
  1045. /*
  1046. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *)
  1047. */
  1048. static ssize_t SYSRAM_WriteFlag(
  1049. struct file *pFile,
  1050. const char *pBuffer,
  1051. size_t Count,
  1052. loff_t *pData)
  1053. {
  1054. LOG_ERR("SYSRAM_WriteFlag: Not implement");
  1055. return 0;
  1056. }
  1057. /*******************************************************************************
  1058. *
  1059. ********************************************************************************/
  1060. static const struct file_operations fsysram_proc_fops = {
  1061. .read = SYSRAM_DumpLayoutToProc,
  1062. .write = NULL,
  1063. };
  1064. static const struct file_operations fsysram_flag_proc_fops = {
  1065. .read = SYSRAM_ReadFlag,
  1066. .write = SYSRAM_WriteFlag,
  1067. };
  1068. /* ----------------------------------------------------------------------------- */
  1069. static int __init SYSRAM_Init(void)
  1070. {
  1071. #if 0
  1072. struct proc_dir_entry *pEntry;
  1073. #endif
  1074. LOG_MSG("E");
  1075. if (platform_driver_register(&SysramPlatformDriver)) {
  1076. LOG_ERR("failed to register sysram driver");
  1077. return -ENODEV;
  1078. }
  1079. /* FIX-ME: linux-3.10 procfs API changed */
  1080. #if 1
  1081. proc_create("sysram", 0, NULL, &fsysram_proc_fops);
  1082. proc_create("sysram_flag", 0, NULL, &fsysram_flag_proc_fops);
  1083. #else
  1084. pEntry = create_proc_entry("sysram", 0, NULL);
  1085. if (pEntry) {
  1086. pEntry->read_proc = SYSRAM_DumpLayoutToProc;
  1087. pEntry->write_proc = NULL;
  1088. } else{
  1089. LOG_ERR("add /proc/sysram entry fail.");
  1090. }
  1091. pEntry = create_proc_entry("sysram_flag", 0, NULL);
  1092. if (pEntry) {
  1093. pEntry->read_proc = SYSRAM_ReadFlag;
  1094. pEntry->write_proc = SYSRAM_WriteFlag;
  1095. } else{
  1096. LOG_ERR("add /proc/sysram_flag entry fail");
  1097. }
  1098. #endif
  1099. LOG_MSG("X");
  1100. return 0;
  1101. }
  1102. /* ------------------------------------------------------------------------------ */
  1103. static void __exit SYSRAM_Exit(void)
  1104. {
  1105. LOG_MSG("E");
  1106. platform_driver_unregister(&SysramPlatformDriver);
  1107. LOG_MSG("X");
  1108. }
  1109. /* ------------------------------------------------------------------------------ */
  1110. module_init(SYSRAM_Init);
  1111. module_exit(SYSRAM_Exit);
  1112. MODULE_DESCRIPTION("Camera sysram driver");
  1113. MODULE_AUTHOR("Marx <marx.chiu@mediatek.com>");
  1114. MODULE_LICENSE("GPL");
  1115. /* ------------------------------------------------------------------------------ */