From 448df6ed271a7b73a1a5e3dfbba826e745b82922 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Thu, 21 Jul 2016 18:26:20 -0700 Subject: gpu: nvgpu: Implement a vidmem allocator Implement an allocator suitable for managing the video memory on dGPUs. It works by allocating chunks from an underlying buddy allocator and collating the chunks together (similar to what an sgt does in the wider Linux kernel). This handles the ability to get large buffers in potentially fragmented memory. The GMMU can then obviously map the physical vidmem into contiguous GVA spaces. Jira DNVGPU-96 Change-Id: Ic1d7800b033a170b77790aa23fad6858443d0e89 Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1197203 (cherry picked from commit fa44684a843956ae384fef6d7a79b9cbbd04f73e) Reviewed-on: http://git-master/r/1185231 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/page_allocator_priv.h | 100 ++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 drivers/gpu/nvgpu/gk20a/page_allocator_priv.h (limited to 'drivers/gpu/nvgpu/gk20a/page_allocator_priv.h') diff --git a/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h b/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h new file mode 100644 index 00000000..bce5b75e --- /dev/null +++ b/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef PAGE_ALLOCATOR_PRIV_H +#define PAGE_ALLOCATOR_PRIV_H + +#include +#include + +#include "gk20a_allocator.h" + +struct gk20a_allocator; + +struct page_alloc_chunk { + struct list_head list_entry; + + u64 base; + u64 length; +}; + +/* + * Struct to handle internal management of page allocation. It holds a list + * of the chunks of page that make up the overall allocation - much like a + * scatter gather table. + */ +struct gk20a_page_alloc { + struct list_head alloc_chunks; + + int nr_chunks; + u64 length; + + /* + * Only useful for the RB tree - since the alloc will have discontiguous + * pages the base is essentially irrelevant except for the fact that it + * is guarenteed to be unique. + */ + u64 base; + + struct rb_node tree_entry; +}; + +struct gk20a_page_allocator { + struct gk20a_allocator *owner; /* Owner of this allocator. */ + + /* + * Use a buddy allocator to manage the allocation of the underlying + * pages. This lets us abstract the discontiguous allocation handling + * out of the annoyingly complicated buddy allocator. + */ + struct gk20a_allocator source_allocator; + + /* + * Page params. + */ + u64 base; + u64 length; + u64 page_size; + u32 page_shift; + + struct rb_root allocs; /* Outstanding allocations. */ + + u64 flags; + + /* + * Stat tracking. + */ + u64 nr_allocs; + u64 nr_frees; + u64 nr_fixed_allocs; + u64 nr_fixed_frees; + u64 pages_alloced; + u64 pages_freed; +}; + +static inline struct gk20a_page_allocator *page_allocator( + struct gk20a_allocator *a) +{ + return (struct gk20a_page_allocator *)(a)->priv; +} + +static inline struct gk20a_allocator *palloc_owner( + struct gk20a_page_allocator *a) +{ + return a->owner; +} + +#endif -- cgit v1.2.2