base.h 5.86 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2 3 4 5 6
/*
 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
 *	Bjorn Helgaas <bjorn.helgaas@hp.com>
 */

7
extern struct mutex pnp_lock;
8
extern const struct attribute_group *pnp_dev_groups[];
Linus Torvalds's avatar
Linus Torvalds committed
9
void *pnp_alloc(long size);
10 11 12 13

int pnp_register_protocol(struct pnp_protocol *protocol);
void pnp_unregister_protocol(struct pnp_protocol *protocol);

14 15
#define PNP_EISA_ID_MASK 0x7fffffff
void pnp_eisa_id_to_string(u32 id, char *str);
16 17
struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id,
			      const char *pnpid);
18
struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
19 20

int pnp_add_device(struct pnp_dev *dev);
21
struct pnp_id *pnp_add_id(struct pnp_dev *dev, const char *id);
22 23 24 25 26 27

int pnp_add_card(struct pnp_card *card);
void pnp_remove_card(struct pnp_card *card);
int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
void pnp_remove_card_device(struct pnp_dev *dev);

28
struct pnp_port {
29 30 31 32
	resource_size_t min;	/* min base number */
	resource_size_t max;	/* max base number */
	resource_size_t align;	/* align boundary */
	resource_size_t size;	/* size of range */
33 34 35 36
	unsigned char flags;	/* port flags */
};

#define PNP_IRQ_NR 256
37 38
typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t;

39
struct pnp_irq {
40
	pnp_irq_mask_t map;	/* bitmap for IRQ lines */
41 42 43 44 45 46 47 48 49
	unsigned char flags;	/* IRQ flags */
};

struct pnp_dma {
	unsigned char map;	/* bitmask for DMA channels */
	unsigned char flags;	/* DMA flags */
};

struct pnp_mem {
50 51 52 53
	resource_size_t min;	/* min base number */
	resource_size_t max;	/* max base number */
	resource_size_t align;	/* align boundary */
	resource_size_t size;	/* size of range */
54 55 56
	unsigned char flags;	/* memory flags */
};

57 58 59 60 61 62
#define PNP_OPTION_DEPENDENT		0x80000000
#define PNP_OPTION_SET_MASK		0xffff
#define PNP_OPTION_SET_SHIFT		12
#define PNP_OPTION_PRIORITY_MASK	0xfff
#define PNP_OPTION_PRIORITY_SHIFT	0

63 64 65
#define PNP_RES_PRIORITY_PREFERRED	0
#define PNP_RES_PRIORITY_ACCEPTABLE	1
#define PNP_RES_PRIORITY_FUNCTIONAL	2
66
#define PNP_RES_PRIORITY_INVALID	PNP_OPTION_PRIORITY_MASK
67 68

struct pnp_option {
69 70 71 72 73 74 75 76 77 78
	struct list_head list;
	unsigned int flags;	/* independent/dependent, set, priority */

	unsigned long type;	/* IORESOURCE_{IO,MEM,IRQ,DMA} */
	union {
		struct pnp_port port;
		struct pnp_irq irq;
		struct pnp_dma dma;
		struct pnp_mem mem;
	} u;
79 80
};

81
int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags,
82
			      pnp_irq_mask_t *map, unsigned char flags);
83
int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags,
84
			      unsigned char map, unsigned char flags);
85
int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags,
86 87 88
			       resource_size_t min, resource_size_t max,
			       resource_size_t align, resource_size_t size,
			       unsigned char flags);
89
int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags,
90 91 92
			      resource_size_t min, resource_size_t max,
			      resource_size_t align, resource_size_t size,
			      unsigned char flags);
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

static inline int pnp_option_is_dependent(struct pnp_option *option)
{
	return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0;
}

static inline unsigned int pnp_option_set(struct pnp_option *option)
{
	return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK;
}

static inline unsigned int pnp_option_priority(struct pnp_option *option)
{
	return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) &
	    PNP_OPTION_PRIORITY_MASK;
}

static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev,
						 int priority)
{
	unsigned int flags;

	if (priority > PNP_RES_PRIORITY_FUNCTIONAL) {
		dev_warn(&dev->dev, "invalid dependent option priority %d "
			 "clipped to %d", priority,
			 PNP_RES_PRIORITY_INVALID);
		priority = PNP_RES_PRIORITY_INVALID;
	}

	flags = PNP_OPTION_DEPENDENT |
	    ((dev->num_dependent_sets & PNP_OPTION_SET_MASK) <<
		PNP_OPTION_SET_SHIFT) |
	    ((priority & PNP_OPTION_PRIORITY_MASK) <<
		PNP_OPTION_PRIORITY_SHIFT);

	dev->num_dependent_sets++;

	return flags;
}

char *pnp_option_priority_name(struct pnp_option *option);
void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option);

136 137
void pnp_init_resources(struct pnp_dev *dev);

Linus Torvalds's avatar
Linus Torvalds committed
138
void pnp_fixup_device(struct pnp_dev *dev);
139
void pnp_free_options(struct pnp_dev *dev);
Linus Torvalds's avatar
Linus Torvalds committed
140 141 142
int __pnp_add_device(struct pnp_dev *dev);
void __pnp_remove_device(struct pnp_dev *dev);

143 144 145
int pnp_check_port(struct pnp_dev *dev, struct resource *res);
int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
146
#ifdef CONFIG_ISA_DMA_API
147
int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
148
#endif
149

150
char *pnp_resource_type_name(struct resource *res);
151
void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
152

153
void pnp_free_resources(struct pnp_dev *dev);
154
unsigned long pnp_resource_type(struct resource *res);
155

156
struct pnp_resource {
157
	struct list_head list;
158 159 160
	struct resource res;
};

161
void pnp_free_resource(struct pnp_resource *pnp_res);
162

163 164
struct pnp_resource *pnp_add_resource(struct pnp_dev *dev,
				      struct resource *res);
165 166
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
					  int flags);
167 168
struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
					  int flags);
169 170 171
struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
					 resource_size_t start,
					 resource_size_t end, int flags);
172 173 174
struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
					  resource_size_t start,
					  resource_size_t end, int flags);
175 176 177
struct pnp_resource *pnp_add_bus_resource(struct pnp_dev *dev,
					  resource_size_t start,
					  resource_size_t end);
178 179 180 181 182 183 184 185 186 187

extern int pnp_debug;

#if defined(CONFIG_PNP_DEBUG_MESSAGES)
#define pnp_dbg(dev, format, arg...)					\
	({ if (pnp_debug) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
#else
#define pnp_dbg(dev, format, arg...)					\
	({ if (0) dev_printk(KERN_DEBUG, dev, format, ## arg); 0; })
#endif