2 * drivers/video/tegra/host/gk20a/gk20a.c
6 * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #define CREATE_TRACE_POINTS
22 #include <trace/events/gk20a.h>
24 #include <linux/module.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/highmem.h>
27 #include <linux/string.h>
28 #include <linux/cdev.h>
29 #include <linux/delay.h>
30 #include <linux/firmware.h>
31 #include <linux/interrupt.h>
32 #include <linux/irq.h>
33 #include <linux/export.h>
34 #include <linux/file.h>
36 #include <linux/of_device.h>
37 #include <linux/of_platform.h>
38 #include <linux/pm_runtime.h>
39 #include <linux/thermal.h>
40 #include <asm/cacheflush.h>
41 #include <linux/debugfs.h>
42 #include <linux/spinlock.h>
43 #include <linux/tegra-powergate.h>
44 #include <linux/tegra_pm_domains.h>
45 #include <linux/clk/tegra.h>
47 #include <linux/sched.h>
48 #include <linux/input-cfboost.h>
52 #include "debug_gk20a.h"
53 #include "ctrl_gk20a.h"
54 #include "hw_mc_gk20a.h"
55 #include "hw_timer_gk20a.h"
56 #include "hw_bus_gk20a.h"
57 #include "hw_sim_gk20a.h"
58 #include "hw_top_gk20a.h"
59 #include "hw_ltc_gk20a.h"
60 #include "gk20a_scale.h"
61 #include "dbg_gpu_gk20a.h"
65 #define __cpuc_flush_dcache_area __flush_dcache_area
68 #define CLASS_NAME "nvidia-gpu"
69 /* TODO: Change to e.g. "nvidia-gpu%s" once we have symlinks in place. */
70 #define INTERFACE_NAME "nvhost%s-gpu"
72 #define GK20A_NUM_CDEVS 5
74 #if defined(GK20A_DEBUG)
75 u32 gk20a_dbg_mask = GK20A_DEFAULT_DBG_MASK;
79 #define GK20A_WAIT_FOR_IDLE_MS 2000
81 static int gk20a_pm_finalize_poweron(struct device *dev);
82 static int gk20a_pm_prepare_poweroff(struct device *dev);
84 static inline void set_gk20a(struct platform_device *dev, struct gk20a *gk20a)
86 gk20a_get_platform(dev)->g = gk20a;
89 static const struct file_operations gk20a_channel_ops = {
91 .release = gk20a_channel_release,
92 .open = gk20a_channel_open,
94 .compat_ioctl = gk20a_channel_ioctl,
96 .unlocked_ioctl = gk20a_channel_ioctl,
99 static const struct file_operations gk20a_ctrl_ops = {
100 .owner = THIS_MODULE,
101 .release = gk20a_ctrl_dev_release,
102 .open = gk20a_ctrl_dev_open,
103 .unlocked_ioctl = gk20a_ctrl_dev_ioctl,
105 .compat_ioctl = gk20a_ctrl_dev_ioctl,
109 static const struct file_operations gk20a_dbg_ops = {
110 .owner = THIS_MODULE,
111 .release = gk20a_dbg_gpu_dev_release,
112 .open = gk20a_dbg_gpu_dev_open,
113 .unlocked_ioctl = gk20a_dbg_gpu_dev_ioctl,
114 .poll = gk20a_dbg_gpu_dev_poll,
116 .compat_ioctl = gk20a_dbg_gpu_dev_ioctl,
120 static const struct file_operations gk20a_as_ops = {
121 .owner = THIS_MODULE,
122 .release = gk20a_as_dev_release,
123 .open = gk20a_as_dev_open,
125 .compat_ioctl = gk20a_as_dev_ioctl,
127 .unlocked_ioctl = gk20a_as_dev_ioctl,
131 * Note: We use a different 'open' to trigger handling of the profiler session.
132 * Most of the code is shared between them... Though, at some point if the
133 * code does get too tangled trying to handle each in the same path we can
134 * separate them cleanly.
136 static const struct file_operations gk20a_prof_ops = {
137 .owner = THIS_MODULE,
138 .release = gk20a_dbg_gpu_dev_release,
139 .open = gk20a_prof_gpu_dev_open,
140 .unlocked_ioctl = gk20a_dbg_gpu_dev_ioctl,
141 /* .mmap = gk20a_prof_gpu_dev_mmap,*/
142 /*int (*mmap) (struct file *, struct vm_area_struct *);*/
143 .compat_ioctl = gk20a_dbg_gpu_dev_ioctl,
145 .compat_ioctl = gk20a_dbg_gpu_dev_ioctl,
149 static inline void sim_writel(struct gk20a *g, u32 r, u32 v)
151 writel(v, g->sim.regs+r);
154 static inline u32 sim_readl(struct gk20a *g, u32 r)
156 return readl(g->sim.regs+r);
159 static void kunmap_and_free_iopage(void **kvaddr, struct page **page)
171 static void gk20a_free_sim_support(struct gk20a *g)
173 /* free sim mappings, bfrs */
174 kunmap_and_free_iopage(&g->sim.send_bfr.kvaddr,
175 &g->sim.send_bfr.page);
177 kunmap_and_free_iopage(&g->sim.recv_bfr.kvaddr,
178 &g->sim.recv_bfr.page);
180 kunmap_and_free_iopage(&g->sim.msg_bfr.kvaddr,
181 &g->sim.msg_bfr.page);
184 static void gk20a_remove_sim_support(struct sim_gk20a *s)
186 struct gk20a *g = s->g;
188 sim_writel(g, sim_config_r(), sim_config_mode_disabled_v());
189 gk20a_free_sim_support(g);
192 static int alloc_and_kmap_iopage(struct device *d,
198 *page = alloc_page(GFP_KERNEL);
202 dev_err(d, "couldn't allocate io page\n");
206 *kvaddr = kmap(*page);
209 dev_err(d, "couldn't kmap io page\n");
212 *phys = page_to_phys(*page);
216 kunmap_and_free_iopage(kvaddr, page);
221 static void __iomem *gk20a_ioremap_resource(struct platform_device *dev, int i,
222 struct resource **out)
224 struct resource *r = platform_get_resource(dev, IORESOURCE_MEM, i);
229 return devm_request_and_ioremap(&dev->dev, r);
232 /* TBD: strip from released */
233 static int gk20a_init_sim_support(struct platform_device *dev)
236 struct gk20a *g = get_gk20a(dev);
237 struct device *d = &dev->dev;
241 g->sim.regs = gk20a_ioremap_resource(dev, GK20A_SIM_IORESOURCE_MEM,
244 dev_err(d, "failed to remap gk20a sim regs\n");
249 /* allocate sim event/msg buffers */
250 err = alloc_and_kmap_iopage(d, &g->sim.send_bfr.kvaddr,
251 &g->sim.send_bfr.phys,
252 &g->sim.send_bfr.page);
254 err = err || alloc_and_kmap_iopage(d, &g->sim.recv_bfr.kvaddr,
255 &g->sim.recv_bfr.phys,
256 &g->sim.recv_bfr.page);
258 err = err || alloc_and_kmap_iopage(d, &g->sim.msg_bfr.kvaddr,
259 &g->sim.msg_bfr.phys,
260 &g->sim.msg_bfr.page);
262 if (!(g->sim.send_bfr.kvaddr && g->sim.recv_bfr.kvaddr &&
263 g->sim.msg_bfr.kvaddr)) {
264 dev_err(d, "couldn't allocate all sim buffers\n");
268 /*mark send ring invalid*/
269 sim_writel(g, sim_send_ring_r(), sim_send_ring_status_invalid_f());
271 /*read get pointer and make equal to put*/
272 g->sim.send_ring_put = sim_readl(g, sim_send_get_r());
273 sim_writel(g, sim_send_put_r(), g->sim.send_ring_put);
275 /*write send ring address and make it valid*/
276 /*TBD: work for >32b physmem*/
277 phys = g->sim.send_bfr.phys;
278 sim_writel(g, sim_send_ring_hi_r(), 0);
279 sim_writel(g, sim_send_ring_r(),
280 sim_send_ring_status_valid_f() |
281 sim_send_ring_target_phys_pci_coherent_f() |
282 sim_send_ring_size_4kb_f() |
283 sim_send_ring_addr_lo_f(phys >> PAGE_SHIFT));
285 /*repeat for recv ring (but swap put,get as roles are opposite) */
286 sim_writel(g, sim_recv_ring_r(), sim_recv_ring_status_invalid_f());
288 /*read put pointer and make equal to get*/
289 g->sim.recv_ring_get = sim_readl(g, sim_recv_put_r());
290 sim_writel(g, sim_recv_get_r(), g->sim.recv_ring_get);
292 /*write send ring address and make it valid*/
293 /*TBD: work for >32b physmem*/
294 phys = g->sim.recv_bfr.phys;
295 sim_writel(g, sim_recv_ring_hi_r(), 0);
296 sim_writel(g, sim_recv_ring_r(),
297 sim_recv_ring_status_valid_f() |
298 sim_recv_ring_target_phys_pci_coherent_f() |
299 sim_recv_ring_size_4kb_f() |
300 sim_recv_ring_addr_lo_f(phys >> PAGE_SHIFT));
302 g->sim.remove_support = gk20a_remove_sim_support;
306 gk20a_free_sim_support(g);
310 static inline u32 sim_msg_header_size(void)
312 return 24;/*TBD: fix the header to gt this from NV_VGPU_MSG_HEADER*/
315 static inline u32 *sim_msg_bfr(struct gk20a *g, u32 byte_offset)
317 return (u32 *)(g->sim.msg_bfr.kvaddr + byte_offset);
320 static inline u32 *sim_msg_hdr(struct gk20a *g, u32 byte_offset)
322 return sim_msg_bfr(g, byte_offset); /*starts at 0*/
325 static inline u32 *sim_msg_param(struct gk20a *g, u32 byte_offset)
327 /*starts after msg header/cmn*/
328 return sim_msg_bfr(g, byte_offset + sim_msg_header_size());
331 static inline void sim_write_hdr(struct gk20a *g, u32 func, u32 size)
333 /*memset(g->sim.msg_bfr.kvaddr,0,min(PAGE_SIZE,size));*/
334 *sim_msg_hdr(g, sim_msg_signature_r()) = sim_msg_signature_valid_v();
335 *sim_msg_hdr(g, sim_msg_result_r()) = sim_msg_result_rpc_pending_v();
336 *sim_msg_hdr(g, sim_msg_spare_r()) = sim_msg_spare__init_v();
337 *sim_msg_hdr(g, sim_msg_function_r()) = func;
338 *sim_msg_hdr(g, sim_msg_length_r()) = size + sim_msg_header_size();
341 static inline u32 sim_escape_read_hdr_size(void)
343 return 12; /*TBD: fix NV_VGPU_SIM_ESCAPE_READ_HEADER*/
346 static u32 *sim_send_ring_bfr(struct gk20a *g, u32 byte_offset)
348 return (u32 *)(g->sim.send_bfr.kvaddr + byte_offset);
351 static int rpc_send_message(struct gk20a *g)
353 /* calculations done in units of u32s */
354 u32 send_base = sim_send_put_pointer_v(g->sim.send_ring_put) * 2;
355 u32 dma_offset = send_base + sim_dma_r()/sizeof(u32);
356 u32 dma_hi_offset = send_base + sim_dma_hi_r()/sizeof(u32);
358 *sim_send_ring_bfr(g, dma_offset*sizeof(u32)) =
359 sim_dma_target_phys_pci_coherent_f() |
360 sim_dma_status_valid_f() |
361 sim_dma_size_4kb_f() |
362 sim_dma_addr_lo_f(g->sim.msg_bfr.phys >> PAGE_SHIFT);
364 *sim_send_ring_bfr(g, dma_hi_offset*sizeof(u32)) = 0; /*TBD >32b phys*/
366 *sim_msg_hdr(g, sim_msg_sequence_r()) = g->sim.sequence_base++;
368 g->sim.send_ring_put = (g->sim.send_ring_put + 2 * sizeof(u32)) %
371 __cpuc_flush_dcache_area(g->sim.msg_bfr.kvaddr, PAGE_SIZE);
372 __cpuc_flush_dcache_area(g->sim.send_bfr.kvaddr, PAGE_SIZE);
373 __cpuc_flush_dcache_area(g->sim.recv_bfr.kvaddr, PAGE_SIZE);
375 /* Update the put pointer. This will trap into the host. */
376 sim_writel(g, sim_send_put_r(), g->sim.send_ring_put);
381 static inline u32 *sim_recv_ring_bfr(struct gk20a *g, u32 byte_offset)
383 return (u32 *)(g->sim.recv_bfr.kvaddr + byte_offset);
386 static int rpc_recv_poll(struct gk20a *g)
388 phys_addr_t recv_phys_addr;
390 /* XXX This read is not required (?) */
391 /*pVGpu->recv_ring_get = VGPU_REG_RD32(pGpu, NV_VGPU_RECV_GET);*/
393 /* Poll the recv ring get pointer in an infinite loop*/
395 g->sim.recv_ring_put = sim_readl(g, sim_recv_put_r());
396 } while (g->sim.recv_ring_put == g->sim.recv_ring_get);
398 /* process all replies */
399 while (g->sim.recv_ring_put != g->sim.recv_ring_get) {
400 /* these are in u32 offsets*/
402 sim_recv_put_pointer_v(g->sim.recv_ring_get)*2 + 0;
403 /*u32 dma_hi_offset = dma_lo_offset + 1;*/
404 u32 recv_phys_addr_lo = sim_dma_addr_lo_v(*sim_recv_ring_bfr(g, dma_lo_offset*4));
406 /*u32 recv_phys_addr_hi = sim_dma_hi_addr_v(
407 (phys_addr_t)sim_recv_ring_bfr(g,dma_hi_offset*4));*/
409 /*TBD >32b phys addr */
410 recv_phys_addr = recv_phys_addr_lo << PAGE_SHIFT;
412 if (recv_phys_addr != g->sim.msg_bfr.phys) {
413 dev_err(dev_from_gk20a(g), "%s Error in RPC reply\n",
418 /* Update GET pointer */
419 g->sim.recv_ring_get = (g->sim.recv_ring_get + 2*sizeof(u32)) %
422 __cpuc_flush_dcache_area(g->sim.msg_bfr.kvaddr, PAGE_SIZE);
423 __cpuc_flush_dcache_area(g->sim.send_bfr.kvaddr, PAGE_SIZE);
424 __cpuc_flush_dcache_area(g->sim.recv_bfr.kvaddr, PAGE_SIZE);
426 sim_writel(g, sim_recv_get_r(), g->sim.recv_ring_get);
428 g->sim.recv_ring_put = sim_readl(g, sim_recv_put_r());
434 static int issue_rpc_and_wait(struct gk20a *g)
438 err = rpc_send_message(g);
440 dev_err(dev_from_gk20a(g), "%s failed rpc_send_message\n",
445 err = rpc_recv_poll(g);
447 dev_err(dev_from_gk20a(g), "%s failed rpc_recv_poll\n",
452 /* Now check if RPC really succeeded */
453 if (*sim_msg_hdr(g, sim_msg_result_r()) != sim_msg_result_success_v()) {
454 dev_err(dev_from_gk20a(g), "%s received failed status!\n",
456 return -(*sim_msg_hdr(g, sim_msg_result_r()));
461 int gk20a_sim_esc_read(struct gk20a *g, char *path, u32 index, u32 count, u32 *data)
464 size_t pathlen = strlen(path);
467 sim_write_hdr(g, sim_msg_function_sim_escape_read_v(),
468 sim_escape_read_hdr_size());
469 *sim_msg_param(g, 0) = index;
470 *sim_msg_param(g, 4) = count;
471 data_offset = roundup(0xc + pathlen + 1, sizeof(u32));
472 *sim_msg_param(g, 8) = data_offset;
473 strcpy((char *)sim_msg_param(g, 0xc), path);
475 err = issue_rpc_and_wait(g);
478 memcpy(data, sim_msg_param(g, data_offset), count);
482 static irqreturn_t gk20a_intr_isr_stall(int irq, void *dev_id)
484 struct gk20a *g = dev_id;
490 /* not from gpu when sharing irq with others */
491 mc_intr_0 = gk20a_readl(g, mc_intr_0_r());
492 if (unlikely(!mc_intr_0))
495 gk20a_writel(g, mc_intr_en_0_r(),
496 mc_intr_en_0_inta_disabled_f());
498 /* flush previous write */
499 gk20a_readl(g, mc_intr_en_0_r());
501 return IRQ_WAKE_THREAD;
504 static irqreturn_t gk20a_intr_isr_nonstall(int irq, void *dev_id)
506 struct gk20a *g = dev_id;
512 /* not from gpu when sharing irq with others */
513 mc_intr_1 = gk20a_readl(g, mc_intr_1_r());
514 if (unlikely(!mc_intr_1))
517 gk20a_writel(g, mc_intr_en_1_r(),
518 mc_intr_en_1_inta_disabled_f());
520 /* flush previous write */
521 gk20a_readl(g, mc_intr_en_1_r());
523 return IRQ_WAKE_THREAD;
526 static void gk20a_pbus_isr(struct gk20a *g)
529 val = gk20a_readl(g, bus_intr_0_r());
530 if (val & (bus_intr_0_pri_squash_m() |
531 bus_intr_0_pri_fecserr_m() |
532 bus_intr_0_pri_timeout_m())) {
533 gk20a_err(dev_from_gk20a(g), "pmc_enable : 0x%x",
534 gk20a_readl(g, mc_enable_r()));
535 gk20a_err(&g->dev->dev,
536 "NV_PTIMER_PRI_TIMEOUT_SAVE_0: 0x%x\n",
537 gk20a_readl(g, timer_pri_timeout_save_0_r()));
538 gk20a_err(&g->dev->dev,
539 "NV_PTIMER_PRI_TIMEOUT_SAVE_1: 0x%x\n",
540 gk20a_readl(g, timer_pri_timeout_save_1_r()));
541 gk20a_err(&g->dev->dev,
542 "NV_PTIMER_PRI_TIMEOUT_FECS_ERRCODE: 0x%x\n",
543 gk20a_readl(g, timer_pri_timeout_fecs_errcode_r()));
547 gk20a_err(&g->dev->dev,
548 "Unhandled pending pbus interrupt\n");
550 gk20a_writel(g, bus_intr_0_r(), val);
553 static irqreturn_t gk20a_intr_thread_stall(int irq, void *dev_id)
555 struct gk20a *g = dev_id;
558 gk20a_dbg(gpu_dbg_intr, "interrupt thread launched");
560 mc_intr_0 = gk20a_readl(g, mc_intr_0_r());
562 gk20a_dbg(gpu_dbg_intr, "stall intr %08x\n", mc_intr_0);
564 if (mc_intr_0 & mc_intr_0_pgraph_pending_f())
565 gr_gk20a_elpg_protected_call(g, gk20a_gr_isr(g));
566 if (mc_intr_0 & mc_intr_0_pfifo_pending_f())
568 if (mc_intr_0 & mc_intr_0_pmu_pending_f())
570 if (mc_intr_0 & mc_intr_0_priv_ring_pending_f())
571 gk20a_priv_ring_isr(g);
572 if (mc_intr_0 & mc_intr_0_ltc_pending_f())
574 if (mc_intr_0 & mc_intr_0_pbus_pending_f())
577 gk20a_writel(g, mc_intr_en_0_r(),
578 mc_intr_en_0_inta_hardware_f());
580 /* flush previous write */
581 gk20a_readl(g, mc_intr_en_0_r());
586 static irqreturn_t gk20a_intr_thread_nonstall(int irq, void *dev_id)
588 struct gk20a *g = dev_id;
591 gk20a_dbg(gpu_dbg_intr, "interrupt thread launched");
593 mc_intr_1 = gk20a_readl(g, mc_intr_1_r());
595 gk20a_dbg(gpu_dbg_intr, "non-stall intr %08x\n", mc_intr_1);
597 if (mc_intr_1 & mc_intr_0_pfifo_pending_f())
598 gk20a_fifo_nonstall_isr(g);
599 if (mc_intr_1 & mc_intr_0_pgraph_pending_f())
600 gk20a_gr_nonstall_isr(g);
602 gk20a_writel(g, mc_intr_en_1_r(),
603 mc_intr_en_1_inta_hardware_f());
605 /* flush previous write */
606 gk20a_readl(g, mc_intr_en_1_r());
611 static void gk20a_remove_support(struct platform_device *dev)
613 struct gk20a *g = get_gk20a(dev);
615 if (g->pmu.remove_support)
616 g->pmu.remove_support(&g->pmu);
618 if (g->gk20a_cdev.gk20a_cooling_dev)
619 thermal_cooling_device_unregister(g->gk20a_cdev.gk20a_cooling_dev);
621 if (g->gr.remove_support)
622 g->gr.remove_support(&g->gr);
624 if (g->fifo.remove_support)
625 g->fifo.remove_support(&g->fifo);
627 if (g->mm.remove_support)
628 g->mm.remove_support(&g->mm);
630 if (g->sim.remove_support)
631 g->sim.remove_support(&g->sim);
633 release_firmware(g->pmu_fw);
635 free_irq(g->irq_stall, g);
636 free_irq(g->irq_nonstall, g);
638 /* free mappings to registers, etc*/
650 static int gk20a_init_support(struct platform_device *dev)
653 struct gk20a *g = get_gk20a(dev);
655 g->regs = gk20a_ioremap_resource(dev, GK20A_BAR0_IORESOURCE_MEM,
658 dev_err(dev_from_gk20a(g), "failed to remap gk20a registers\n");
663 g->bar1 = gk20a_ioremap_resource(dev, GK20A_BAR1_IORESOURCE_MEM,
666 dev_err(dev_from_gk20a(g), "failed to remap gk20a bar1\n");
671 /* Get interrupt numbers */
672 g->irq_nonstall = platform_get_irq(dev, 1);
673 if (g->irq_stall < 0 || g->irq_nonstall < 0) {
678 if (tegra_cpu_is_asim()) {
679 err = gk20a_init_sim_support(dev);
684 mutex_init(&g->dbg_sessions_lock);
685 mutex_init(&g->client_lock);
687 g->remove_support = gk20a_remove_support;
691 gk20a_remove_support(dev);
695 static int gk20a_init_client(struct platform_device *dev)
697 struct gk20a *g = get_gk20a(dev);
702 #ifndef CONFIG_PM_RUNTIME
703 gk20a_pm_finalize_poweron(&dev->dev);
706 err = gk20a_init_mm_setup_sw(g);
710 if (IS_ENABLED(CONFIG_GK20A_DEVFREQ))
711 gk20a_scale_hw_init(dev);
715 static void gk20a_deinit_client(struct platform_device *dev)
718 #ifndef CONFIG_PM_RUNTIME
719 gk20a_pm_prepare_poweroff(&dev->dev);
723 int gk20a_get_client(struct gk20a *g)
727 mutex_lock(&g->client_lock);
728 if (g->client_refcount == 0)
729 err = gk20a_init_client(g->dev);
731 g->client_refcount++;
732 mutex_unlock(&g->client_lock);
736 void gk20a_put_client(struct gk20a *g)
738 mutex_lock(&g->client_lock);
739 if (g->client_refcount == 1)
740 gk20a_deinit_client(g->dev);
741 g->client_refcount--;
742 mutex_unlock(&g->client_lock);
743 WARN_ON(g->client_refcount < 0);
746 static int gk20a_pm_prepare_poweroff(struct device *dev)
748 struct platform_device *pdev = to_platform_device(dev);
749 struct gk20a *g = get_gk20a(pdev);
754 gk20a_scale_suspend(pdev);
759 ret = gk20a_channel_suspend(g);
764 * After this point, gk20a interrupts should not get
767 disable_irq(g->irq_stall);
768 disable_irq(g->irq_nonstall);
770 /* disable elpg before gr or fifo suspend */
771 ret |= gk20a_pmu_destroy(g);
772 ret |= gk20a_gr_suspend(g);
773 ret |= gk20a_mm_suspend(g);
774 ret |= gk20a_fifo_suspend(g);
777 ret |= gk20a_suspend_clk_support(g);
784 static void gk20a_detect_chip(struct gk20a *g)
786 struct nvhost_gpu_characteristics *gpu = &g->gpu_characteristics;
788 u32 mc_boot_0_value = gk20a_readl(g, mc_boot_0_r());
789 gpu->arch = mc_boot_0_architecture_v(mc_boot_0_value) <<
790 NVHOST_GPU_ARCHITECTURE_SHIFT;
791 gpu->impl = mc_boot_0_implementation_v(mc_boot_0_value);
793 (mc_boot_0_major_revision_v(mc_boot_0_value) << 4) |
794 mc_boot_0_minor_revision_v(mc_boot_0_value);
796 gk20a_dbg_info("arch: %x, impl: %x, rev: %x\n",
797 g->gpu_characteristics.arch,
798 g->gpu_characteristics.impl,
799 g->gpu_characteristics.rev);
802 static int gk20a_pm_finalize_poweron(struct device *dev)
804 struct platform_device *pdev = to_platform_device(dev);
805 struct gk20a *g = get_gk20a(pdev);
813 nice_value = task_nice(current);
814 set_user_nice(current, -20);
816 enable_irq(g->irq_stall);
817 enable_irq(g->irq_nonstall);
821 gk20a_writel(g, mc_intr_mask_1_r(),
822 mc_intr_0_pfifo_pending_f()
823 | mc_intr_0_pgraph_pending_f());
824 gk20a_writel(g, mc_intr_en_1_r(),
825 mc_intr_en_1_inta_hardware_f());
827 gk20a_writel(g, mc_intr_mask_0_r(),
828 mc_intr_0_pgraph_pending_f()
829 | mc_intr_0_pfifo_pending_f()
830 | mc_intr_0_priv_ring_pending_f()
831 | mc_intr_0_ltc_pending_f()
832 | mc_intr_0_pbus_pending_f());
833 gk20a_writel(g, mc_intr_en_0_r(),
834 mc_intr_en_0_inta_hardware_f());
836 if (!tegra_platform_is_silicon())
837 gk20a_writel(g, bus_intr_en_0_r(), 0x0);
839 gk20a_writel(g, bus_intr_en_0_r(),
840 bus_intr_en_0_pri_squash_m() |
841 bus_intr_en_0_pri_fecserr_m() |
842 bus_intr_en_0_pri_timeout_m());
843 gk20a_reset_priv_ring(g);
845 gk20a_detect_chip(g);
846 err = gpu_init_hal(g);
850 /* TBD: move this after graphics init in which blcg/slcg is enabled.
851 This function removes SlowdownOnBoot which applies 32x divider
852 on gpcpll bypass path. The purpose of slowdown is to save power
853 during boot but it also significantly slows down gk20a init on
854 simulation and emulation. We should remove SOB after graphics power
855 saving features (blcg/slcg) are enabled. For now, do it here. */
856 err = gk20a_init_clk_support(g);
858 gk20a_err(dev, "failed to init gk20a clk");
862 /* enable pri timeout only on silicon */
863 if (tegra_platform_is_silicon()) {
865 timer_pri_timeout_r(),
866 timer_pri_timeout_period_f(0x186A0) |
867 timer_pri_timeout_en_en_enabled_f());
870 timer_pri_timeout_r(),
871 timer_pri_timeout_period_f(0x186A0) |
872 timer_pri_timeout_en_en_disabled_f());
875 err = gk20a_init_fifo_reset_enable_hw(g);
877 gk20a_err(dev, "failed to reset gk20a fifo");
881 err = gk20a_init_mm_support(g);
883 gk20a_err(dev, "failed to init gk20a mm");
887 err = gk20a_init_pmu_support(g);
889 gk20a_err(dev, "failed to init gk20a pmu");
893 err = gk20a_init_fifo_support(g);
895 gk20a_err(dev, "failed to init gk20a fifo");
899 err = gk20a_init_gr_support(g);
901 gk20a_err(dev, "failed to init gk20a gr");
905 err = gk20a_init_therm_support(g);
907 gk20a_err(dev, "failed to init gk20a therm");
911 err = gk20a_init_gpu_characteristics(g);
913 gk20a_err(dev, "failed to init gk20a gpu characteristics");
917 wait_event(g->pmu.boot_wq, g->pmu.pmu_state == PMU_STATE_STARTED);
919 gk20a_channel_resume(g);
920 set_user_nice(current, nice_value);
922 gk20a_scale_resume(pdev);
924 #ifdef CONFIG_INPUT_CFBOOST
925 if (!g->boost_added) {
926 gk20a_dbg_info("add touch boost");
928 g->boost_added = true;
935 static struct of_device_id tegra_gk20a_of_match[] = {
936 #ifdef CONFIG_TEGRA_GK20A
937 { .compatible = "nvidia,tegra124-gk20a",
938 .data = &gk20a_tegra_platform },
940 { .compatible = "nvidia,generic-gk20a",
941 .data = &gk20a_generic_platform },
945 int tegra_gpu_get_max_state(struct thermal_cooling_device *cdev,
946 unsigned long *max_state)
948 struct cooling_device_gk20a *gk20a_gpufreq_device = cdev->devdata;
950 *max_state = gk20a_gpufreq_device->gk20a_freq_table_size - 1;
954 int tegra_gpu_get_cur_state(struct thermal_cooling_device *cdev,
955 unsigned long *cur_state)
957 struct cooling_device_gk20a *gk20a_gpufreq_device = cdev->devdata;
959 *cur_state = gk20a_gpufreq_device->gk20a_freq_state;
963 int tegra_gpu_set_cur_state(struct thermal_cooling_device *c_dev,
964 unsigned long cur_state)
968 struct gpufreq_table_data *gpu_cooling_table;
969 struct cooling_device_gk20a *gk20a_gpufreq_device = c_dev->devdata;
971 BUG_ON(cur_state >= gk20a_gpufreq_device->gk20a_freq_table_size);
973 g = container_of(gk20a_gpufreq_device, struct gk20a, gk20a_cdev);
975 gpu_cooling_table = tegra_gpufreq_table_get();
976 target_freq = gpu_cooling_table[cur_state].frequency;
978 /* ensure a query for state will get the proper value */
979 gk20a_gpufreq_device->gk20a_freq_state = cur_state;
981 gk20a_clk_set_rate(g, target_freq);
986 static struct thermal_cooling_device_ops tegra_gpu_cooling_ops = {
987 .get_max_state = tegra_gpu_get_max_state,
988 .get_cur_state = tegra_gpu_get_cur_state,
989 .set_cur_state = tegra_gpu_set_cur_state,
992 static int gk20a_create_device(
993 struct platform_device *pdev, int devno, const char *cdev_name,
994 struct cdev *cdev, struct device **out,
995 const struct file_operations *ops)
999 struct gk20a *g = get_gk20a(pdev);
1003 cdev_init(cdev, ops);
1004 cdev->owner = THIS_MODULE;
1006 err = cdev_add(cdev, devno, 1);
1009 "failed to add %s cdev\n", cdev_name);
1013 dev = device_create(g->class, NULL, devno, NULL,
1014 (pdev->id <= 0) ? INTERFACE_NAME : INTERFACE_NAME ".%d",
1015 cdev_name, pdev->id);
1021 "failed to create %s device for %s\n",
1022 cdev_name, pdev->name);
1030 static void gk20a_user_deinit(struct platform_device *dev)
1032 struct gk20a *g = get_gk20a(dev);
1034 if (g->channel.node) {
1035 device_destroy(g->class, g->channel.cdev.dev);
1036 cdev_del(&g->channel.cdev);
1040 device_destroy(g->class, g->as.cdev.dev);
1041 cdev_del(&g->as.cdev);
1045 device_destroy(g->class, g->ctrl.cdev.dev);
1046 cdev_del(&g->ctrl.cdev);
1050 device_destroy(g->class, g->dbg.cdev.dev);
1051 cdev_del(&g->dbg.cdev);
1055 device_destroy(g->class, g->prof.cdev.dev);
1056 cdev_del(&g->prof.cdev);
1060 unregister_chrdev_region(g->cdev_region, GK20A_NUM_CDEVS);
1063 class_destroy(g->class);
1066 static int gk20a_user_init(struct platform_device *dev)
1070 struct gk20a *g = get_gk20a(dev);
1072 g->class = class_create(THIS_MODULE, CLASS_NAME);
1073 if (IS_ERR(g->class)) {
1074 err = PTR_ERR(g->class);
1077 "failed to create " CLASS_NAME " class\n");
1081 err = alloc_chrdev_region(&devno, 0, GK20A_NUM_CDEVS, CLASS_NAME);
1083 dev_err(&dev->dev, "failed to allocate devno\n");
1086 g->cdev_region = devno;
1088 err = gk20a_create_device(dev, devno++, "",
1089 &g->channel.cdev, &g->channel.node,
1090 &gk20a_channel_ops);
1094 err = gk20a_create_device(dev, devno++, "-as",
1095 &g->as.cdev, &g->as.node,
1100 err = gk20a_create_device(dev, devno++, "-ctrl",
1101 &g->ctrl.cdev, &g->ctrl.node,
1106 err = gk20a_create_device(dev, devno++, "-dbg",
1107 &g->dbg.cdev, &g->dbg.node,
1112 err = gk20a_create_device(dev, devno++, "-prof",
1113 &g->prof.cdev, &g->prof.node,
1120 gk20a_user_deinit(dev);
1124 struct channel_gk20a *gk20a_get_channel_from_file(int fd)
1126 struct channel_gk20a *ch;
1127 struct file *f = fget(fd);
1131 if (f->f_op != &gk20a_channel_ops) {
1136 ch = (struct channel_gk20a *)f->private_data;
1141 static int gk20a_pm_enable_clk(struct device *dev)
1144 struct gk20a_platform *platform;
1146 platform = dev_get_drvdata(dev);
1150 for (index = 0; index < platform->num_clks; index++) {
1151 int err = clk_prepare_enable(platform->clk[index]);
1159 static int gk20a_pm_disable_clk(struct device *dev)
1162 struct gk20a_platform *platform;
1164 platform = dev_get_drvdata(dev);
1168 for (index = 0; index < platform->num_clks; index++)
1169 clk_disable_unprepare(platform->clk[index]);
1174 static void gk20a_pm_shutdown(struct platform_device *pdev)
1176 dev_info(&pdev->dev, "shutting down");
1177 __pm_runtime_disable(&pdev->dev, false);
1181 const struct dev_pm_ops gk20a_pm_ops = {
1182 #if defined(CONFIG_PM_RUNTIME) && !defined(CONFIG_PM_GENERIC_DOMAINS)
1183 .runtime_resume = gk20a_pm_enable_clk,
1184 .runtime_suspend = gk20a_pm_disable_clk,
1189 static int gk20a_pm_railgate(struct generic_pm_domain *domain)
1191 struct gk20a *g = container_of(domain, struct gk20a, pd);
1192 struct gk20a_platform *platform = platform_get_drvdata(g->dev);
1195 if (platform->railgate)
1196 ret = platform->railgate(platform->g->dev);
1201 static int gk20a_pm_unrailgate(struct generic_pm_domain *domain)
1203 struct gk20a *g = container_of(domain, struct gk20a, pd);
1204 struct gk20a_platform *platform = platform_get_drvdata(g->dev);
1207 if (platform->unrailgate) {
1208 mutex_lock(&platform->railgate_lock);
1209 ret = platform->unrailgate(platform->g->dev);
1210 mutex_unlock(&platform->railgate_lock);
1216 static int gk20a_pm_suspend(struct device *dev)
1218 struct gk20a_platform *platform = dev_get_drvdata(dev);
1221 if (atomic_read(&dev->power.usage_count) > 1)
1224 ret = gk20a_pm_prepare_poweroff(dev);
1228 if (platform->suspend)
1229 platform->suspend(dev);
1234 static int gk20a_pm_resume(struct device *dev)
1236 return gk20a_pm_finalize_poweron(dev);
1239 static int gk20a_pm_initialise_domain(struct platform_device *pdev)
1241 struct gk20a_platform *platform = platform_get_drvdata(pdev);
1242 struct dev_power_governor *pm_domain_gov = NULL;
1243 struct generic_pm_domain *domain = &platform->g->pd;
1246 domain->name = "gpu";
1248 if (!platform->can_railgate)
1249 pm_domain_gov = &pm_domain_always_on_gov;
1251 pm_genpd_init(domain, pm_domain_gov, true);
1253 domain->power_off = gk20a_pm_railgate;
1254 domain->power_on = gk20a_pm_unrailgate;
1255 domain->dev_ops.start = gk20a_pm_enable_clk;
1256 domain->dev_ops.stop = gk20a_pm_disable_clk;
1257 domain->dev_ops.save_state = gk20a_pm_prepare_poweroff;
1258 domain->dev_ops.restore_state = gk20a_pm_finalize_poweron;
1259 domain->dev_ops.suspend = gk20a_pm_suspend;
1260 domain->dev_ops.resume = gk20a_pm_resume;
1262 device_set_wakeup_capable(&pdev->dev, 0);
1263 ret = pm_genpd_add_device(domain, &pdev->dev);
1265 if (platform->railgate_delay)
1266 pm_genpd_set_poweroff_delay(domain, platform->railgate_delay);
1271 static int gk20a_pm_init(struct platform_device *dev)
1273 struct gk20a_platform *platform = platform_get_drvdata(dev);
1276 mutex_init(&platform->railgate_lock);
1278 /* Initialise pm runtime */
1279 if (platform->clockgate_delay) {
1280 pm_runtime_set_autosuspend_delay(&dev->dev,
1281 platform->clockgate_delay);
1282 pm_runtime_use_autosuspend(&dev->dev);
1285 pm_runtime_enable(&dev->dev);
1286 if (!pm_runtime_enabled(&dev->dev))
1287 gk20a_pm_enable_clk(&dev->dev);
1289 /* Enable runtime railgating if possible. If not,
1290 * turn on the rail now. */
1291 if (platform->can_railgate && IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS))
1292 platform->railgate(dev);
1294 platform->unrailgate(dev);
1296 /* genpd will take care of runtime power management if it is enabled */
1297 if (IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS))
1298 err = gk20a_pm_initialise_domain(dev);
1303 int gk20a_secure_page_alloc(struct platform_device *pdev)
1305 struct gk20a_platform *platform = platform_get_drvdata(pdev);
1308 if (platform->secure_page_alloc) {
1309 tegra_periph_reset_assert(platform->clk[0]);
1311 err = platform->secure_page_alloc(pdev);
1312 tegra_periph_reset_deassert(platform->clk[0]);
1314 platform->secure_alloc_ready = true;
1320 static int gk20a_probe(struct platform_device *dev)
1322 struct gk20a *gk20a;
1324 struct gk20a_platform *platform = NULL;
1325 struct cooling_device_gk20a *gpu_cdev = NULL;
1327 if (dev->dev.of_node) {
1328 const struct of_device_id *match;
1330 match = of_match_device(tegra_gk20a_of_match, &dev->dev);
1332 platform = (struct gk20a_platform *)match->data;
1334 platform = (struct gk20a_platform *)dev->dev.platform_data;
1337 dev_err(&dev->dev, "no platform data\n");
1343 platform_set_drvdata(dev, platform);
1345 gk20a = kzalloc(sizeof(struct gk20a), GFP_KERNEL);
1347 dev_err(&dev->dev, "couldn't allocate gk20a support");
1351 set_gk20a(dev, gk20a);
1354 gk20a->irq_stall = platform_get_irq(dev, 0);
1355 gk20a->irq_nonstall = platform_get_irq(dev, 1);
1356 if (gk20a->irq_stall < 0 || gk20a->irq_nonstall < 0)
1358 err = devm_request_threaded_irq(&dev->dev,
1360 gk20a_intr_isr_stall,
1361 gk20a_intr_thread_stall,
1362 0, "gk20a_stall", gk20a);
1365 "failed to request stall intr irq @ %d\n",
1369 err = devm_request_threaded_irq(&dev->dev,
1370 gk20a->irq_nonstall,
1371 gk20a_intr_isr_nonstall,
1372 gk20a_intr_thread_nonstall,
1373 0, "gk20a_nonstall", gk20a);
1376 "failed to request non-stall intr irq @ %d\n",
1377 gk20a->irq_nonstall);
1380 disable_irq(gk20a->irq_stall);
1381 disable_irq(gk20a->irq_nonstall);
1383 err = gk20a_user_init(dev);
1387 gk20a_init_support(dev);
1389 init_rwsem(&gk20a->busy_lock);
1391 spin_lock_init(&gk20a->mc_enable_lock);
1393 /* Initialize the platform interface. */
1394 err = platform->probe(dev);
1396 dev_err(&dev->dev, "platform probe failed");
1400 err = gk20a_pm_init(dev);
1402 dev_err(&dev->dev, "pm init failed");
1406 /* Initialise scaling */
1407 if (IS_ENABLED(CONFIG_GK20A_DEVFREQ))
1408 gk20a_scale_init(dev);
1410 if (platform->late_probe) {
1411 err = platform->late_probe(dev);
1413 dev_err(&dev->dev, "late probe failed");
1418 err = gk20a_secure_page_alloc(dev);
1421 "failed to allocate secure buffer %d\n", err);
1423 gk20a_debug_init(dev);
1425 /* Set DMA parameters to allow larger sgt lists */
1426 dev->dev.dma_parms = &gk20a->dma_parms;
1427 dma_set_max_seg_size(&dev->dev, UINT_MAX);
1429 gpu_cdev = &gk20a->gk20a_cdev;
1430 gpu_cdev->gk20a_freq_table_size = tegra_gpufreq_table_size_get();
1431 gpu_cdev->gk20a_freq_state = 0;
1432 gpu_cdev->g = gk20a;
1433 gpu_cdev->gk20a_cooling_dev = thermal_cooling_device_register("gk20a_cdev", gpu_cdev,
1434 &tegra_gpu_cooling_ops);
1436 gk20a->gr_idle_timeout_default =
1437 CONFIG_GK20A_DEFAULT_TIMEOUT;
1438 gk20a->timeouts_enabled = true;
1440 /* Set up initial clock gating settings */
1441 if (tegra_platform_is_silicon()) {
1442 gk20a->slcg_enabled = true;
1443 gk20a->blcg_enabled = true;
1444 gk20a->elcg_enabled = true;
1445 gk20a->elpg_enabled = true;
1446 gk20a->aelpg_enabled = true;
1449 gk20a_create_sysfs(dev);
1451 #ifdef CONFIG_DEBUG_FS
1452 clk_gk20a_debugfs_init(dev);
1454 spin_lock_init(&gk20a->debugfs_lock);
1455 gk20a->mm.ltc_enabled = true;
1456 gk20a->mm.ltc_enabled_debug = true;
1457 gk20a->debugfs_ltc_enabled =
1458 debugfs_create_bool("ltc_enabled", S_IRUGO|S_IWUSR,
1460 &gk20a->mm.ltc_enabled_debug);
1461 gk20a->mm.ltc_enabled_debug = true;
1462 gk20a->debugfs_gr_idle_timeout_default =
1463 debugfs_create_u32("gr_idle_timeout_default_us",
1464 S_IRUGO|S_IWUSR, platform->debugfs,
1465 &gk20a->gr_idle_timeout_default);
1466 gk20a->debugfs_timeouts_enabled =
1467 debugfs_create_bool("timeouts_enabled",
1470 &gk20a->timeouts_enabled);
1471 gk20a_pmu_debugfs_init(dev);
1473 init_waitqueue_head(&gk20a->pmu.boot_wq);
1475 gk20a_init_gr(gk20a);
1480 static int __exit gk20a_remove(struct platform_device *dev)
1482 struct gk20a *g = get_gk20a(dev);
1485 #ifdef CONFIG_INPUT_CFBOOST
1487 cfb_remove_device(&dev->dev);
1490 if (g->remove_support)
1491 g->remove_support(dev);
1493 gk20a_user_deinit(dev);
1496 #ifdef CONFIG_DEBUG_FS
1497 debugfs_remove(g->debugfs_ltc_enabled);
1498 debugfs_remove(g->debugfs_gr_idle_timeout_default);
1499 debugfs_remove(g->debugfs_timeouts_enabled);
1504 #ifdef CONFIG_PM_RUNTIME
1505 pm_runtime_put(&dev->dev);
1506 pm_runtime_disable(&dev->dev);
1508 nvhost_module_disable_clk(&dev->dev);
1514 static struct platform_driver gk20a_driver = {
1515 .probe = gk20a_probe,
1516 .remove = __exit_p(gk20a_remove),
1517 .shutdown = gk20a_pm_shutdown,
1519 .owner = THIS_MODULE,
1522 .of_match_table = tegra_gk20a_of_match,
1525 .pm = &gk20a_pm_ops,
1530 static int __init gk20a_init(void)
1532 return platform_driver_register(&gk20a_driver);
1535 static void __exit gk20a_exit(void)
1537 platform_driver_unregister(&gk20a_driver);
1540 bool is_gk20a_module(struct platform_device *dev)
1542 return &gk20a_driver.driver == dev->dev.driver;
1545 void gk20a_busy_noresume(struct platform_device *pdev)
1547 pm_runtime_get_noresume(&pdev->dev);
1550 int gk20a_busy(struct platform_device *pdev)
1553 struct gk20a *g = get_gk20a(pdev);
1555 down_read(&g->busy_lock);
1557 #ifdef CONFIG_PM_RUNTIME
1558 ret = pm_runtime_get_sync(&pdev->dev);
1560 pm_runtime_put_noidle(&pdev->dev);
1562 gk20a_scale_notify_busy(pdev);
1564 up_read(&g->busy_lock);
1566 return ret < 0 ? ret : 0;
1569 void gk20a_idle(struct platform_device *pdev)
1571 #ifdef CONFIG_PM_RUNTIME
1572 if (atomic_read(&pdev->dev.power.usage_count) == 1)
1573 gk20a_scale_notify_idle(pdev);
1574 pm_runtime_mark_last_busy(&pdev->dev);
1575 pm_runtime_put_sync_autosuspend(&pdev->dev);
1577 gk20a_scale_notify_idle(pdev);
1581 void gk20a_disable(struct gk20a *g, u32 units)
1585 gk20a_dbg(gpu_dbg_info, "pmc disable: %08x\n", units);
1587 spin_lock(&g->mc_enable_lock);
1588 pmc = gk20a_readl(g, mc_enable_r());
1590 gk20a_writel(g, mc_enable_r(), pmc);
1591 spin_unlock(&g->mc_enable_lock);
1594 void gk20a_enable(struct gk20a *g, u32 units)
1598 gk20a_dbg(gpu_dbg_info, "pmc enable: %08x\n", units);
1600 spin_lock(&g->mc_enable_lock);
1601 pmc = gk20a_readl(g, mc_enable_r());
1603 gk20a_writel(g, mc_enable_r(), pmc);
1604 gk20a_readl(g, mc_enable_r());
1605 spin_unlock(&g->mc_enable_lock);
1610 void gk20a_reset(struct gk20a *g, u32 units)
1612 gk20a_disable(g, units);
1614 gk20a_enable(g, units);
1618 * gk20a_do_idle() - force the GPU to idle and railgate
1620 * In success, this call MUST be balanced by caller with gk20a_do_unidle()
1622 int gk20a_do_idle(void)
1624 struct platform_device *pdev = to_platform_device(
1625 bus_find_device_by_name(&platform_bus_type,
1627 struct gk20a *g = get_gk20a(pdev);
1628 struct gk20a_platform *platform = dev_get_drvdata(&pdev->dev);
1629 unsigned long timeout = jiffies +
1630 msecs_to_jiffies(GK20A_WAIT_FOR_IDLE_MS);
1634 if (!platform->can_railgate)
1637 /* acquire busy lock to block other busy() calls */
1638 down_write(&g->busy_lock);
1640 /* acquire railgate lock to prevent unrailgate in midst of do_idle() */
1641 mutex_lock(&platform->railgate_lock);
1643 /* check if it is already railgated ? */
1644 if (platform->is_railgated(pdev))
1647 /* prevent suspend by incrementing usage counter */
1648 pm_runtime_get_noresume(&pdev->dev);
1650 /* check and wait until GPU is idle (with a timeout) */
1651 pm_runtime_barrier(&pdev->dev);
1655 ref_cnt = atomic_read(&pdev->dev.power.usage_count);
1656 } while (ref_cnt != 1 && time_before(jiffies, timeout));
1662 * if GPU is now idle, we will have only one ref count
1663 * drop this ref which will rail gate the GPU
1665 pm_runtime_put_sync(&pdev->dev);
1667 /* add sufficient delay to allow GPU to rail gate */
1668 msleep(platform->railgate_delay);
1670 timeout = jiffies + msecs_to_jiffies(GK20A_WAIT_FOR_IDLE_MS);
1672 /* check in loop if GPU is railgated or not */
1675 is_railgated = platform->is_railgated(pdev);
1676 } while (!is_railgated && time_before(jiffies, timeout));
1684 pm_runtime_put_noidle(&pdev->dev);
1686 mutex_unlock(&platform->railgate_lock);
1687 up_write(&g->busy_lock);
1692 * gk20a_do_unidle() - unblock all the tasks blocked by gk20a_do_idle()
1694 int gk20a_do_unidle(void)
1696 struct platform_device *pdev = to_platform_device(
1697 bus_find_device_by_name(&platform_bus_type,
1699 struct gk20a *g = get_gk20a(pdev);
1700 struct gk20a_platform *platform = dev_get_drvdata(&pdev->dev);
1702 /* release the lock and open up all other busy() calls */
1703 mutex_unlock(&platform->railgate_lock);
1704 up_write(&g->busy_lock);
1709 int gk20a_init_gpu_characteristics(struct gk20a *g)
1711 struct nvhost_gpu_characteristics *gpu = &g->gpu_characteristics;
1713 gpu->L2_cache_size = g->ops.ltc.determine_L2_size_bytes(g);
1714 gpu->on_board_video_memory_size = 0; /* integrated GPU */
1716 gpu->num_gpc = g->gr.gpc_count;
1717 gpu->num_tpc_per_gpc = g->gr.max_tpc_per_gpc_count;
1719 gpu->bus_type = NVHOST_GPU_BUS_TYPE_AXI; /* always AXI for now */
1721 gpu->big_page_size = g->mm.big_page_size;
1722 gpu->compression_page_size = g->mm.compression_page_size;
1723 gpu->pde_coverage_bit_count = g->mm.pde_stride_shift;
1729 static const struct firmware *
1730 do_request_firmware(struct device *dev, const char *prefix, const char *fw_name)
1732 const struct firmware *fw;
1733 char *fw_path = NULL;
1737 path_len = strlen(prefix) + strlen(fw_name);
1738 path_len += 2; /* for the path separator and zero terminator*/
1740 fw_path = kzalloc(sizeof(*fw_path) * path_len, GFP_KERNEL);
1744 sprintf(fw_path, "%s/%s", prefix, fw_name);
1748 err = request_firmware(&fw, fw_name, dev);
1755 /* This is a simple wrapper around request_firmware that takes 'fw_name' and
1756 * applies an IP specific relative path prefix to it. The caller is
1757 * responsible for calling release_firmware later. */
1758 const struct firmware *
1759 gk20a_request_firmware(struct gk20a *g, const char *fw_name)
1761 struct device *dev = &g->dev->dev;
1762 const struct firmware *fw;
1764 /* current->fs is NULL when calling from SYS_EXIT.
1765 Add a check here to prevent crash in request_firmware */
1766 if (!current->fs || !fw_name)
1769 BUG_ON(!g->ops.name);
1770 fw = do_request_firmware(dev, g->ops.name, fw_name);
1772 #ifdef CONFIG_TEGRA_GK20A
1773 /* TO BE REMOVED - Support loading from legacy SOC specific path. */
1775 fw = nvhost_client_request_firmware(g->dev, fw_name);
1779 dev_err(dev, "failed to get firmware\n");
1786 MODULE_LICENSE("GPL v2");
1787 module_init(gk20a_init);
1788 module_exit(gk20a_exit);