/* SPDX-License-Identifier: GPL-2.0-only */


#ifndef __MINIDUMP_H
#define __MINIDUMP_H

#include <linux/types.h>
#include <linux/workqueue.h>

enum minidump_entry_cmd {
	MINIDUMP_ADD,
	MINIDUMP_REMOVE,
	MINIDUMP_UPDATE,
	MINIDUMP_NO_CMD
};

#if IS_ENABLED(CONFIG_ARCH_QTI_VM)
#define MAX_NAME_LENGTH		9
#else
#define MAX_NAME_LENGTH		12
#endif


struct md_region {
	char	name[MAX_NAME_LENGTH + 1];
	u32	id;
	u64	virt_addr;
	u64	phys_addr;
	u64	size;
};

struct md_pending_region {
	struct list_head	list;
	struct md_region	entry;
};

struct md_rm_region {
	char	name[MAX_NAME_LENGTH + 1];
	u32	slot_num;
};

struct md_rm_request {
	struct md_region	entry;
	struct work_struct	work;
	enum minidump_entry_cmd	work_cmd;
};


#if IS_ENABLED(CONFIG_QCOM_MINIDUMP)
extern int msm_minidump_add_region(const struct md_region *entry);
extern int msm_minidump_remove_region(const struct md_region *entry);

extern int msm_minidump_update_region(int regno, const struct md_region *entry);
extern bool msm_minidump_enabled(void);
extern struct md_region md_get_region(char *name);
extern void dump_stack_minidump(u64 sp);
extern int msm_minidump_get_available_region(void);
#else
static inline int msm_minidump_add_region(const struct md_region *entry)
{
	
	return 0;
}
static inline int msm_minidump_remove_region(const struct md_region *entry)
{
	return 0;
}
static inline bool msm_minidump_enabled(void) { return false; }
static inline struct md_region md_get_region(char *name)
{
	struct md_region mdr = {0};
	return mdr;
}
static inline void dump_stack_minidump(u64 sp) {}
static inline void add_trace_event(char *buf, size_t size) {}
#endif

#if IS_ENABLED(CONFIG_QCOM_MINIDUMP_PANIC_DUMP)
extern void md_dump_process(void);
#else
static inline void md_dump_process(void) {}
#endif


#define MAX_OWNER_STRING	32
struct va_md_entry {
	unsigned long vaddr;
	unsigned char owner[MAX_OWNER_STRING];
	unsigned int size;
	void (*cb)(void *dst, unsigned long size);
};

#if IS_ENABLED(CONFIG_QCOM_VA_MINIDUMP)
extern bool qcom_va_md_enabled(void);
extern int qcom_va_md_register(const char *name, struct notifier_block *nb);
extern int qcom_va_md_unregister(const char *name, struct notifier_block *nb);
extern int qcom_va_md_add_region(struct va_md_entry *entry);
#else
static inline bool qcom_va_md_enabled(void) { return false; }
static inline int qcom_va_md_register(const char *name, struct notifier_block *nb)
{
	return -ENODEV;
}

static inline int qcom_va_md_unregister(const char *name, struct notifier_block *nb)
{
	return -ENODEV;
}

static inline int qcom_va_md_add_region(struct va_md_entry *entry)
{
	return -ENODEV;
}
#endif

#endif
