summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/clk
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-03-08 19:52:11 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2017-03-26 12:55:10 -0400
commitf403208306c100f16daf8577b585528124f9f004 (patch)
tree6d5b70d7c01ecb74aea66bcf2798c1be0a491ff2 /drivers/gpu/nvgpu/clk
parentc11228d48be1825e1ec84afd38c6938504fa4100 (diff)
gpu: nvgpu: Use new kmem API functions (clk/*)
Use the new kmem API functions in clk/*. Also add a struct gk20a pointer to the following functions: nvgpu_clk_notification_queue_alloc() nvgpu_clk_notification_queue_free() Bug 1799159 Bug 1823380 Change-Id: I7eb67dc443c0bbe0d3f67dac7bf363da60e1051c Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1318316 Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com> Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/clk')
-rw-r--r--drivers/gpu/nvgpu/clk/clk_arb.c75
-rw-r--r--drivers/gpu/nvgpu/clk/clk_mclk.c4
-rw-r--r--drivers/gpu/nvgpu/clk/clk_prog.c8
3 files changed, 45 insertions, 42 deletions
diff --git a/drivers/gpu/nvgpu/clk/clk_arb.c b/drivers/gpu/nvgpu/clk/clk_arb.c
index fc821235..9c954deb 100644
--- a/drivers/gpu/nvgpu/clk/clk_arb.c
+++ b/drivers/gpu/nvgpu/clk/clk_arb.c
@@ -11,18 +11,20 @@
11 * more details. 11 * more details.
12 */ 12 */
13 13
14#include "gk20a/gk20a.h"
15 14
16#include <linux/cdev.h> 15#include <linux/cdev.h>
17#include <linux/file.h> 16#include <linux/file.h>
18#include <linux/anon_inodes.h> 17#include <linux/anon_inodes.h>
19#include <linux/nvgpu.h> 18#include <linux/nvgpu.h>
20#include <linux/bitops.h> 19#include <linux/bitops.h>
21#include <nvgpu/lock.h>
22#include <linux/rculist.h> 20#include <linux/rculist.h>
23#include <linux/llist.h> 21#include <linux/llist.h>
24#include "clk/clk_arb.h"
25 22
23#include <nvgpu/lock.h>
24#include <nvgpu/kmem.h>
25
26#include "gk20a/gk20a.h"
27#include "clk/clk_arb.h"
26 28
27#define MAX_F_POINTS 256 29#define MAX_F_POINTS 256
28#define DEFAULT_EVENT_NUMBER 32 30#define DEFAULT_EVENT_NUMBER 32
@@ -66,11 +68,11 @@ static void nvgpu_clk_arb_clear_global_alarm(struct gk20a *g, u32 alarm);
66static void nvgpu_clk_arb_queue_notification(struct gk20a *g, 68static void nvgpu_clk_arb_queue_notification(struct gk20a *g,
67 struct nvgpu_clk_notification_queue *queue, 69 struct nvgpu_clk_notification_queue *queue,
68 u32 alarm_mask); 70 u32 alarm_mask);
69static int nvgpu_clk_notification_queue_alloc( 71static int nvgpu_clk_notification_queue_alloc(struct gk20a *g,
70 struct nvgpu_clk_notification_queue *queue, 72 struct nvgpu_clk_notification_queue *queue,
71 size_t events_number); 73 size_t events_number);
72 74
73static void nvgpu_clk_notification_queue_free( 75static void nvgpu_clk_notification_queue_free(struct gk20a *g,
74 struct nvgpu_clk_notification_queue *queue); 76 struct nvgpu_clk_notification_queue *queue);
75 77
76#define VF_POINT_INVALID_PSTATE ~0U 78#define VF_POINT_INVALID_PSTATE ~0U
@@ -230,11 +232,11 @@ static const struct file_operations event_dev_ops = {
230 .unlocked_ioctl = nvgpu_clk_arb_ioctl_event_dev, 232 .unlocked_ioctl = nvgpu_clk_arb_ioctl_event_dev,
231}; 233};
232 234
233static int nvgpu_clk_notification_queue_alloc( 235static int nvgpu_clk_notification_queue_alloc(struct gk20a *g,
234 struct nvgpu_clk_notification_queue *queue, 236 struct nvgpu_clk_notification_queue *queue,
235 size_t events_number) { 237 size_t events_number) {
236 queue->notifications = kcalloc(events_number, 238 queue->notifications = nvgpu_kcalloc(g, events_number,
237 sizeof(struct nvgpu_clk_notification), GFP_KERNEL); 239 sizeof(struct nvgpu_clk_notification));
238 if (!queue->notifications) 240 if (!queue->notifications)
239 return -ENOMEM; 241 return -ENOMEM;
240 queue->size = events_number; 242 queue->size = events_number;
@@ -245,9 +247,9 @@ static int nvgpu_clk_notification_queue_alloc(
245 return 0; 247 return 0;
246} 248}
247 249
248static void nvgpu_clk_notification_queue_free( 250static void nvgpu_clk_notification_queue_free(struct gk20a *g,
249 struct nvgpu_clk_notification_queue *queue) { 251 struct nvgpu_clk_notification_queue *queue) {
250 kfree(queue->notifications); 252 nvgpu_kfree(g, queue->notifications);
251 queue->size = 0; 253 queue->size = 0;
252 atomic_set(&queue->head, 0); 254 atomic_set(&queue->head, 0);
253 atomic_set(&queue->tail, 0); 255 atomic_set(&queue->tail, 0);
@@ -266,7 +268,7 @@ int nvgpu_clk_arb_init_arbiter(struct gk20a *g)
266 if (!g->ops.clk_arb.get_arbiter_clk_domains) 268 if (!g->ops.clk_arb.get_arbiter_clk_domains)
267 return 0; 269 return 0;
268 270
269 arb = kzalloc(sizeof(struct nvgpu_clk_arb), GFP_KERNEL); 271 arb = nvgpu_kzalloc(g, sizeof(struct nvgpu_clk_arb));
270 if (!arb) 272 if (!arb)
271 return -ENOMEM; 273 return -ENOMEM;
272 274
@@ -276,13 +278,13 @@ int nvgpu_clk_arb_init_arbiter(struct gk20a *g)
276 nvgpu_spinlock_init(&arb->sessions_lock); 278 nvgpu_spinlock_init(&arb->sessions_lock);
277 nvgpu_spinlock_init(&arb->users_lock); 279 nvgpu_spinlock_init(&arb->users_lock);
278 280
279 arb->mclk_f_points = kcalloc(MAX_F_POINTS, sizeof(u16), GFP_KERNEL); 281 arb->mclk_f_points = nvgpu_kcalloc(g, MAX_F_POINTS, sizeof(u16));
280 if (!arb->mclk_f_points) { 282 if (!arb->mclk_f_points) {
281 err = -ENOMEM; 283 err = -ENOMEM;
282 goto init_fail; 284 goto init_fail;
283 } 285 }
284 286
285 arb->gpc2clk_f_points = kcalloc(MAX_F_POINTS, sizeof(u16), GFP_KERNEL); 287 arb->gpc2clk_f_points = nvgpu_kcalloc(g, MAX_F_POINTS, sizeof(u16));
286 if (!arb->gpc2clk_f_points) { 288 if (!arb->gpc2clk_f_points) {
287 err = -ENOMEM; 289 err = -ENOMEM;
288 goto init_fail; 290 goto init_fail;
@@ -293,16 +295,16 @@ int nvgpu_clk_arb_init_arbiter(struct gk20a *g)
293 table->gpc2clk_num_points = MAX_F_POINTS; 295 table->gpc2clk_num_points = MAX_F_POINTS;
294 table->mclk_num_points = MAX_F_POINTS; 296 table->mclk_num_points = MAX_F_POINTS;
295 297
296 table->gpc2clk_points = kcalloc(MAX_F_POINTS, 298 table->gpc2clk_points = nvgpu_kcalloc(g, MAX_F_POINTS,
297 sizeof(struct nvgpu_clk_vf_point), GFP_KERNEL); 299 sizeof(struct nvgpu_clk_vf_point));
298 if (!table->gpc2clk_points) { 300 if (!table->gpc2clk_points) {
299 err = -ENOMEM; 301 err = -ENOMEM;
300 goto init_fail; 302 goto init_fail;
301 } 303 }
302 304
303 305
304 table->mclk_points = kcalloc(MAX_F_POINTS, 306 table->mclk_points = nvgpu_kcalloc(g, MAX_F_POINTS,
305 sizeof(struct nvgpu_clk_vf_point), GFP_KERNEL); 307 sizeof(struct nvgpu_clk_vf_point));
306 if (!table->mclk_points) { 308 if (!table->mclk_points) {
307 err = -ENOMEM; 309 err = -ENOMEM;
308 goto init_fail; 310 goto init_fail;
@@ -335,7 +337,7 @@ int nvgpu_clk_arb_init_arbiter(struct gk20a *g)
335 atomic_set(&arb->req_nr, 0); 337 atomic_set(&arb->req_nr, 0);
336 338
337 atomic64_set(&arb->alarm_mask, 0); 339 atomic64_set(&arb->alarm_mask, 0);
338 err = nvgpu_clk_notification_queue_alloc(&arb->notification_queue, 340 err = nvgpu_clk_notification_queue_alloc(g, &arb->notification_queue,
339 DEFAULT_EVENT_NUMBER); 341 DEFAULT_EVENT_NUMBER);
340 if (err < 0) 342 if (err < 0)
341 goto init_fail; 343 goto init_fail;
@@ -381,19 +383,18 @@ int nvgpu_clk_arb_init_arbiter(struct gk20a *g)
381 return arb->status; 383 return arb->status;
382 384
383init_fail: 385init_fail:
384 386 nvgpu_kfree(g, arb->gpc2clk_f_points);
385 kfree(arb->gpc2clk_f_points); 387 nvgpu_kfree(g, arb->mclk_f_points);
386 kfree(arb->mclk_f_points);
387 388
388 for (index = 0; index < 2; index++) { 389 for (index = 0; index < 2; index++) {
389 kfree(arb->vf_table_pool[index].gpc2clk_points); 390 nvgpu_kfree(g, arb->vf_table_pool[index].gpc2clk_points);
390 kfree(arb->vf_table_pool[index].mclk_points); 391 nvgpu_kfree(g, arb->vf_table_pool[index].mclk_points);
391 } 392 }
392 393
393 nvgpu_mutex_destroy(&arb->pstate_lock); 394 nvgpu_mutex_destroy(&arb->pstate_lock);
394 395
395mutex_fail: 396mutex_fail:
396 kfree(arb); 397 nvgpu_kfree(g, arb);
397 398
398 return err; 399 return err;
399} 400}
@@ -478,7 +479,7 @@ void nvgpu_clk_arb_cleanup_arbiter(struct gk20a *g)
478 } 479 }
479 480
480 nvgpu_mutex_destroy(&g->clk_arb->pstate_lock); 481 nvgpu_mutex_destroy(&g->clk_arb->pstate_lock);
481 kfree(g->clk_arb); 482 nvgpu_kfree(g, g->clk_arb);
482 g->clk_arb = NULL; 483 g->clk_arb = NULL;
483} 484}
484 485
@@ -488,19 +489,19 @@ static int nvgpu_clk_arb_install_fd(struct gk20a *g,
488 struct nvgpu_clk_dev **_dev) 489 struct nvgpu_clk_dev **_dev)
489{ 490{
490 struct file *file; 491 struct file *file;
491 char *name;
492 int fd; 492 int fd;
493 int err; 493 int err;
494 struct nvgpu_clk_dev *dev;
495 int status; 494 int status;
495 char name[64];
496 struct nvgpu_clk_dev *dev;
496 497
497 gk20a_dbg_fn(""); 498 gk20a_dbg_fn("");
498 499
499 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 500 dev = nvgpu_kzalloc(g, sizeof(*dev));
500 if (!dev) 501 if (!dev)
501 return -ENOMEM; 502 return -ENOMEM;
502 503
503 status = nvgpu_clk_notification_queue_alloc(&dev->queue, 504 status = nvgpu_clk_notification_queue_alloc(g, &dev->queue,
504 DEFAULT_EVENT_NUMBER); 505 DEFAULT_EVENT_NUMBER);
505 if (status < 0) { 506 if (status < 0) {
506 err = status; 507 err = status;
@@ -513,9 +514,8 @@ static int nvgpu_clk_arb_install_fd(struct gk20a *g,
513 goto fail; 514 goto fail;
514 } 515 }
515 516
516 name = kasprintf(GFP_KERNEL, "%s-clk-fd%d", dev_name(g->dev), fd); 517 snprintf(name, sizeof(name), "%s-clk-fd%d", dev_name(g->dev), fd);
517 file = anon_inode_getfile(name, fops, dev, O_RDWR); 518 file = anon_inode_getfile(name, fops, dev, O_RDWR);
518 kfree(name);
519 if (IS_ERR(file)) { 519 if (IS_ERR(file)) {
520 err = PTR_ERR(file); 520 err = PTR_ERR(file);
521 goto fail_fd; 521 goto fail_fd;
@@ -539,7 +539,7 @@ static int nvgpu_clk_arb_install_fd(struct gk20a *g,
539fail_fd: 539fail_fd:
540 put_unused_fd(fd); 540 put_unused_fd(fd);
541fail: 541fail:
542 kfree(dev); 542 nvgpu_kfree(g, dev);
543 543
544 return err; 544 return err;
545} 545}
@@ -555,7 +555,7 @@ int nvgpu_clk_arb_init_session(struct gk20a *g,
555 if (!g->ops.clk_arb.get_arbiter_clk_domains) 555 if (!g->ops.clk_arb.get_arbiter_clk_domains)
556 return 0; 556 return 0;
557 557
558 session = kzalloc(sizeof(struct nvgpu_clk_session), GFP_KERNEL); 558 session = nvgpu_kzalloc(g, sizeof(struct nvgpu_clk_session));
559 if (!session) 559 if (!session)
560 return -ENOMEM; 560 return -ENOMEM;
561 session->g = g; 561 session->g = g;
@@ -584,8 +584,9 @@ static void nvgpu_clk_arb_free_fd(struct kref *refcount)
584{ 584{
585 struct nvgpu_clk_dev *dev = container_of(refcount, 585 struct nvgpu_clk_dev *dev = container_of(refcount,
586 struct nvgpu_clk_dev, refcount); 586 struct nvgpu_clk_dev, refcount);
587 struct nvgpu_clk_session *session = dev->session;
587 588
588 kfree(dev); 589 nvgpu_kfree(session->g, dev);
589} 590}
590 591
591static void nvgpu_clk_arb_free_session(struct kref *refcount) 592static void nvgpu_clk_arb_free_session(struct kref *refcount)
@@ -593,6 +594,7 @@ static void nvgpu_clk_arb_free_session(struct kref *refcount)
593 struct nvgpu_clk_session *session = container_of(refcount, 594 struct nvgpu_clk_session *session = container_of(refcount,
594 struct nvgpu_clk_session, refcount); 595 struct nvgpu_clk_session, refcount);
595 struct nvgpu_clk_arb *arb = session->g->clk_arb; 596 struct nvgpu_clk_arb *arb = session->g->clk_arb;
597 struct gk20a *g = session->g;
596 struct nvgpu_clk_dev *dev, *tmp; 598 struct nvgpu_clk_dev *dev, *tmp;
597 struct llist_node *head; 599 struct llist_node *head;
598 600
@@ -609,7 +611,7 @@ static void nvgpu_clk_arb_free_session(struct kref *refcount)
609 kref_put(&dev->refcount, nvgpu_clk_arb_free_fd); 611 kref_put(&dev->refcount, nvgpu_clk_arb_free_fd);
610 } 612 }
611 synchronize_rcu(); 613 synchronize_rcu();
612 kfree(session); 614 nvgpu_kfree(g, session);
613} 615}
614 616
615void nvgpu_clk_arb_release_session(struct gk20a *g, 617void nvgpu_clk_arb_release_session(struct gk20a *g,
@@ -1618,12 +1620,11 @@ static int nvgpu_clk_arb_release_event_dev(struct inode *inode,
1618 nvgpu_spinlock_acquire(&arb->users_lock); 1620 nvgpu_spinlock_acquire(&arb->users_lock);
1619 list_del_rcu(&dev->link); 1621 list_del_rcu(&dev->link);
1620 nvgpu_spinlock_release(&arb->users_lock); 1622 nvgpu_spinlock_release(&arb->users_lock);
1623 nvgpu_clk_notification_queue_free(arb->g, &dev->queue);
1621 } 1624 }
1622 1625
1623 synchronize_rcu(); 1626 synchronize_rcu();
1624 kref_put(&session->refcount, nvgpu_clk_arb_free_session); 1627 kref_put(&session->refcount, nvgpu_clk_arb_free_session);
1625
1626 nvgpu_clk_notification_queue_free(&dev->queue);
1627 kref_put(&dev->refcount, nvgpu_clk_arb_free_fd); 1628 kref_put(&dev->refcount, nvgpu_clk_arb_free_fd);
1628 1629
1629 return 0; 1630 return 0;
diff --git a/drivers/gpu/nvgpu/clk/clk_mclk.c b/drivers/gpu/nvgpu/clk/clk_mclk.c
index e5452051..16852b5e 100644
--- a/drivers/gpu/nvgpu/clk/clk_mclk.c
+++ b/drivers/gpu/nvgpu/clk/clk_mclk.c
@@ -14,6 +14,7 @@
14#include <linux/delay.h> 14#include <linux/delay.h>
15 15
16#include <nvgpu/bios.h> 16#include <nvgpu/bios.h>
17#include <nvgpu/kmem.h>
17 18
18#include "gk20a/gk20a.h" 19#include "gk20a/gk20a.h"
19#include "gk20a/pmu_gk20a.h" 20#include "gk20a/pmu_gk20a.h"
@@ -2216,8 +2217,7 @@ int clk_mclkseq_init_mclk_gddr5(struct gk20a *g)
2216 mclk->p0_min = p0_info->min_mhz; 2217 mclk->p0_min = p0_info->min_mhz;
2217 2218
2218 2219
2219 mclk->vreg_buf = kcalloc(VREG_COUNT, 2220 mclk->vreg_buf = nvgpu_kcalloc(g, VREG_COUNT, sizeof(u32));
2220 sizeof(u32), GFP_KERNEL);
2221 if (!mclk->vreg_buf) { 2221 if (!mclk->vreg_buf) {
2222 gk20a_err(dev_from_gk20a(g), 2222 gk20a_err(dev_from_gk20a(g),
2223 "unable to allocate memory for VREG"); 2223 "unable to allocate memory for VREG");
diff --git a/drivers/gpu/nvgpu/clk/clk_prog.c b/drivers/gpu/nvgpu/clk/clk_prog.c
index b4f6a464..dc9c58a6 100644
--- a/drivers/gpu/nvgpu/clk/clk_prog.c
+++ b/drivers/gpu/nvgpu/clk/clk_prog.c
@@ -13,6 +13,8 @@
13 13
14#include <nvgpu/bios.h> 14#include <nvgpu/bios.h>
15 15
16#include <nvgpu/kmem.h>
17
16#include "gk20a/gk20a.h" 18#include "gk20a/gk20a.h"
17#include "clk.h" 19#include "clk.h"
18#include "clk_prog.h" 20#include "clk_prog.h"
@@ -613,7 +615,7 @@ static u32 clk_prog_construct_1x_master(struct gk20a *g,
613 getslaveclk_prog_1x_master; 615 getslaveclk_prog_1x_master;
614 616
615 pclkprog->p_vf_entries = (struct ctrl_clk_clk_prog_1x_master_vf_entry *) 617 pclkprog->p_vf_entries = (struct ctrl_clk_clk_prog_1x_master_vf_entry *)
616 kzalloc(vfsize, GFP_KERNEL); 618 nvgpu_kzalloc(g, vfsize);
617 619
618 memcpy(pclkprog->p_vf_entries, ptmpprog->p_vf_entries, vfsize); 620 memcpy(pclkprog->p_vf_entries, ptmpprog->p_vf_entries, vfsize);
619 621
@@ -658,7 +660,7 @@ static u32 clk_prog_construct_1x_master_ratio(struct gk20a *g,
658 660
659 pclkprog->p_slave_entries = 661 pclkprog->p_slave_entries =
660 (struct ctrl_clk_clk_prog_1x_master_ratio_slave_entry *) 662 (struct ctrl_clk_clk_prog_1x_master_ratio_slave_entry *)
661 kzalloc(slavesize, GFP_KERNEL); 663 nvgpu_kzalloc(g, slavesize);
662 if (!pclkprog->p_slave_entries) 664 if (!pclkprog->p_slave_entries)
663 return -ENOMEM; 665 return -ENOMEM;
664 666
@@ -699,7 +701,7 @@ static u32 clk_prog_construct_1x_master_table(struct gk20a *g,
699 701
700 pclkprog->p_slave_entries = 702 pclkprog->p_slave_entries =
701 (struct ctrl_clk_clk_prog_1x_master_table_slave_entry *) 703 (struct ctrl_clk_clk_prog_1x_master_table_slave_entry *)
702 kzalloc(slavesize, GFP_KERNEL); 704 nvgpu_kzalloc(g, slavesize);
703 705
704 if (!pclkprog->p_slave_entries) { 706 if (!pclkprog->p_slave_entries) {
705 status = -ENOMEM; 707 status = -ENOMEM;