linux/include/linux/ioport.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * ioport.h	Definitions of routines for detecting, reserving and
 *		allocating system resources.
 *
 * Authors:	Linus Torvalds
 */

#ifndef _LINUX_IOPORT_H
#define _LINUX_IOPORT_H

#ifndef __ASSEMBLY__
#include <linux/bits.h>
#include <linux/compiler.h>
#include <linux/minmax.h>
#include <linux/types.h>
/*
 * Resources are tree-like, allowing
 * nesting etc..
 */
struct resource {};

/*
 * IO resources have these defined flags.
 *
 * PCI devices expose these flags to userspace in the "resource" sysfs file,
 * so don't move them.
 */
#define IORESOURCE_BITS

#define IORESOURCE_TYPE_BITS
#define IORESOURCE_IO
#define IORESOURCE_MEM
#define IORESOURCE_REG
#define IORESOURCE_IRQ
#define IORESOURCE_DMA
#define IORESOURCE_BUS

#define IORESOURCE_PREFETCH
#define IORESOURCE_READONLY
#define IORESOURCE_CACHEABLE
#define IORESOURCE_RANGELENGTH
#define IORESOURCE_SHADOWABLE

#define IORESOURCE_SIZEALIGN
#define IORESOURCE_STARTALIGN

#define IORESOURCE_MEM_64
#define IORESOURCE_WINDOW
#define IORESOURCE_MUXED

#define IORESOURCE_EXT_TYPE_BITS
#define IORESOURCE_SYSRAM

/* IORESOURCE_SYSRAM specific bits. */
#define IORESOURCE_SYSRAM_DRIVER_MANAGED
#define IORESOURCE_SYSRAM_MERGEABLE

#define IORESOURCE_EXCLUSIVE

#define IORESOURCE_DISABLED
#define IORESOURCE_UNSET
#define IORESOURCE_AUTO
#define IORESOURCE_BUSY

/* I/O resource extended types */
#define IORESOURCE_SYSTEM_RAM

/* PnP IRQ specific bits (IORESOURCE_BITS) */
#define IORESOURCE_IRQ_HIGHEDGE
#define IORESOURCE_IRQ_LOWEDGE
#define IORESOURCE_IRQ_HIGHLEVEL
#define IORESOURCE_IRQ_LOWLEVEL
#define IORESOURCE_IRQ_SHAREABLE
#define IORESOURCE_IRQ_OPTIONAL
#define IORESOURCE_IRQ_WAKECAPABLE

/* PnP DMA specific bits (IORESOURCE_BITS) */
#define IORESOURCE_DMA_TYPE_MASK
#define IORESOURCE_DMA_8BIT
#define IORESOURCE_DMA_8AND16BIT
#define IORESOURCE_DMA_16BIT

#define IORESOURCE_DMA_MASTER
#define IORESOURCE_DMA_BYTE
#define IORESOURCE_DMA_WORD

#define IORESOURCE_DMA_SPEED_MASK
#define IORESOURCE_DMA_COMPATIBLE
#define IORESOURCE_DMA_TYPEA
#define IORESOURCE_DMA_TYPEB
#define IORESOURCE_DMA_TYPEF

/* PnP memory I/O specific bits (IORESOURCE_BITS) */
#define IORESOURCE_MEM_WRITEABLE
#define IORESOURCE_MEM_CACHEABLE
#define IORESOURCE_MEM_RANGELENGTH
#define IORESOURCE_MEM_TYPE_MASK
#define IORESOURCE_MEM_8BIT
#define IORESOURCE_MEM_16BIT
#define IORESOURCE_MEM_8AND16BIT
#define IORESOURCE_MEM_32BIT
#define IORESOURCE_MEM_SHADOWABLE
#define IORESOURCE_MEM_EXPANSIONROM
#define IORESOURCE_MEM_NONPOSTED

/* PnP I/O specific bits (IORESOURCE_BITS) */
#define IORESOURCE_IO_16BIT_ADDR
#define IORESOURCE_IO_FIXED
#define IORESOURCE_IO_SPARSE

/* PCI ROM control bits (IORESOURCE_BITS) */
#define IORESOURCE_ROM_ENABLE
#define IORESOURCE_ROM_SHADOW

/* PCI control bits.  Shares IORESOURCE_BITS with above PCI ROM.  */
#define IORESOURCE_PCI_FIXED
#define IORESOURCE_PCI_EA_BEI

/*
 * I/O Resource Descriptors
 *
 * Descriptors are used by walk_iomem_res_desc() and region_intersects()
 * for searching a specific resource range in the iomem table.  Assign
 * a new descriptor when a resource range supports the search interfaces.
 * Otherwise, resource.desc must be set to IORES_DESC_NONE (0).
 */
enum {};

/*
 * Flags controlling ioremap() behavior.
 */
enum {};

/* helpers to define resources */
#define DEFINE_RES_NAMED(_start, _size, _name, _flags)

#define DEFINE_RES_IO_NAMED(_start, _size, _name)
#define DEFINE_RES_IO(_start, _size)

#define DEFINE_RES_MEM_NAMED(_start, _size, _name)
#define DEFINE_RES_MEM(_start, _size)

#define DEFINE_RES_REG_NAMED(_start, _size, _name)
#define DEFINE_RES_REG(_start, _size)

#define DEFINE_RES_IRQ_NAMED(_irq, _name)
#define DEFINE_RES_IRQ(_irq)

#define DEFINE_RES_DMA_NAMED(_dma, _name)
#define DEFINE_RES_DMA(_dma)

