18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright IBM Corp. 2006, 2019
48c2ecf20Sopenharmony_ci * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
58c2ecf20Sopenharmony_ci *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
68c2ecf20Sopenharmony_ci *	      Ralph Wuerthner <rwuerthn@de.ibm.com>
78c2ecf20Sopenharmony_ci *	      Felix Beck <felix.beck@de.ibm.com>
88c2ecf20Sopenharmony_ci *	      Holger Dengler <hd@linux.vnet.ibm.com>
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Adjunct processor bus header file.
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifndef _AP_BUS_H_
148c2ecf20Sopenharmony_ci#define _AP_BUS_H_
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/device.h>
178c2ecf20Sopenharmony_ci#include <linux/types.h>
188c2ecf20Sopenharmony_ci#include <linux/hashtable.h>
198c2ecf20Sopenharmony_ci#include <asm/isc.h>
208c2ecf20Sopenharmony_ci#include <asm/ap.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define AP_DEVICES 256		/* Number of AP devices. */
238c2ecf20Sopenharmony_ci#define AP_DOMAINS 256		/* Number of AP domains. */
248c2ecf20Sopenharmony_ci#define AP_IOCTLS  256		/* Number of ioctls. */
258c2ecf20Sopenharmony_ci#define AP_RESET_TIMEOUT (HZ*0.7)	/* Time in ticks for reset timeouts. */
268c2ecf20Sopenharmony_ci#define AP_CONFIG_TIME 30	/* Time in seconds between AP bus rescans. */
278c2ecf20Sopenharmony_ci#define AP_POLL_TIME 1		/* Time in ticks between receive polls. */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciextern int ap_domain_index;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciextern DECLARE_HASHTABLE(ap_queues, 8);
328c2ecf20Sopenharmony_ciextern spinlock_t ap_queues_lock;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic inline int ap_test_bit(unsigned int *ptr, unsigned int nr)
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	return (*ptr & (0x80000000u >> nr)) != 0;
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define AP_RESPONSE_NORMAL		0x00
408c2ecf20Sopenharmony_ci#define AP_RESPONSE_Q_NOT_AVAIL		0x01
418c2ecf20Sopenharmony_ci#define AP_RESPONSE_RESET_IN_PROGRESS	0x02
428c2ecf20Sopenharmony_ci#define AP_RESPONSE_DECONFIGURED	0x03
438c2ecf20Sopenharmony_ci#define AP_RESPONSE_CHECKSTOPPED	0x04
448c2ecf20Sopenharmony_ci#define AP_RESPONSE_BUSY		0x05
458c2ecf20Sopenharmony_ci#define AP_RESPONSE_INVALID_ADDRESS	0x06
468c2ecf20Sopenharmony_ci#define AP_RESPONSE_OTHERWISE_CHANGED	0x07
478c2ecf20Sopenharmony_ci#define AP_RESPONSE_Q_FULL		0x10
488c2ecf20Sopenharmony_ci#define AP_RESPONSE_NO_PENDING_REPLY	0x10
498c2ecf20Sopenharmony_ci#define AP_RESPONSE_INDEX_TOO_BIG	0x11
508c2ecf20Sopenharmony_ci#define AP_RESPONSE_NO_FIRST_PART	0x13
518c2ecf20Sopenharmony_ci#define AP_RESPONSE_MESSAGE_TOO_BIG	0x15
528c2ecf20Sopenharmony_ci#define AP_RESPONSE_REQ_FAC_NOT_INST	0x16
538c2ecf20Sopenharmony_ci#define AP_RESPONSE_INVALID_DOMAIN	0x42
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/*
568c2ecf20Sopenharmony_ci * Known device types
578c2ecf20Sopenharmony_ci */
588c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_PCICC	3
598c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_PCICA	4
608c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_PCIXCC	5
618c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_CEX2A	6
628c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_CEX2C	7
638c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_CEX3A	8
648c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_CEX3C	9
658c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_CEX4	10
668c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_CEX5	11
678c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_CEX6	12
688c2ecf20Sopenharmony_ci#define AP_DEVICE_TYPE_CEX7	13
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/*
718c2ecf20Sopenharmony_ci * Known function facilities
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_ci#define AP_FUNC_MEX4K 1
748c2ecf20Sopenharmony_ci#define AP_FUNC_CRT4K 2
758c2ecf20Sopenharmony_ci#define AP_FUNC_COPRO 3
768c2ecf20Sopenharmony_ci#define AP_FUNC_ACCEL 4
778c2ecf20Sopenharmony_ci#define AP_FUNC_EP11  5
788c2ecf20Sopenharmony_ci#define AP_FUNC_APXA  6
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/*
818c2ecf20Sopenharmony_ci * AP queue state machine states
828c2ecf20Sopenharmony_ci */
838c2ecf20Sopenharmony_cienum ap_sm_state {
848c2ecf20Sopenharmony_ci	AP_SM_STATE_RESET_START = 0,
858c2ecf20Sopenharmony_ci	AP_SM_STATE_RESET_WAIT,
868c2ecf20Sopenharmony_ci	AP_SM_STATE_SETIRQ_WAIT,
878c2ecf20Sopenharmony_ci	AP_SM_STATE_IDLE,
888c2ecf20Sopenharmony_ci	AP_SM_STATE_WORKING,
898c2ecf20Sopenharmony_ci	AP_SM_STATE_QUEUE_FULL,
908c2ecf20Sopenharmony_ci	NR_AP_SM_STATES
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/*
948c2ecf20Sopenharmony_ci * AP queue state machine events
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_cienum ap_sm_event {
978c2ecf20Sopenharmony_ci	AP_SM_EVENT_POLL,
988c2ecf20Sopenharmony_ci	AP_SM_EVENT_TIMEOUT,
998c2ecf20Sopenharmony_ci	NR_AP_SM_EVENTS
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/*
1038c2ecf20Sopenharmony_ci * AP queue state wait behaviour
1048c2ecf20Sopenharmony_ci */
1058c2ecf20Sopenharmony_cienum ap_sm_wait {
1068c2ecf20Sopenharmony_ci	AP_SM_WAIT_AGAIN = 0,	/* retry immediately */
1078c2ecf20Sopenharmony_ci	AP_SM_WAIT_TIMEOUT,	/* wait for timeout */
1088c2ecf20Sopenharmony_ci	AP_SM_WAIT_INTERRUPT,	/* wait for thin interrupt (if available) */
1098c2ecf20Sopenharmony_ci	AP_SM_WAIT_NONE,	/* no wait */
1108c2ecf20Sopenharmony_ci	NR_AP_SM_WAIT
1118c2ecf20Sopenharmony_ci};
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/*
1148c2ecf20Sopenharmony_ci * AP queue device states
1158c2ecf20Sopenharmony_ci */
1168c2ecf20Sopenharmony_cienum ap_dev_state {
1178c2ecf20Sopenharmony_ci	AP_DEV_STATE_UNINITIATED = 0,	/* fresh and virgin, not touched */
1188c2ecf20Sopenharmony_ci	AP_DEV_STATE_OPERATING,		/* queue dev is working normal */
1198c2ecf20Sopenharmony_ci	AP_DEV_STATE_SHUTDOWN,		/* remove/unbind/shutdown in progress */
1208c2ecf20Sopenharmony_ci	AP_DEV_STATE_ERROR,		/* device is in error state */
1218c2ecf20Sopenharmony_ci	NR_AP_DEV_STATES
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistruct ap_device;
1258c2ecf20Sopenharmony_cistruct ap_message;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/*
1288c2ecf20Sopenharmony_ci * The ap driver struct includes a flags field which holds some info for
1298c2ecf20Sopenharmony_ci * the ap bus about the driver. Currently only one flag is supported and
1308c2ecf20Sopenharmony_ci * used: The DEFAULT flag marks an ap driver as a default driver which is
1318c2ecf20Sopenharmony_ci * used together with the apmask and aqmask whitelisting of the ap bus.
1328c2ecf20Sopenharmony_ci */
1338c2ecf20Sopenharmony_ci#define AP_DRIVER_FLAG_DEFAULT 0x0001
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_cistruct ap_driver {
1368c2ecf20Sopenharmony_ci	struct device_driver driver;
1378c2ecf20Sopenharmony_ci	struct ap_device_id *ids;
1388c2ecf20Sopenharmony_ci	unsigned int flags;
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	int (*probe)(struct ap_device *);
1418c2ecf20Sopenharmony_ci	void (*remove)(struct ap_device *);
1428c2ecf20Sopenharmony_ci};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define to_ap_drv(x) container_of((x), struct ap_driver, driver)
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciint ap_driver_register(struct ap_driver *, struct module *, char *);
1478c2ecf20Sopenharmony_civoid ap_driver_unregister(struct ap_driver *);
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistruct ap_device {
1508c2ecf20Sopenharmony_ci	struct device device;
1518c2ecf20Sopenharmony_ci	struct ap_driver *drv;		/* Pointer to AP device driver. */
1528c2ecf20Sopenharmony_ci	int device_type;		/* AP device type. */
1538c2ecf20Sopenharmony_ci};
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define to_ap_dev(x) container_of((x), struct ap_device, device)
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistruct ap_card {
1588c2ecf20Sopenharmony_ci	struct ap_device ap_dev;
1598c2ecf20Sopenharmony_ci	void *private;			/* ap driver private pointer. */
1608c2ecf20Sopenharmony_ci	int raw_hwtype;			/* AP raw hardware type. */
1618c2ecf20Sopenharmony_ci	unsigned int functions;		/* AP device function bitfield. */
1628c2ecf20Sopenharmony_ci	int queue_depth;		/* AP queue depth.*/
1638c2ecf20Sopenharmony_ci	int id;				/* AP card number. */
1648c2ecf20Sopenharmony_ci	bool config;			/* configured state */
1658c2ecf20Sopenharmony_ci	atomic64_t total_request_count;	/* # requests ever for this AP device.*/
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci#define to_ap_card(x) container_of((x), struct ap_card, ap_dev.device)
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistruct ap_queue {
1718c2ecf20Sopenharmony_ci	struct ap_device ap_dev;
1728c2ecf20Sopenharmony_ci	struct hlist_node hnode;	/* Node for the ap_queues hashtable */
1738c2ecf20Sopenharmony_ci	struct ap_card *card;		/* Ptr to assoc. AP card. */
1748c2ecf20Sopenharmony_ci	spinlock_t lock;		/* Per device lock. */
1758c2ecf20Sopenharmony_ci	void *private;			/* ap driver private pointer. */
1768c2ecf20Sopenharmony_ci	enum ap_dev_state dev_state;	/* queue device state */
1778c2ecf20Sopenharmony_ci	bool config;			/* configured state */
1788c2ecf20Sopenharmony_ci	ap_qid_t qid;			/* AP queue id. */
1798c2ecf20Sopenharmony_ci	bool interrupt;			/* indicate if interrupts are enabled */
1808c2ecf20Sopenharmony_ci	int queue_count;		/* # messages currently on AP queue. */
1818c2ecf20Sopenharmony_ci	int pendingq_count;		/* # requests on pendingq list. */
1828c2ecf20Sopenharmony_ci	int requestq_count;		/* # requests on requestq list. */
1838c2ecf20Sopenharmony_ci	u64 total_request_count;	/* # requests ever for this AP device.*/
1848c2ecf20Sopenharmony_ci	int request_timeout;		/* Request timeout in jiffies. */
1858c2ecf20Sopenharmony_ci	struct timer_list timeout;	/* Timer for request timeouts. */
1868c2ecf20Sopenharmony_ci	struct list_head pendingq;	/* List of message sent to AP queue. */
1878c2ecf20Sopenharmony_ci	struct list_head requestq;	/* List of message yet to be sent. */
1888c2ecf20Sopenharmony_ci	struct ap_message *reply;	/* Per device reply message. */
1898c2ecf20Sopenharmony_ci	enum ap_sm_state sm_state;	/* ap queue state machine state */
1908c2ecf20Sopenharmony_ci	int last_err_rc;		/* last error state response code */
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#define to_ap_queue(x) container_of((x), struct ap_queue, ap_dev.device)
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_citypedef enum ap_sm_wait (ap_func_t)(struct ap_queue *queue);
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci/* failure injection cmd struct */
1988c2ecf20Sopenharmony_cistruct ap_fi {
1998c2ecf20Sopenharmony_ci	union {
2008c2ecf20Sopenharmony_ci		u16 cmd;		/* fi flags + action */
2018c2ecf20Sopenharmony_ci		struct {
2028c2ecf20Sopenharmony_ci			u8 flags;	/* fi flags only */
2038c2ecf20Sopenharmony_ci			u8 action;	/* fi action only */
2048c2ecf20Sopenharmony_ci		};
2058c2ecf20Sopenharmony_ci	};
2068c2ecf20Sopenharmony_ci};
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/* all currently known fi actions */
2098c2ecf20Sopenharmony_cienum ap_fi_actions {
2108c2ecf20Sopenharmony_ci	AP_FI_ACTION_CCA_AGENT_FF   = 0x01,
2118c2ecf20Sopenharmony_ci	AP_FI_ACTION_CCA_DOM_INVAL  = 0x02,
2128c2ecf20Sopenharmony_ci	AP_FI_ACTION_NQAP_QID_INVAL = 0x03,
2138c2ecf20Sopenharmony_ci};
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci/* all currently known fi flags */
2168c2ecf20Sopenharmony_cienum ap_fi_flags {
2178c2ecf20Sopenharmony_ci	AP_FI_FLAG_NO_RETRY	  = 0x01,
2188c2ecf20Sopenharmony_ci	AP_FI_FLAG_TOGGLE_SPECIAL = 0x02,
2198c2ecf20Sopenharmony_ci};
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_cistruct ap_message {
2228c2ecf20Sopenharmony_ci	struct list_head list;		/* Request queueing. */
2238c2ecf20Sopenharmony_ci	unsigned long long psmid;	/* Message id. */
2248c2ecf20Sopenharmony_ci	void *msg;			/* Pointer to message buffer. */
2258c2ecf20Sopenharmony_ci	unsigned int len;		/* Message length. */
2268c2ecf20Sopenharmony_ci	u16 flags;			/* Flags, see AP_MSG_FLAG_xxx */
2278c2ecf20Sopenharmony_ci	struct ap_fi fi;		/* Failure Injection cmd */
2288c2ecf20Sopenharmony_ci	int rc;				/* Return code for this message */
2298c2ecf20Sopenharmony_ci	void *private;			/* ap driver private pointer. */
2308c2ecf20Sopenharmony_ci	/* receive is called from tasklet context */
2318c2ecf20Sopenharmony_ci	void (*receive)(struct ap_queue *, struct ap_message *,
2328c2ecf20Sopenharmony_ci			struct ap_message *);
2338c2ecf20Sopenharmony_ci};
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci#define AP_MSG_FLAG_SPECIAL  1		/* flag msg as 'special' with NQAP */
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci/**
2388c2ecf20Sopenharmony_ci * ap_init_message() - Initialize ap_message.
2398c2ecf20Sopenharmony_ci * Initialize a message before using. Otherwise this might result in
2408c2ecf20Sopenharmony_ci * unexpected behaviour.
2418c2ecf20Sopenharmony_ci */
2428c2ecf20Sopenharmony_cistatic inline void ap_init_message(struct ap_message *ap_msg)
2438c2ecf20Sopenharmony_ci{
2448c2ecf20Sopenharmony_ci	memset(ap_msg, 0, sizeof(*ap_msg));
2458c2ecf20Sopenharmony_ci}
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci/**
2488c2ecf20Sopenharmony_ci * ap_release_message() - Release ap_message.
2498c2ecf20Sopenharmony_ci * Releases all memory used internal within the ap_message struct
2508c2ecf20Sopenharmony_ci * Currently this is the message and private field.
2518c2ecf20Sopenharmony_ci */
2528c2ecf20Sopenharmony_cistatic inline void ap_release_message(struct ap_message *ap_msg)
2538c2ecf20Sopenharmony_ci{
2548c2ecf20Sopenharmony_ci	kfree_sensitive(ap_msg->msg);
2558c2ecf20Sopenharmony_ci	kfree_sensitive(ap_msg->private);
2568c2ecf20Sopenharmony_ci}
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci/*
2598c2ecf20Sopenharmony_ci * Note: don't use ap_send/ap_recv after using ap_queue_message
2608c2ecf20Sopenharmony_ci * for the first time. Otherwise the ap message queue will get
2618c2ecf20Sopenharmony_ci * confused.
2628c2ecf20Sopenharmony_ci */
2638c2ecf20Sopenharmony_ciint ap_send(ap_qid_t, unsigned long long, void *, size_t);
2648c2ecf20Sopenharmony_ciint ap_recv(ap_qid_t, unsigned long long *, void *, size_t);
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cienum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event);
2678c2ecf20Sopenharmony_cienum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event);
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ciint ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg);
2708c2ecf20Sopenharmony_civoid ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg);
2718c2ecf20Sopenharmony_civoid ap_flush_queue(struct ap_queue *aq);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_civoid *ap_airq_ptr(void);
2748c2ecf20Sopenharmony_civoid ap_wait(enum ap_sm_wait wait);
2758c2ecf20Sopenharmony_civoid ap_request_timeout(struct timer_list *t);
2768c2ecf20Sopenharmony_civoid ap_bus_force_rescan(void);
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ciint ap_test_config_usage_domain(unsigned int domain);
2798c2ecf20Sopenharmony_ciint ap_test_config_ctrl_domain(unsigned int domain);
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_civoid ap_queue_init_reply(struct ap_queue *aq, struct ap_message *ap_msg);
2828c2ecf20Sopenharmony_cistruct ap_queue *ap_queue_create(ap_qid_t qid, int device_type);
2838c2ecf20Sopenharmony_civoid ap_queue_prepare_remove(struct ap_queue *aq);
2848c2ecf20Sopenharmony_civoid ap_queue_remove(struct ap_queue *aq);
2858c2ecf20Sopenharmony_civoid ap_queue_init_state(struct ap_queue *aq);
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_cistruct ap_card *ap_card_create(int id, int queue_depth, int raw_device_type,
2888c2ecf20Sopenharmony_ci			       int comp_device_type, unsigned int functions);
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_cistruct ap_perms {
2918c2ecf20Sopenharmony_ci	unsigned long ioctlm[BITS_TO_LONGS(AP_IOCTLS)];
2928c2ecf20Sopenharmony_ci	unsigned long apm[BITS_TO_LONGS(AP_DEVICES)];
2938c2ecf20Sopenharmony_ci	unsigned long aqm[BITS_TO_LONGS(AP_DOMAINS)];
2948c2ecf20Sopenharmony_ci};
2958c2ecf20Sopenharmony_ciextern struct ap_perms ap_perms;
2968c2ecf20Sopenharmony_ciextern struct mutex ap_perms_mutex;
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci/*
2998c2ecf20Sopenharmony_ci * Get ap_queue device for this qid.
3008c2ecf20Sopenharmony_ci * Returns ptr to the struct ap_queue device or NULL if there
3018c2ecf20Sopenharmony_ci * was no ap_queue device with this qid found. When something is
3028c2ecf20Sopenharmony_ci * found, the reference count of the embedded device is increased.
3038c2ecf20Sopenharmony_ci * So the caller has to decrease the reference count after use
3048c2ecf20Sopenharmony_ci * with a call to put_device(&aq->ap_dev.device).
3058c2ecf20Sopenharmony_ci */
3068c2ecf20Sopenharmony_cistruct ap_queue *ap_get_qdev(ap_qid_t qid);
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci/*
3098c2ecf20Sopenharmony_ci * check APQN for owned/reserved by ap bus and default driver(s).
3108c2ecf20Sopenharmony_ci * Checks if this APQN is or will be in use by the ap bus
3118c2ecf20Sopenharmony_ci * and the default set of drivers.
3128c2ecf20Sopenharmony_ci * If yes, returns 1, if not returns 0. On error a negative
3138c2ecf20Sopenharmony_ci * errno value is returned.
3148c2ecf20Sopenharmony_ci */
3158c2ecf20Sopenharmony_ciint ap_owned_by_def_drv(int card, int queue);
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci/*
3188c2ecf20Sopenharmony_ci * check 'matrix' of APQNs for owned/reserved by ap bus and
3198c2ecf20Sopenharmony_ci * default driver(s).
3208c2ecf20Sopenharmony_ci * Checks if there is at least one APQN in the given 'matrix'
3218c2ecf20Sopenharmony_ci * marked as owned/reserved by the ap bus and default driver(s).
3228c2ecf20Sopenharmony_ci * If such an APQN is found the return value is 1, otherwise
3238c2ecf20Sopenharmony_ci * 0 is returned. On error a negative errno value is returned.
3248c2ecf20Sopenharmony_ci * The parameter apm is a bitmask which should be declared
3258c2ecf20Sopenharmony_ci * as DECLARE_BITMAP(apm, AP_DEVICES), the aqm parameter is
3268c2ecf20Sopenharmony_ci * similar, should be declared as DECLARE_BITMAP(aqm, AP_DOMAINS).
3278c2ecf20Sopenharmony_ci */
3288c2ecf20Sopenharmony_ciint ap_apqn_in_matrix_owned_by_def_drv(unsigned long *apm,
3298c2ecf20Sopenharmony_ci				       unsigned long *aqm);
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci/*
3328c2ecf20Sopenharmony_ci * ap_parse_mask_str() - helper function to parse a bitmap string
3338c2ecf20Sopenharmony_ci * and clear/set the bits in the bitmap accordingly. The string may be
3348c2ecf20Sopenharmony_ci * given as absolute value, a hex string like 0x1F2E3D4C5B6A" simple
3358c2ecf20Sopenharmony_ci * overwriting the current content of the bitmap. Or as relative string
3368c2ecf20Sopenharmony_ci * like "+1-16,-32,-0x40,+128" where only single bits or ranges of
3378c2ecf20Sopenharmony_ci * bits are cleared or set. Distinction is done based on the very
3388c2ecf20Sopenharmony_ci * first character which may be '+' or '-' for the relative string
3398c2ecf20Sopenharmony_ci * and othewise assume to be an absolute value string. If parsing fails
3408c2ecf20Sopenharmony_ci * a negative errno value is returned. All arguments and bitmaps are
3418c2ecf20Sopenharmony_ci * big endian order.
3428c2ecf20Sopenharmony_ci */
3438c2ecf20Sopenharmony_ciint ap_parse_mask_str(const char *str,
3448c2ecf20Sopenharmony_ci		      unsigned long *bitmap, int bits,
3458c2ecf20Sopenharmony_ci		      struct mutex *lock);
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci#endif /* _AP_BUS_H_ */
348