From 0d90b21da7cc94bf5efbd7ca6601d285624875e8 Mon Sep 17 00:00:00 2001 From: Jason Montleon Date: Wed, 12 Feb 2025 09:03:43 -0500 Subject: [PATCH 410/416] stop triggering vmlinux rebuild --- drivers/memory/eswin/Makefile | 4 - drivers/memory/eswin/es_dev_buf/Makefile | 4 - drivers/memory/eswin/es_proc/Makefile | 4 - include/linux/buddy.h | 217 +++++++++++++++++++++++ include/linux/dsp_dma_buf.h | 44 +++++ include/linux/es_proc.h | 40 +++++ include/linux/eswin_memblock.h | 18 ++ 7 files changed, 319 insertions(+), 12 deletions(-) create mode 100644 include/linux/buddy.h create mode 100644 include/linux/dsp_dma_buf.h create mode 100644 include/linux/es_proc.h create mode 100644 include/linux/eswin_memblock.h diff --git a/drivers/memory/eswin/Makefile b/drivers/memory/eswin/Makefile index 1d33ac236716..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 := $(srctree)/drivers/memory/eswin/ - -COPY_HEADERS := $(shell mkdir -p include/linux && 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 854348e41f91..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 := $(srctree)/drivers/memory/eswin/es_dev_buf/include/linux -COPY_HEADERS:=$(shell mkdir -p include/linux && cp $(ES_DEV_DMA_BUF_HEADER)/*.h include/linux) - diff --git a/drivers/memory/eswin/es_proc/Makefile b/drivers/memory/eswin/es_proc/Makefile index 9dc204e89fb8..09e2bc7767a3 100644 --- a/drivers/memory/eswin/es_proc/Makefile +++ b/drivers/memory/eswin/es_proc/Makefile @@ -1,7 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_ESWIN_PROC) += es_proc.o ccflags-y := -DDEBUG - -ES_PROC_HEADER := $(srctree)/drivers/memory/eswin/es_proc/include/linux - -COPY_HEADERS := $(shell mkdir -p include/linux && cp $(ES_PROC_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/es_proc.h b/include/linux/es_proc.h new file mode 100644 index 000000000000..65c73460e11b --- /dev/null +++ b/include/linux/es_proc.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Header file of es_proc.c + * + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd. + * Authors: + * HuangYiFeng + * + */ + +#ifndef __ES_PROC__ +#define __ES_PROC__ + +#define PROC_ENTRY_VI "vi" +#define PROC_ENTRY_VO "vo" +#define PROC_ENTRY_VB "vb" +#define PROC_ENTRY_ISP "isp" + +// proc +typedef struct es_proc_dir_entry { + char name[50]; + void *proc_dir_entry; + int (*open)(struct es_proc_dir_entry *entry); + int (*read)(struct es_proc_dir_entry *entry); + int (*write)(struct es_proc_dir_entry *entry, const char *buf, + int count, long long *); + void *private; + void *seqfile; + struct list_head node; +} es_proc_entry_t; + +extern es_proc_entry_t *es_create_proc_entry(const char *name, + es_proc_entry_t *parent); +extern es_proc_entry_t *es_proc_mkdir(const char *name, + es_proc_entry_t *parent); +extern void es_remove_proc_entry(const char *name, es_proc_entry_t *parent); +extern int es_seq_printf(es_proc_entry_t *entry, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); + +#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.48.1