time.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. /*
  2. * Common time routines among all ppc machines.
  3. *
  4. * Written by Cort Dougan (cort@cs.nmt.edu) to merge
  5. * Paul Mackerras' version and mine for PReP and Pmac.
  6. * MPC8xx/MBX changes by Dan Malek (dmalek@jlc.net).
  7. * Converted for 64-bit by Mike Corrigan (mikejc@us.ibm.com)
  8. *
  9. * First round of bugfixes by Gabriel Paubert (paubert@iram.es)
  10. * to make clock more stable (2.4.0-test5). The only thing
  11. * that this code assumes is that the timebases have been synchronized
  12. * by firmware on SMP and are never stopped (never do sleep
  13. * on SMP then, nap and doze are OK).
  14. *
  15. * Speeded up do_gettimeofday by getting rid of references to
  16. * xtime (which required locks for consistency). (mikejc@us.ibm.com)
  17. *
  18. * TODO (not necessarily in this file):
  19. * - improve precision and reproducibility of timebase frequency
  20. * measurement at boot time.
  21. * - for astronomical applications: add a new function to get
  22. * non ambiguous timestamps even around leap seconds. This needs
  23. * a new timestamp format and a good name.
  24. *
  25. * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
  26. * "A Kernel Model for Precision Timekeeping" by Dave Mills
  27. *
  28. * This program is free software; you can redistribute it and/or
  29. * modify it under the terms of the GNU General Public License
  30. * as published by the Free Software Foundation; either version
  31. * 2 of the License, or (at your option) any later version.
  32. */
  33. #include <linux/errno.h>
  34. #include <linux/export.h>
  35. #include <linux/sched.h>
  36. #include <linux/sched/clock.h>
  37. #include <linux/kernel.h>
  38. #include <linux/param.h>
  39. #include <linux/string.h>
  40. #include <linux/mm.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/timex.h>
  43. #include <linux/kernel_stat.h>
  44. #include <linux/time.h>
  45. #include <linux/clockchips.h>
  46. #include <linux/init.h>
  47. #include <linux/profile.h>
  48. #include <linux/cpu.h>
  49. #include <linux/security.h>
  50. #include <linux/percpu.h>
  51. #include <linux/rtc.h>
  52. #include <linux/jiffies.h>
  53. #include <linux/posix-timers.h>
  54. #include <linux/irq.h>
  55. #include <linux/delay.h>
  56. #include <linux/irq_work.h>
  57. #include <linux/clk-provider.h>
  58. #include <linux/suspend.h>
  59. #include <linux/rtc.h>
  60. #include <linux/sched/cputime.h>
  61. #include <linux/processor.h>
  62. #include <asm/trace.h>
  63. #include <asm/io.h>
  64. #include <asm/nvram.h>
  65. #include <asm/cache.h>
  66. #include <asm/machdep.h>
  67. #include <linux/uaccess.h>
  68. #include <asm/time.h>
  69. #include <asm/prom.h>
  70. #include <asm/irq.h>
  71. #include <asm/div64.h>
  72. #include <asm/smp.h>
  73. #include <asm/vdso_datapage.h>
  74. #include <asm/firmware.h>
  75. #include <asm/asm-prototypes.h>
  76. /* powerpc clocksource/clockevent code */
  77. #include <linux/clockchips.h>
  78. #include <linux/timekeeper_internal.h>
  79. static u64 rtc_read(struct clocksource *);
  80. static struct clocksource clocksource_rtc = {
  81. .name = "rtc",
  82. .rating = 400,
  83. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  84. .mask = CLOCKSOURCE_MASK(64),
  85. .read = rtc_read,
  86. };
  87. static u64 timebase_read(struct clocksource *);
  88. static struct clocksource clocksource_timebase = {
  89. .name = "timebase",
  90. .rating = 400,
  91. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  92. .mask = CLOCKSOURCE_MASK(64),
  93. .read = timebase_read,
  94. };
  95. #define DECREMENTER_DEFAULT_MAX 0x7FFFFFFF
  96. u64 decrementer_max = DECREMENTER_DEFAULT_MAX;
  97. static int decrementer_set_next_event(unsigned long evt,
  98. struct clock_event_device *dev);
  99. static int decrementer_shutdown(struct clock_event_device *evt);
  100. struct clock_event_device decrementer_clockevent = {
  101. .name = "decrementer",
  102. .rating = 200,
  103. .irq = 0,
  104. .set_next_event = decrementer_set_next_event,
  105. .set_state_shutdown = decrementer_shutdown,
  106. .tick_resume = decrementer_shutdown,
  107. .features = CLOCK_EVT_FEAT_ONESHOT |
  108. CLOCK_EVT_FEAT_C3STOP,
  109. };
  110. EXPORT_SYMBOL(decrementer_clockevent);
  111. DEFINE_PER_CPU(u64, decrementers_next_tb);
  112. static DEFINE_PER_CPU(struct clock_event_device, decrementers);
  113. #define XSEC_PER_SEC (1024*1024)
  114. #ifdef CONFIG_PPC64
  115. #define SCALE_XSEC(xsec, max) (((xsec) * max) / XSEC_PER_SEC)
  116. #else
  117. /* compute ((xsec << 12) * max) >> 32 */
  118. #define SCALE_XSEC(xsec, max) mulhwu((xsec) << 12, max)
  119. #endif
  120. unsigned long tb_ticks_per_jiffy;
  121. unsigned long tb_ticks_per_usec = 100; /* sane default */
  122. EXPORT_SYMBOL(tb_ticks_per_usec);
  123. unsigned long tb_ticks_per_sec;
  124. EXPORT_SYMBOL(tb_ticks_per_sec); /* for cputime_t conversions */
  125. DEFINE_SPINLOCK(rtc_lock);
  126. EXPORT_SYMBOL_GPL(rtc_lock);
  127. static u64 tb_to_ns_scale __read_mostly;
  128. static unsigned tb_to_ns_shift __read_mostly;
  129. static u64 boot_tb __read_mostly;
  130. extern struct timezone sys_tz;
  131. static long timezone_offset;
  132. unsigned long ppc_proc_freq;
  133. EXPORT_SYMBOL_GPL(ppc_proc_freq);
  134. unsigned long ppc_tb_freq;
  135. EXPORT_SYMBOL_GPL(ppc_tb_freq);
  136. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  137. /*
  138. * Factor for converting from cputime_t (timebase ticks) to
  139. * microseconds. This is stored as 0.64 fixed-point binary fraction.
  140. */
  141. u64 __cputime_usec_factor;
  142. EXPORT_SYMBOL(__cputime_usec_factor);
  143. #ifdef CONFIG_PPC_SPLPAR
  144. void (*dtl_consumer)(struct dtl_entry *, u64);
  145. #endif
  146. #ifdef CONFIG_PPC64
  147. #define get_accounting(tsk) (&get_paca()->accounting)
  148. #else
  149. #define get_accounting(tsk) (&task_thread_info(tsk)->accounting)
  150. #endif
  151. static void calc_cputime_factors(void)
  152. {
  153. struct div_result res;
  154. div128_by_32(1000000, 0, tb_ticks_per_sec, &res);
  155. __cputime_usec_factor = res.result_low;
  156. }
  157. /*
  158. * Read the SPURR on systems that have it, otherwise the PURR,
  159. * or if that doesn't exist return the timebase value passed in.
  160. */
  161. static unsigned long read_spurr(unsigned long tb)
  162. {
  163. if (cpu_has_feature(CPU_FTR_SPURR))
  164. return mfspr(SPRN_SPURR);
  165. if (cpu_has_feature(CPU_FTR_PURR))
  166. return mfspr(SPRN_PURR);
  167. return tb;
  168. }
  169. #ifdef CONFIG_PPC_SPLPAR
  170. /*
  171. * Scan the dispatch trace log and count up the stolen time.
  172. * Should be called with interrupts disabled.
  173. */
  174. static u64 scan_dispatch_log(u64 stop_tb)
  175. {
  176. u64 i = local_paca->dtl_ridx;
  177. struct dtl_entry *dtl = local_paca->dtl_curr;
  178. struct dtl_entry *dtl_end = local_paca->dispatch_log_end;
  179. struct lppaca *vpa = local_paca->lppaca_ptr;
  180. u64 tb_delta;
  181. u64 stolen = 0;
  182. u64 dtb;
  183. if (!dtl)
  184. return 0;
  185. if (i == be64_to_cpu(vpa->dtl_idx))
  186. return 0;
  187. while (i < be64_to_cpu(vpa->dtl_idx)) {
  188. dtb = be64_to_cpu(dtl->timebase);
  189. tb_delta = be32_to_cpu(dtl->enqueue_to_dispatch_time) +
  190. be32_to_cpu(dtl->ready_to_enqueue_time);
  191. barrier();
  192. if (i + N_DISPATCH_LOG < be64_to_cpu(vpa->dtl_idx)) {
  193. /* buffer has overflowed */
  194. i = be64_to_cpu(vpa->dtl_idx) - N_DISPATCH_LOG;
  195. dtl = local_paca->dispatch_log + (i % N_DISPATCH_LOG);
  196. continue;
  197. }
  198. if (dtb > stop_tb)
  199. break;
  200. if (dtl_consumer)
  201. dtl_consumer(dtl, i);
  202. stolen += tb_delta;
  203. ++i;
  204. ++dtl;
  205. if (dtl == dtl_end)
  206. dtl = local_paca->dispatch_log;
  207. }
  208. local_paca->dtl_ridx = i;
  209. local_paca->dtl_curr = dtl;
  210. return stolen;
  211. }
  212. /*
  213. * Accumulate stolen time by scanning the dispatch trace log.
  214. * Called on entry from user mode.
  215. */
  216. void accumulate_stolen_time(void)
  217. {
  218. u64 sst, ust;
  219. unsigned long save_irq_soft_mask = irq_soft_mask_return();
  220. struct cpu_accounting_data *acct = &local_paca->accounting;
  221. /* We are called early in the exception entry, before
  222. * soft/hard_enabled are sync'ed to the expected state
  223. * for the exception. We are hard disabled but the PACA
  224. * needs to reflect that so various debug stuff doesn't
  225. * complain
  226. */
  227. irq_soft_mask_set(IRQS_DISABLED);
  228. sst = scan_dispatch_log(acct->starttime_user);
  229. ust = scan_dispatch_log(acct->starttime);
  230. acct->stime -= sst;
  231. acct->utime -= ust;
  232. acct->steal_time += ust + sst;
  233. irq_soft_mask_set(save_irq_soft_mask);
  234. }
  235. static inline u64 calculate_stolen_time(u64 stop_tb)
  236. {
  237. if (get_paca()->dtl_ridx != be64_to_cpu(get_lppaca()->dtl_idx))
  238. return scan_dispatch_log(stop_tb);
  239. return 0;
  240. }
  241. #else /* CONFIG_PPC_SPLPAR */
  242. static inline u64 calculate_stolen_time(u64 stop_tb)
  243. {
  244. return 0;
  245. }
  246. #endif /* CONFIG_PPC_SPLPAR */
  247. /*
  248. * Account time for a transition between system, hard irq
  249. * or soft irq state.
  250. */
  251. static unsigned long vtime_delta(struct task_struct *tsk,
  252. unsigned long *stime_scaled,
  253. unsigned long *steal_time)
  254. {
  255. unsigned long now, nowscaled, deltascaled;
  256. unsigned long stime;
  257. unsigned long utime, utime_scaled;
  258. struct cpu_accounting_data *acct = get_accounting(tsk);
  259. WARN_ON_ONCE(!irqs_disabled());
  260. now = mftb();
  261. nowscaled = read_spurr(now);
  262. stime = now - acct->starttime;
  263. acct->starttime = now;
  264. deltascaled = nowscaled - acct->startspurr;
  265. acct->startspurr = nowscaled;
  266. *steal_time = calculate_stolen_time(now);
  267. utime = acct->utime - acct->utime_sspurr;
  268. acct->utime_sspurr = acct->utime;
  269. /*
  270. * Because we don't read the SPURR on every kernel entry/exit,
  271. * deltascaled includes both user and system SPURR ticks.
  272. * Apportion these ticks to system SPURR ticks and user
  273. * SPURR ticks in the same ratio as the system time (delta)
  274. * and user time (udelta) values obtained from the timebase
  275. * over the same interval. The system ticks get accounted here;
  276. * the user ticks get saved up in paca->user_time_scaled to be
  277. * used by account_process_tick.
  278. */
  279. *stime_scaled = stime;
  280. utime_scaled = utime;
  281. if (deltascaled != stime + utime) {
  282. if (utime) {
  283. *stime_scaled = deltascaled * stime / (stime + utime);
  284. utime_scaled = deltascaled - *stime_scaled;
  285. } else {
  286. *stime_scaled = deltascaled;
  287. }
  288. }
  289. acct->utime_scaled += utime_scaled;
  290. return stime;
  291. }
  292. void vtime_account_system(struct task_struct *tsk)
  293. {
  294. unsigned long stime, stime_scaled, steal_time;
  295. struct cpu_accounting_data *acct = get_accounting(tsk);
  296. stime = vtime_delta(tsk, &stime_scaled, &steal_time);
  297. stime -= min(stime, steal_time);
  298. acct->steal_time += steal_time;
  299. if ((tsk->flags & PF_VCPU) && !irq_count()) {
  300. acct->gtime += stime;
  301. acct->utime_scaled += stime_scaled;
  302. } else {
  303. if (hardirq_count())
  304. acct->hardirq_time += stime;
  305. else if (in_serving_softirq())
  306. acct->softirq_time += stime;
  307. else
  308. acct->stime += stime;
  309. acct->stime_scaled += stime_scaled;
  310. }
  311. }
  312. EXPORT_SYMBOL_GPL(vtime_account_system);
  313. void vtime_account_idle(struct task_struct *tsk)
  314. {
  315. unsigned long stime, stime_scaled, steal_time;
  316. struct cpu_accounting_data *acct = get_accounting(tsk);
  317. stime = vtime_delta(tsk, &stime_scaled, &steal_time);
  318. acct->idle_time += stime + steal_time;
  319. }
  320. /*
  321. * Account the whole cputime accumulated in the paca
  322. * Must be called with interrupts disabled.
  323. * Assumes that vtime_account_system/idle() has been called
  324. * recently (i.e. since the last entry from usermode) so that
  325. * get_paca()->user_time_scaled is up to date.
  326. */
  327. void vtime_flush(struct task_struct *tsk)
  328. {
  329. struct cpu_accounting_data *acct = get_accounting(tsk);
  330. if (acct->utime)
  331. account_user_time(tsk, cputime_to_nsecs(acct->utime));
  332. if (acct->utime_scaled)
  333. tsk->utimescaled += cputime_to_nsecs(acct->utime_scaled);
  334. if (acct->gtime)
  335. account_guest_time(tsk, cputime_to_nsecs(acct->gtime));
  336. if (acct->steal_time)
  337. account_steal_time(cputime_to_nsecs(acct->steal_time));
  338. if (acct->idle_time)
  339. account_idle_time(cputime_to_nsecs(acct->idle_time));
  340. if (acct->stime)
  341. account_system_index_time(tsk, cputime_to_nsecs(acct->stime),
  342. CPUTIME_SYSTEM);
  343. if (acct->stime_scaled)
  344. tsk->stimescaled += cputime_to_nsecs(acct->stime_scaled);
  345. if (acct->hardirq_time)
  346. account_system_index_time(tsk, cputime_to_nsecs(acct->hardirq_time),
  347. CPUTIME_IRQ);
  348. if (acct->softirq_time)
  349. account_system_index_time(tsk, cputime_to_nsecs(acct->softirq_time),
  350. CPUTIME_SOFTIRQ);
  351. acct->utime = 0;
  352. acct->utime_scaled = 0;
  353. acct->utime_sspurr = 0;
  354. acct->gtime = 0;
  355. acct->steal_time = 0;
  356. acct->idle_time = 0;
  357. acct->stime = 0;
  358. acct->stime_scaled = 0;
  359. acct->hardirq_time = 0;
  360. acct->softirq_time = 0;
  361. }
  362. #ifdef CONFIG_PPC32
  363. /*
  364. * Called from the context switch with interrupts disabled, to charge all
  365. * accumulated times to the current process, and to prepare accounting on
  366. * the next process.
  367. */
  368. void arch_vtime_task_switch(struct task_struct *prev)
  369. {
  370. struct cpu_accounting_data *acct = get_accounting(current);
  371. acct->starttime = get_accounting(prev)->starttime;
  372. acct->startspurr = get_accounting(prev)->startspurr;
  373. }
  374. #endif /* CONFIG_PPC32 */
  375. #else /* ! CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  376. #define calc_cputime_factors()
  377. #endif
  378. void __delay(unsigned long loops)
  379. {
  380. unsigned long start;
  381. int diff;
  382. spin_begin();
  383. if (__USE_RTC()) {
  384. start = get_rtcl();
  385. do {
  386. /* the RTCL register wraps at 1000000000 */
  387. diff = get_rtcl() - start;
  388. if (diff < 0)
  389. diff += 1000000000;
  390. spin_cpu_relax();
  391. } while (diff < loops);
  392. } else {
  393. start = get_tbl();
  394. while (get_tbl() - start < loops)
  395. spin_cpu_relax();
  396. }
  397. spin_end();
  398. }
  399. EXPORT_SYMBOL(__delay);
  400. void udelay(unsigned long usecs)
  401. {
  402. __delay(tb_ticks_per_usec * usecs);
  403. }
  404. EXPORT_SYMBOL(udelay);
  405. #ifdef CONFIG_SMP
  406. unsigned long profile_pc(struct pt_regs *regs)
  407. {
  408. unsigned long pc = instruction_pointer(regs);
  409. if (in_lock_functions(pc))
  410. return regs->link;
  411. return pc;
  412. }
  413. EXPORT_SYMBOL(profile_pc);
  414. #endif
  415. #ifdef CONFIG_IRQ_WORK
  416. /*
  417. * 64-bit uses a byte in the PACA, 32-bit uses a per-cpu variable...
  418. */
  419. #ifdef CONFIG_PPC64
  420. static inline unsigned long test_irq_work_pending(void)
  421. {
  422. unsigned long x;
  423. asm volatile("lbz %0,%1(13)"
  424. : "=r" (x)
  425. : "i" (offsetof(struct paca_struct, irq_work_pending)));
  426. return x;
  427. }
  428. static inline void set_irq_work_pending_flag(void)
  429. {
  430. asm volatile("stb %0,%1(13)" : :
  431. "r" (1),
  432. "i" (offsetof(struct paca_struct, irq_work_pending)));
  433. }
  434. static inline void clear_irq_work_pending(void)
  435. {
  436. asm volatile("stb %0,%1(13)" : :
  437. "r" (0),
  438. "i" (offsetof(struct paca_struct, irq_work_pending)));
  439. }
  440. #else /* 32-bit */
  441. DEFINE_PER_CPU(u8, irq_work_pending);
  442. #define set_irq_work_pending_flag() __this_cpu_write(irq_work_pending, 1)
  443. #define test_irq_work_pending() __this_cpu_read(irq_work_pending)
  444. #define clear_irq_work_pending() __this_cpu_write(irq_work_pending, 0)
  445. #endif /* 32 vs 64 bit */
  446. void arch_irq_work_raise(void)
  447. {
  448. preempt_disable();
  449. set_irq_work_pending_flag();
  450. set_dec(1);
  451. preempt_enable();
  452. }
  453. #else /* CONFIG_IRQ_WORK */
  454. #define test_irq_work_pending() 0
  455. #define clear_irq_work_pending()
  456. #endif /* CONFIG_IRQ_WORK */
  457. static void __timer_interrupt(void)
  458. {
  459. struct pt_regs *regs = get_irq_regs();
  460. u64 *next_tb = this_cpu_ptr(&decrementers_next_tb);
  461. struct clock_event_device *evt = this_cpu_ptr(&decrementers);
  462. u64 now;
  463. trace_timer_interrupt_entry(regs);
  464. if (test_irq_work_pending()) {
  465. clear_irq_work_pending();
  466. irq_work_run();
  467. }
  468. now = get_tb_or_rtc();
  469. if (now >= *next_tb) {
  470. *next_tb = ~(u64)0;
  471. if (evt->event_handler)
  472. evt->event_handler(evt);
  473. __this_cpu_inc(irq_stat.timer_irqs_event);
  474. } else {
  475. now = *next_tb - now;
  476. if (now <= decrementer_max)
  477. set_dec(now);
  478. /* We may have raced with new irq work */
  479. if (test_irq_work_pending())
  480. set_dec(1);
  481. __this_cpu_inc(irq_stat.timer_irqs_others);
  482. }
  483. #ifdef CONFIG_PPC64
  484. /* collect purr register values often, for accurate calculations */
  485. if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
  486. struct cpu_usage *cu = this_cpu_ptr(&cpu_usage_array);
  487. cu->current_tb = mfspr(SPRN_PURR);
  488. }
  489. #endif
  490. trace_timer_interrupt_exit(regs);
  491. }
  492. /*
  493. * timer_interrupt - gets called when the decrementer overflows,
  494. * with interrupts disabled.
  495. */
  496. void timer_interrupt(struct pt_regs * regs)
  497. {
  498. struct pt_regs *old_regs;
  499. u64 *next_tb = this_cpu_ptr(&decrementers_next_tb);
  500. /* Ensure a positive value is written to the decrementer, or else
  501. * some CPUs will continue to take decrementer exceptions.
  502. */
  503. set_dec(decrementer_max);
  504. /* Some implementations of hotplug will get timer interrupts while
  505. * offline, just ignore these and we also need to set
  506. * decrementers_next_tb as MAX to make sure __check_irq_replay
  507. * don't replay timer interrupt when return, otherwise we'll trap
  508. * here infinitely :(
  509. */
  510. if (!cpu_online(smp_processor_id())) {
  511. *next_tb = ~(u64)0;
  512. return;
  513. }
  514. /* Conditionally hard-enable interrupts now that the DEC has been
  515. * bumped to its maximum value
  516. */
  517. may_hard_irq_enable();
  518. #if defined(CONFIG_PPC32) && defined(CONFIG_PPC_PMAC)
  519. if (atomic_read(&ppc_n_lost_interrupts) != 0)
  520. do_IRQ(regs);
  521. #endif
  522. old_regs = set_irq_regs(regs);
  523. irq_enter();
  524. __timer_interrupt();
  525. irq_exit();
  526. set_irq_regs(old_regs);
  527. }
  528. EXPORT_SYMBOL(timer_interrupt);
  529. /*
  530. * Hypervisor decrementer interrupts shouldn't occur but are sometimes
  531. * left pending on exit from a KVM guest. We don't need to do anything
  532. * to clear them, as they are edge-triggered.
  533. */
  534. void hdec_interrupt(struct pt_regs *regs)
  535. {
  536. }
  537. #ifdef CONFIG_SUSPEND
  538. static void generic_suspend_disable_irqs(void)
  539. {
  540. /* Disable the decrementer, so that it doesn't interfere
  541. * with suspending.
  542. */
  543. set_dec(decrementer_max);
  544. local_irq_disable();
  545. set_dec(decrementer_max);
  546. }
  547. static void generic_suspend_enable_irqs(void)
  548. {
  549. local_irq_enable();
  550. }
  551. /* Overrides the weak version in kernel/power/main.c */
  552. void arch_suspend_disable_irqs(void)
  553. {
  554. if (ppc_md.suspend_disable_irqs)
  555. ppc_md.suspend_disable_irqs();
  556. generic_suspend_disable_irqs();
  557. }
  558. /* Overrides the weak version in kernel/power/main.c */
  559. void arch_suspend_enable_irqs(void)
  560. {
  561. generic_suspend_enable_irqs();
  562. if (ppc_md.suspend_enable_irqs)
  563. ppc_md.suspend_enable_irqs();
  564. }
  565. #endif
  566. unsigned long long tb_to_ns(unsigned long long ticks)
  567. {
  568. return mulhdu(ticks, tb_to_ns_scale) << tb_to_ns_shift;
  569. }
  570. EXPORT_SYMBOL_GPL(tb_to_ns);
  571. /*
  572. * Scheduler clock - returns current time in nanosec units.
  573. *
  574. * Note: mulhdu(a, b) (multiply high double unsigned) returns
  575. * the high 64 bits of a * b, i.e. (a * b) >> 64, where a and b
  576. * are 64-bit unsigned numbers.
  577. */
  578. notrace unsigned long long sched_clock(void)
  579. {
  580. if (__USE_RTC())
  581. return get_rtc();
  582. return mulhdu(get_tb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift;
  583. }
  584. #ifdef CONFIG_PPC_PSERIES
  585. /*
  586. * Running clock - attempts to give a view of time passing for a virtualised
  587. * kernels.
  588. * Uses the VTB register if available otherwise a next best guess.
  589. */
  590. unsigned long long running_clock(void)
  591. {
  592. /*
  593. * Don't read the VTB as a host since KVM does not switch in host
  594. * timebase into the VTB when it takes a guest off the CPU, reading the
  595. * VTB would result in reading 'last switched out' guest VTB.
  596. *
  597. * Host kernels are often compiled with CONFIG_PPC_PSERIES checked, it
  598. * would be unsafe to rely only on the #ifdef above.
  599. */
  600. if (firmware_has_feature(FW_FEATURE_LPAR) &&
  601. cpu_has_feature(CPU_FTR_ARCH_207S))
  602. return mulhdu(get_vtb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift;
  603. /*
  604. * This is a next best approximation without a VTB.
  605. * On a host which is running bare metal there should never be any stolen
  606. * time and on a host which doesn't do any virtualisation TB *should* equal
  607. * VTB so it makes no difference anyway.
  608. */
  609. return local_clock() - kcpustat_this_cpu->cpustat[CPUTIME_STEAL];
  610. }
  611. #endif
  612. static int __init get_freq(char *name, int cells, unsigned long *val)
  613. {
  614. struct device_node *cpu;
  615. const __be32 *fp;
  616. int found = 0;
  617. /* The cpu node should have timebase and clock frequency properties */
  618. cpu = of_find_node_by_type(NULL, "cpu");
  619. if (cpu) {
  620. fp = of_get_property(cpu, name, NULL);
  621. if (fp) {
  622. found = 1;
  623. *val = of_read_ulong(fp, cells);
  624. }
  625. of_node_put(cpu);
  626. }
  627. return found;
  628. }
  629. static void start_cpu_decrementer(void)
  630. {
  631. #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
  632. unsigned int tcr;
  633. /* Clear any pending timer interrupts */
  634. mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
  635. tcr = mfspr(SPRN_TCR);
  636. /*
  637. * The watchdog may have already been enabled by u-boot. So leave
  638. * TRC[WP] (Watchdog Period) alone.
  639. */
  640. tcr &= TCR_WP_MASK; /* Clear all bits except for TCR[WP] */
  641. tcr |= TCR_DIE; /* Enable decrementer */
  642. mtspr(SPRN_TCR, tcr);
  643. #endif
  644. }
  645. void __init generic_calibrate_decr(void)
  646. {
  647. ppc_tb_freq = DEFAULT_TB_FREQ; /* hardcoded default */
  648. if (!get_freq("ibm,extended-timebase-frequency", 2, &ppc_tb_freq) &&
  649. !get_freq("timebase-frequency", 1, &ppc_tb_freq)) {
  650. printk(KERN_ERR "WARNING: Estimating decrementer frequency "
  651. "(not found)\n");
  652. }
  653. ppc_proc_freq = DEFAULT_PROC_FREQ; /* hardcoded default */
  654. if (!get_freq("ibm,extended-clock-frequency", 2, &ppc_proc_freq) &&
  655. !get_freq("clock-frequency", 1, &ppc_proc_freq)) {
  656. printk(KERN_ERR "WARNING: Estimating processor frequency "
  657. "(not found)\n");
  658. }
  659. }
  660. int update_persistent_clock(struct timespec now)
  661. {
  662. struct rtc_time tm;
  663. if (!ppc_md.set_rtc_time)
  664. return -ENODEV;
  665. to_tm(now.tv_sec + 1 + timezone_offset, &tm);
  666. tm.tm_year -= 1900;
  667. tm.tm_mon -= 1;
  668. return ppc_md.set_rtc_time(&tm);
  669. }
  670. static void __read_persistent_clock(struct timespec *ts)
  671. {
  672. struct rtc_time tm;
  673. static int first = 1;
  674. ts->tv_nsec = 0;
  675. /* XXX this is a litle fragile but will work okay in the short term */
  676. if (first) {
  677. first = 0;
  678. if (ppc_md.time_init)
  679. timezone_offset = ppc_md.time_init();
  680. /* get_boot_time() isn't guaranteed to be safe to call late */
  681. if (ppc_md.get_boot_time) {
  682. ts->tv_sec = ppc_md.get_boot_time() - timezone_offset;
  683. return;
  684. }
  685. }
  686. if (!ppc_md.get_rtc_time) {
  687. ts->tv_sec = 0;
  688. return;
  689. }
  690. ppc_md.get_rtc_time(&tm);
  691. ts->tv_sec = mktime(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
  692. tm.tm_hour, tm.tm_min, tm.tm_sec);
  693. }
  694. void read_persistent_clock(struct timespec *ts)
  695. {
  696. __read_persistent_clock(ts);
  697. /* Sanitize it in case real time clock is set below EPOCH */
  698. if (ts->tv_sec < 0) {
  699. ts->tv_sec = 0;
  700. ts->tv_nsec = 0;
  701. }
  702. }
  703. /* clocksource code */
  704. static notrace u64 rtc_read(struct clocksource *cs)
  705. {
  706. return (u64)get_rtc();
  707. }
  708. static notrace u64 timebase_read(struct clocksource *cs)
  709. {
  710. return (u64)get_tb();
  711. }
  712. void update_vsyscall(struct timekeeper *tk)
  713. {
  714. struct timespec xt;
  715. struct clocksource *clock = tk->tkr_mono.clock;
  716. u32 mult = tk->tkr_mono.mult;
  717. u32 shift = tk->tkr_mono.shift;
  718. u64 cycle_last = tk->tkr_mono.cycle_last;
  719. u64 new_tb_to_xs, new_stamp_xsec;
  720. u64 frac_sec;
  721. if (clock != &clocksource_timebase)
  722. return;
  723. xt.tv_sec = tk->xtime_sec;
  724. xt.tv_nsec = (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift);
  725. /* Make userspace gettimeofday spin until we're done. */
  726. ++vdso_data->tb_update_count;
  727. smp_mb();
  728. /*
  729. * This computes ((2^20 / 1e9) * mult) >> shift as a
  730. * 0.64 fixed-point fraction.
  731. * The computation in the else clause below won't overflow
  732. * (as long as the timebase frequency is >= 1.049 MHz)
  733. * but loses precision because we lose the low bits of the constant
  734. * in the shift. Note that 19342813113834067 ~= 2^(20+64) / 1e9.
  735. * For a shift of 24 the error is about 0.5e-9, or about 0.5ns
  736. * over a second. (Shift values are usually 22, 23 or 24.)
  737. * For high frequency clocks such as the 512MHz timebase clock
  738. * on POWER[6789], the mult value is small (e.g. 32768000)
  739. * and so we can shift the constant by 16 initially
  740. * (295147905179 ~= 2^(20+64-16) / 1e9) and then do the
  741. * remaining shifts after the multiplication, which gives a
  742. * more accurate result (e.g. with mult = 32768000, shift = 24,
  743. * the error is only about 1.2e-12, or 0.7ns over 10 minutes).
  744. */
  745. if (mult <= 62500000 && clock->shift >= 16)
  746. new_tb_to_xs = ((u64) mult * 295147905179ULL) >> (clock->shift - 16);
  747. else
  748. new_tb_to_xs = (u64) mult * (19342813113834067ULL >> clock->shift);
  749. /*
  750. * Compute the fractional second in units of 2^-32 seconds.
  751. * The fractional second is tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift
  752. * in nanoseconds, so multiplying that by 2^32 / 1e9 gives
  753. * it in units of 2^-32 seconds.
  754. * We assume shift <= 32 because clocks_calc_mult_shift()
  755. * generates shift values in the range 0 - 32.
  756. */
  757. frac_sec = tk->tkr_mono.xtime_nsec << (32 - shift);
  758. do_div(frac_sec, NSEC_PER_SEC);
  759. /*
  760. * Work out new stamp_xsec value for any legacy users of systemcfg.
  761. * stamp_xsec is in units of 2^-20 seconds.
  762. */
  763. new_stamp_xsec = frac_sec >> 12;
  764. new_stamp_xsec += tk->xtime_sec * XSEC_PER_SEC;
  765. /*
  766. * tb_update_count is used to allow the userspace gettimeofday code
  767. * to assure itself that it sees a consistent view of the tb_to_xs and
  768. * stamp_xsec variables. It reads the tb_update_count, then reads
  769. * tb_to_xs and stamp_xsec and then reads tb_update_count again. If
  770. * the two values of tb_update_count match and are even then the
  771. * tb_to_xs and stamp_xsec values are consistent. If not, then it
  772. * loops back and reads them again until this criteria is met.
  773. */
  774. vdso_data->tb_orig_stamp = cycle_last;
  775. vdso_data->stamp_xsec = new_stamp_xsec;
  776. vdso_data->tb_to_xs = new_tb_to_xs;
  777. vdso_data->wtom_clock_sec = tk->wall_to_monotonic.tv_sec;
  778. vdso_data->wtom_clock_nsec = tk->wall_to_monotonic.tv_nsec;
  779. vdso_data->stamp_xtime = xt;
  780. vdso_data->stamp_sec_fraction = frac_sec;
  781. smp_wmb();
  782. ++(vdso_data->tb_update_count);
  783. }
  784. void update_vsyscall_tz(void)
  785. {
  786. vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
  787. vdso_data->tz_dsttime = sys_tz.tz_dsttime;
  788. }
  789. static void __init clocksource_init(void)
  790. {
  791. struct clocksource *clock;
  792. if (__USE_RTC())
  793. clock = &clocksource_rtc;
  794. else
  795. clock = &clocksource_timebase;
  796. if (clocksource_register_hz(clock, tb_ticks_per_sec)) {
  797. printk(KERN_ERR "clocksource: %s is already registered\n",
  798. clock->name);
  799. return;
  800. }
  801. printk(KERN_INFO "clocksource: %s mult[%x] shift[%d] registered\n",
  802. clock->name, clock->mult, clock->shift);
  803. }
  804. static int decrementer_set_next_event(unsigned long evt,
  805. struct clock_event_device *dev)
  806. {
  807. __this_cpu_write(decrementers_next_tb, get_tb_or_rtc() + evt);
  808. set_dec(evt);
  809. /* We may have raced with new irq work */
  810. if (test_irq_work_pending())
  811. set_dec(1);
  812. return 0;
  813. }
  814. static int decrementer_shutdown(struct clock_event_device *dev)
  815. {
  816. decrementer_set_next_event(decrementer_max, dev);
  817. return 0;
  818. }
  819. /* Interrupt handler for the timer broadcast IPI */
  820. void tick_broadcast_ipi_handler(void)
  821. {
  822. u64 *next_tb = this_cpu_ptr(&decrementers_next_tb);
  823. *next_tb = get_tb_or_rtc();
  824. __timer_interrupt();
  825. }
  826. static void register_decrementer_clockevent(int cpu)
  827. {
  828. struct clock_event_device *dec = &per_cpu(decrementers, cpu);
  829. *dec = decrementer_clockevent;
  830. dec->cpumask = cpumask_of(cpu);
  831. printk_once(KERN_DEBUG "clockevent: %s mult[%x] shift[%d] cpu[%d]\n",
  832. dec->name, dec->mult, dec->shift, cpu);
  833. clockevents_register_device(dec);
  834. }
  835. static void enable_large_decrementer(void)
  836. {
  837. if (!cpu_has_feature(CPU_FTR_ARCH_300))
  838. return;
  839. if (decrementer_max <= DECREMENTER_DEFAULT_MAX)
  840. return;
  841. /*
  842. * If we're running as the hypervisor we need to enable the LD manually
  843. * otherwise firmware should have done it for us.
  844. */
  845. if (cpu_has_feature(CPU_FTR_HVMODE))
  846. mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) | LPCR_LD);
  847. }
  848. static void __init set_decrementer_max(void)
  849. {
  850. struct device_node *cpu;
  851. u32 bits = 32;
  852. /* Prior to ISAv3 the decrementer is always 32 bit */
  853. if (!cpu_has_feature(CPU_FTR_ARCH_300))
  854. return;
  855. cpu = of_find_node_by_type(NULL, "cpu");
  856. if (of_property_read_u32(cpu, "ibm,dec-bits", &bits) == 0) {
  857. if (bits > 64 || bits < 32) {
  858. pr_warn("time_init: firmware supplied invalid ibm,dec-bits");
  859. bits = 32;
  860. }
  861. /* calculate the signed maximum given this many bits */
  862. decrementer_max = (1ul << (bits - 1)) - 1;
  863. }
  864. of_node_put(cpu);
  865. pr_info("time_init: %u bit decrementer (max: %llx)\n",
  866. bits, decrementer_max);
  867. }
  868. static void __init init_decrementer_clockevent(void)
  869. {
  870. int cpu = smp_processor_id();
  871. clockevents_calc_mult_shift(&decrementer_clockevent, ppc_tb_freq, 4);
  872. decrementer_clockevent.max_delta_ns =
  873. clockevent_delta2ns(decrementer_max, &decrementer_clockevent);
  874. decrementer_clockevent.max_delta_ticks = decrementer_max;
  875. decrementer_clockevent.min_delta_ns =
  876. clockevent_delta2ns(2, &decrementer_clockevent);
  877. decrementer_clockevent.min_delta_ticks = 2;
  878. register_decrementer_clockevent(cpu);
  879. }
  880. void secondary_cpu_time_init(void)
  881. {
  882. /* Enable and test the large decrementer for this cpu */
  883. enable_large_decrementer();
  884. /* Start the decrementer on CPUs that have manual control
  885. * such as BookE
  886. */
  887. start_cpu_decrementer();
  888. /* FIME: Should make unrelatred change to move snapshot_timebase
  889. * call here ! */
  890. register_decrementer_clockevent(smp_processor_id());
  891. }
  892. /* This function is only called on the boot processor */
  893. void __init time_init(void)
  894. {
  895. struct div_result res;
  896. u64 scale;
  897. unsigned shift;
  898. if (__USE_RTC()) {
  899. /* 601 processor: dec counts down by 128 every 128ns */
  900. ppc_tb_freq = 1000000000;
  901. } else {
  902. /* Normal PowerPC with timebase register */
  903. ppc_md.calibrate_decr();
  904. printk(KERN_DEBUG "time_init: decrementer frequency = %lu.%.6lu MHz\n",
  905. ppc_tb_freq / 1000000, ppc_tb_freq % 1000000);
  906. printk(KERN_DEBUG "time_init: processor frequency = %lu.%.6lu MHz\n",
  907. ppc_proc_freq / 1000000, ppc_proc_freq % 1000000);
  908. }
  909. tb_ticks_per_jiffy = ppc_tb_freq / HZ;
  910. tb_ticks_per_sec = ppc_tb_freq;
  911. tb_ticks_per_usec = ppc_tb_freq / 1000000;
  912. calc_cputime_factors();
  913. /*
  914. * Compute scale factor for sched_clock.
  915. * The calibrate_decr() function has set tb_ticks_per_sec,
  916. * which is the timebase frequency.
  917. * We compute 1e9 * 2^64 / tb_ticks_per_sec and interpret
  918. * the 128-bit result as a 64.64 fixed-point number.
  919. * We then shift that number right until it is less than 1.0,
  920. * giving us the scale factor and shift count to use in
  921. * sched_clock().
  922. */
  923. div128_by_32(1000000000, 0, tb_ticks_per_sec, &res);
  924. scale = res.result_low;
  925. for (shift = 0; res.result_high != 0; ++shift) {
  926. scale = (scale >> 1) | (res.result_high << 63);
  927. res.result_high >>= 1;
  928. }
  929. tb_to_ns_scale = scale;
  930. tb_to_ns_shift = shift;
  931. /* Save the current timebase to pretty up CONFIG_PRINTK_TIME */
  932. boot_tb = get_tb_or_rtc();
  933. /* If platform provided a timezone (pmac), we correct the time */
  934. if (timezone_offset) {
  935. sys_tz.tz_minuteswest = -timezone_offset / 60;
  936. sys_tz.tz_dsttime = 0;
  937. }
  938. vdso_data->tb_update_count = 0;
  939. vdso_data->tb_ticks_per_sec = tb_ticks_per_sec;
  940. /* initialise and enable the large decrementer (if we have one) */
  941. set_decrementer_max();
  942. enable_large_decrementer();
  943. /* Start the decrementer on CPUs that have manual control
  944. * such as BookE
  945. */
  946. start_cpu_decrementer();
  947. /* Register the clocksource */
  948. clocksource_init();
  949. init_decrementer_clockevent();
  950. tick_setup_hrtimer_broadcast();
  951. #ifdef CONFIG_COMMON_CLK
  952. of_clk_init(NULL);
  953. #endif
  954. }
  955. #define FEBRUARY 2
  956. #define STARTOFTIME 1970
  957. #define SECDAY 86400L
  958. #define SECYR (SECDAY * 365)
  959. #define leapyear(year) ((year) % 4 == 0 && \
  960. ((year) % 100 != 0 || (year) % 400 == 0))
  961. #define days_in_year(a) (leapyear(a) ? 366 : 365)
  962. #define days_in_month(a) (month_days[(a) - 1])
  963. static int month_days[12] = {
  964. 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  965. };
  966. void to_tm(int tim, struct rtc_time * tm)
  967. {
  968. register int i;
  969. register long hms, day;
  970. day = tim / SECDAY;
  971. hms = tim % SECDAY;
  972. /* Hours, minutes, seconds are easy */
  973. tm->tm_hour = hms / 3600;
  974. tm->tm_min = (hms % 3600) / 60;
  975. tm->tm_sec = (hms % 3600) % 60;
  976. /* Number of years in days */
  977. for (i = STARTOFTIME; day >= days_in_year(i); i++)
  978. day -= days_in_year(i);
  979. tm->tm_year = i;
  980. /* Number of months in days left */
  981. if (leapyear(tm->tm_year))
  982. days_in_month(FEBRUARY) = 29;
  983. for (i = 1; day >= days_in_month(i); i++)
  984. day -= days_in_month(i);
  985. days_in_month(FEBRUARY) = 28;
  986. tm->tm_mon = i;
  987. /* Days are what is left over (+1) from all that. */
  988. tm->tm_mday = day + 1;
  989. /*
  990. * No-one uses the day of the week.
  991. */
  992. tm->tm_wday = -1;
  993. }
  994. EXPORT_SYMBOL(to_tm);
  995. /*
  996. * Divide a 128-bit dividend by a 32-bit divisor, leaving a 128 bit
  997. * result.
  998. */
  999. void div128_by_32(u64 dividend_high, u64 dividend_low,
  1000. unsigned divisor, struct div_result *dr)
  1001. {
  1002. unsigned long a, b, c, d;
  1003. unsigned long w, x, y, z;
  1004. u64 ra, rb, rc;
  1005. a = dividend_high >> 32;
  1006. b = dividend_high & 0xffffffff;
  1007. c = dividend_low >> 32;
  1008. d = dividend_low & 0xffffffff;
  1009. w = a / divisor;
  1010. ra = ((u64)(a - (w * divisor)) << 32) + b;
  1011. rb = ((u64) do_div(ra, divisor) << 32) + c;
  1012. x = ra;
  1013. rc = ((u64) do_div(rb, divisor) << 32) + d;
  1014. y = rb;
  1015. do_div(rc, divisor);
  1016. z = rc;
  1017. dr->result_high = ((u64)w << 32) + x;
  1018. dr->result_low = ((u64)y << 32) + z;
  1019. }
  1020. /* We don't need to calibrate delay, we use the CPU timebase for that */
  1021. void calibrate_delay(void)
  1022. {
  1023. /* Some generic code (such as spinlock debug) use loops_per_jiffy
  1024. * as the number of __delay(1) in a jiffy, so make it so
  1025. */
  1026. loops_per_jiffy = tb_ticks_per_jiffy;
  1027. }
  1028. #if IS_ENABLED(CONFIG_RTC_DRV_GENERIC)
  1029. static int rtc_generic_get_time(struct device *dev, struct rtc_time *tm)
  1030. {
  1031. ppc_md.get_rtc_time(tm);
  1032. return rtc_valid_tm(tm);
  1033. }
  1034. static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm)
  1035. {
  1036. if (!ppc_md.set_rtc_time)
  1037. return -EOPNOTSUPP;
  1038. if (ppc_md.set_rtc_time(tm) < 0)
  1039. return -EOPNOTSUPP;
  1040. return 0;
  1041. }
  1042. static const struct rtc_class_ops rtc_generic_ops = {
  1043. .read_time = rtc_generic_get_time,
  1044. .set_time = rtc_generic_set_time,
  1045. };
  1046. static int __init rtc_init(void)
  1047. {
  1048. struct platform_device *pdev;
  1049. if (!ppc_md.get_rtc_time)
  1050. return -ENODEV;
  1051. pdev = platform_device_register_data(NULL, "rtc-generic", -1,
  1052. &rtc_generic_ops,
  1053. sizeof(rtc_generic_ops));
  1054. return PTR_ERR_OR_ZERO(pdev);
  1055. }
  1056. device_initcall(rtc_init);
  1057. #endif