From 8254994b586dfac49c5ee6f209daeb72ec55a3ba Mon Sep 17 00:00:00 2001 From: Jason Montleon Date: Fri, 27 Dec 2024 11:13:30 -0500 Subject: [PATCH 220/222] stop triggering vmlinux rebuild --- drivers/memory/eswin/Makefile | 4 - drivers/memory/eswin/es_dev_buf/Makefile | 4 - include/linux/buddy.h | 217 +++++++++++++++++++++++ include/linux/dsp_dma_buf.h | 44 +++++ include/linux/eswin_memblock.h | 18 ++ 5 files changed, 279 insertions(+), 8 deletions(-) create mode 100644 include/linux/buddy.h create mode 100644 include/linux/dsp_dma_buf.h create mode 100644 include/linux/eswin_memblock.h diff --git a/drivers/memory/eswin/Makefile b/drivers/memory/eswin/Makefile index e6e57575ccb8..479d12548b55 100644 --- a/drivers/memory/eswin/Makefile +++ b/drivers/memory/eswin/Makefile @@ -9,7 +9,3 @@ obj-$(CONFIG_ESWIN_RSVMEM_HEAP) += es_mmz_vb/ obj-$(CONFIG_ESWIN_DEV_DMA_BUF) += es_dev_buf/ obj-$(CONFIG_ESWIN_IOMMU_RSV) += es_iommu_rsv/ obj-$(CONFIG_ESWIN_DMA_MEMCP) += es_dma_memcp/ - -ES_MEM_HEADER := drivers/memory/eswin/ - -COPY_HEADERS := $(shell cp $(ES_MEM_HEADER)/*.h include/linux) diff --git a/drivers/memory/eswin/es_dev_buf/Makefile b/drivers/memory/eswin/es_dev_buf/Makefile index 3ba183ff62bd..391af838aada 100644 --- a/drivers/memory/eswin/es_dev_buf/Makefile +++ b/drivers/memory/eswin/es_dev_buf/Makefile @@ -1,5 +1 @@ obj-$(CONFIG_ESWIN_DEV_DMA_BUF) += es_dev_buf.o - -ES_DEV_DMA_BUF_HEADER := drivers/memory/eswin/es_dev_buf/include/linux -COPY_HEADERS:=$(shell cp $(ES_DEV_DMA_BUF_HEADER)/*.h include/linux) - diff --git a/include/linux/buddy.h b/include/linux/buddy.h new file mode 100644 index 000000000000..ff47325f2d27 --- /dev/null +++ b/include/linux/buddy.h @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Header file of ESWIN internal buddy allocator + * + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd. + * Authors: + * LinMin + * + */ + +#ifndef __BUDDY_H__ +#define __BUDDY_H__ + +#define RUN_IN_KERNEL 1 + +#ifdef RUN_IN_KERNEL +#include +#include +#include +#include +#include +#include + +// #define buddy_print(fmt...) printk(fmt) +#define buddy_print(fmt...) +#define BUDDY_BUG_ON(condition) WARN_ON(condition) + +#define es_spin_lock_init(esLock) spin_lock_init(esLock) +#define es_spin_lock(esLock) spin_lock(esLock) +#define es_spin_unlock(esLock) spin_unlock(esLock) +#define buddy_spin_lock_init(lock) +#define buddy_spin_lock(lock) +#define buddy_spin_unlock(lock) +#else +#include "list.h" +#include //printf +#include //memset +#include //assert + +#define buddy_print(fmt...) printf(fmt) +#define BUDDY_BUG_ON(condition) assert(condition) + +#define buddy_spin_lock_init(lock) do {}while(0) +#define buddy_spin_lock(lock) do {}while(0) +#define buddy_spin_unlock(lock) do {}while(0) + +#define es_spin_lock_init(esLock) +#define es_spin_lock(esLock) +#define es_spin_unlock(esLock) +#endif + +enum esPageflags_e{ + enPG_head, + enPG_tail, + enPG_buddy, +}; + +#define BUDDY_PAGE_SHIFT PAGE_SHIFT//(12UL) +#define BUDDY_PAGE_SIZE (1UL << BUDDY_PAGE_SHIFT) +#define BUDDY_MAX_ORDER MAX_ORDER // (10UL)//(9UL) + +struct esPage_s +{ + // spin_lock lock; + struct list_head lru; + unsigned long flags; + union { + unsigned long order; + struct esPage_s *first_page; + }; +}; + +struct es_free_area_s +{ + struct list_head free_list; + unsigned long nr_free; +}; + +struct mem_zone +{ +#ifdef RUN_IN_KERNEL + spinlock_t lock; +#endif + unsigned long page_num; + unsigned long page_size; + struct esPage_s *first_page; + unsigned long start_addr; + unsigned long end_addr; + struct es_free_area_s free_area[BUDDY_MAX_ORDER]; +}; + +#ifdef RUN_IN_KERNEL +#define BLOCK_MAX_NAME 64 +struct mem_block { +#ifdef RUN_IN_KERNEL + spinlock_t esLock; +#endif + struct mem_zone zone; + unsigned long page_num; + struct esPage_s *esPagesStart; + struct page *kPageStart; + char name[BLOCK_MAX_NAME]; +}; +#else +struct mem_block { + struct mem_zone zone; + struct esPage_s *pages; +}; +#endif + +void buddy_system_init(struct mem_block *memblock, + struct esPage_s *start_page, + unsigned long start_addr, + unsigned long page_num); +struct esPage_s *buddy_get_pages(struct mem_zone *zone, + unsigned long order); +void buddy_free_pages(struct mem_zone *zone, + struct esPage_s *page); +unsigned long buddy_num_free_page(struct mem_zone *zone); + + +static inline void __esSetPageHead(struct esPage_s *page) +{ + page->flags |= (1UL<flags |= (1UL<flags |= (1UL<flags &= ~(1UL<flags &= ~(1UL<flags &= ~(1UL<flags & (1UL<flags & (1UL<flags & (1UL<order = order; + __esSetPageBuddy(page); +} + +static inline void rmv_page_order_buddy(struct esPage_s *page) +{ + page->order = 0; + __esClearPageBuddy(page); +} + + +static inline unsigned long +__find_buddy_index(unsigned long page_idx, unsigned int order) +{ + return (page_idx ^ (1 << order)); +} + +static inline unsigned long +__find_combined_index(unsigned long page_idx, unsigned int order) +{ + return (page_idx & ~(1 << order)); +} + + +static inline unsigned long esCompound_order(struct esPage_s *page) +{ + if (!esPageHead(page)) + return 0; + + return page->order; +} + +static inline void esSet_compound_order(struct esPage_s *page, unsigned long order) +{ + page->order = order; +} + +static inline void BUDDY_BUG(const char *f, int line) +{ + buddy_print("BUDDY_BUG in %s, %d.\n", f, line); + BUDDY_BUG_ON(1); +} + +// print buddy system status +void dump_print(struct mem_zone *zone); +void dump_print_dot(struct mem_zone *zone); + +#endif diff --git a/include/linux/dsp_dma_buf.h b/include/linux/dsp_dma_buf.h new file mode 100644 index 000000000000..ab6962ad1ccf --- /dev/null +++ b/include/linux/dsp_dma_buf.h @@ -0,0 +1,44 @@ +// Copyright © 2023 ESWIN. All rights reserved. +// +// Beijing ESWIN Computing Technology Co., Ltd and its affiliated companies ("ESWIN") retain +// all intellectual property and proprietary rights in and to this software. Except as expressly +// authorized by ESWIN, no part of the software may be released, copied, distributed, reproduced, +// modified, adapted, translated, or created derivative work of, in whole or in part. + +#ifndef __DSP_DMA_BUF_H_ +#define __DSP_DMA_BUF_H_ +#include + +struct dev_buffer_desc { + struct dma_buf *buf; + u32 offset; + u32 len; +}; + +enum es_malloc_policy { + ES_MEM_ALLOC_RSV, + ES_MEM_ALLOC_NORMAL, + ES_MEM_ALLOC_NORMAL_COHERENT, + ES_MEM_ALLOC_CMA, + ES_MEM_ALLOC_CMA_COHERENT, + ES_MEM_ALLOC_CMA_LLC, + ES_MEM_ALLOC_SPRAM_DIE0, + ES_MEM_ALLOC_SPRAM_DIE1, +}; + +int dev_mem_alloc(size_t size, enum es_malloc_policy policy, + struct dma_buf **buf); +int dev_mem_free(struct dma_buf *buf); + +int dev_mem_alloc_pool(size_t size, enum es_malloc_policy policy, char *mmb, + char *zone, struct dma_buf **buf); + +dma_addr_t dev_mem_attach(struct dma_buf *buf, struct device *dev, + enum dma_data_direction direc, + struct dma_buf_attachment **attachment); +int dev_mem_detach(struct dma_buf_attachment *attach, + enum dma_data_direction direction); +void *dev_mem_vmap(struct dev_buffer_desc *dev_buffer); +void dev_mem_vunmap(struct dev_buffer_desc *dev_buf, void *vaddr); + +#endif diff --git a/include/linux/eswin_memblock.h b/include/linux/eswin_memblock.h new file mode 100644 index 000000000000..6c18444599de --- /dev/null +++ b/include/linux/eswin_memblock.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ESWIN_RSVMEM_H__ +#define __ESWIN_RSVMEM_H__ + +#include +#include +#include +#include "buddy.h" + +// #define QEMU_DEBUG 1 + +#define MAX_ESWIN_RSVMEM_AREAS (64) + +struct mem_block *eswin_rsvmem_get_memblock(const char *memBlkName); +int eswin_rsvmem_for_each_block(int (*it)(struct mem_block *rsvmem_block, void *data), void *data); +const char *eswin_rsvmem_get_name(const struct mem_block *memblock); + +#endif -- 2.47.0