/**
 * typedef resource_alignf - Resource alignment callback
 * @data:	Private data used by the callback
 * @res:	Resource candidate range (an empty resource space)
 * @size:	The minimum size of the empty space
 * @align:	Alignment from the constraints
 *
 * Callback allows calculating resource placement and alignment beyond min,
 * max, and align fields in the struct resource_constraint.
 *
 * Return: Start address for the resource.
 */
resource_alignf;

/**
 * struct resource_constraint - constraints to be met while searching empty
 *				resource space
 * @min:		The minimum address for the memory range
 * @max:		The maximum address for the memory range
 * @align:		Alignment for the start address of the empty space
 * @alignf:		Additional alignment constraints callback
 * @alignf_data:	Data provided for @alignf callback
 *
 * Contains the range and alignment constraints that have to be met during
 * find_resource_space(). @alignf can be NULL indicating no alignment beyond
 * @align is necessary.
 */
struct resource_constraint {};

/* PC/ISA/whatever - the normal PC address spaces: IO and memory */
extern struct resource ioport_resource;
extern struct resource iomem_resource;

extern struct resource *request_resource_conflict(struct resource *root, struct resource *new);
extern int request_resource(struct resource *root, struct resource *new);
extern int release_resource(struct resource *new);
void release_child_resources(struct resource *new);
extern void reserve_region_with_split(struct resource *root,
			     resource_size_t start, resource_size_t end,
			     const char *name);
extern struct resource *insert_resource_conflict(struct resource *parent, struct resource *new);
extern int insert_resource(struct resource *parent, struct resource *new);
extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new);
extern int remove_resource(struct resource *old);
extern void arch_remove_reservations(struct resource *avail);
extern int allocate_resource(struct resource *root, struct resource *new,
			     resource_size_t size, resource_size_t min,
			     resource_size_t max, resource_size_t align,
			     resource_alignf alignf,
			     void *alignf_data);
struct resource *lookup_resource(struct resource *root, resource_size_t start);
int adjust_resource(struct resource *res, resource_size_t start,
		    resource_size_t size);
resource_size_t resource_alignment(struct resource *res);
static inline resource_size_t resource_size(const struct resource *res)
{}
static inline unsigned long resource_type(const struct resource *res)
{}
static inline unsigned long resource_ext_type(const struct resource *res)
{}
/* True iff r1 completely contains r2 */
static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
{}

/* True if any part of r1 overlaps r2 */
static inline bool resource_overlaps(const struct resource *r1, const struct resource *r2)
{}

static inline bool resource_intersection(const struct resource *r1, const struct resource *r2,
					 struct resource *r)
{}

static inline bool resource_union(const struct resource *r1, const struct resource *r2,
				  struct resource *r)
{}

int find_resource_space(struct resource *root, struct resource *new,
			resource_size_t size, struct resource_constraint *constraint);

/* Convenience shorthand with allocation */
#define request_region(start,n,name)
#define request_muxed_region(start,n,name)
#define __request_mem_region(start,n,name, excl)
#define request_mem_region(start,n,name)
#define request_mem_region_muxed(start, n, name)
#define request_mem_region_exclusive(start,n,name)
#define rename_region(region, newname)

extern struct resource * __request_region(struct resource *,
					resource_size_t start,
					resource_size_t n,
					const char *name, int flags);

/* Compatibility cruft */
#define release_region(start,n)
#define release_mem_region(start,n)

extern void __release_region(struct resource *, resource_size_t,
				resource_size_t);
#ifdef CONFIG_MEMORY_HOTREMOVE
extern void release_mem_region_adjustable(resource_size_t, resource_size_t);
#endif
#ifdef CONFIG_MEMORY_HOTPLUG
extern void merge_system_ram_resource(struct resource *res);
#endif

/* Wrappers for managed devices */
struct device;

extern int devm_request_resource(struct device *dev, struct resource *root,
				 struct resource *new);
extern void devm_release_resource(struct device *dev, struct resource *new);

#define devm_request_region(dev,start,n,name)
#define devm_request_mem_region(dev,start,n,name)

extern struct resource * __devm_request_region(struct device *dev,
				struct resource *parent, resource_size_t start,
				resource_size_t n, const char *name);

#define devm_release_region(dev, start, n)
#define devm_release_mem_region(dev, start, n)

extern void __devm_release_region(struct device *dev, struct resource *parent,
				  resource_size_t start, resource_size_t n);
extern int iomem_map_sanity_check(resource_size_t addr, unsigned long size);
extern bool iomem_is_exclusive(u64 addr);
extern bool resource_is_exclusive(struct resource *resource, u64 addr,
				  resource_size_t size);

extern int
walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
		void *arg, int (*func)(unsigned long, unsigned long, void *));
extern int
walk_mem_res(u64 start, u64 end, void *arg,
	     int (*func)(struct resource *, void *));
extern int
walk_system_ram_res(u64 start, u64 end, void *arg,
		    int (*func)(struct resource *, void *));
extern int
walk_system_ram_res_rev(u64 start, u64 end, void *arg,
			int (*func)(struct resource *, void *));
extern int
walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end,
		    void *arg, int (*func)(struct resource *, void *));

struct resource *devm_request_free_mem_region(struct device *dev,
		struct resource *base, unsigned long size);
struct resource *request_free_mem_region(struct resource *base,
		unsigned long size, const char *name);
struct resource *alloc_free_mem_region(struct resource *base,
		unsigned long size, unsigned long align, const char *name);

static inline void irqresource_disabled(struct resource *res, u32 irq)
{}

extern struct address_space *iomem_get_mapping(void);

#endif /* __ASSEMBLY__ */
#endif	/* _LINUX_IOPORT_H */