18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * PCI Backend/Frontend Common Data Structures & Macros
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
58c2ecf20Sopenharmony_ci * of this software and associated documentation files (the "Software"), to
68c2ecf20Sopenharmony_ci * deal in the Software without restriction, including without limitation the
78c2ecf20Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
88c2ecf20Sopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is
98c2ecf20Sopenharmony_ci * furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
178c2ecf20Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
188c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
198c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
208c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci *   Author: Ryan Wilson <hap9@epoch.ncsc.mil>
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_ci#ifndef __XEN_PCI_COMMON_H__
258c2ecf20Sopenharmony_ci#define __XEN_PCI_COMMON_H__
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* Be sure to bump this number if you change this file */
288c2ecf20Sopenharmony_ci#define XEN_PCI_MAGIC "7"
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* xen_pci_sharedinfo flags */
318c2ecf20Sopenharmony_ci#define	_XEN_PCIF_active		(0)
328c2ecf20Sopenharmony_ci#define	XEN_PCIF_active			(1<<_XEN_PCIF_active)
338c2ecf20Sopenharmony_ci#define	_XEN_PCIB_AERHANDLER		(1)
348c2ecf20Sopenharmony_ci#define	XEN_PCIB_AERHANDLER		(1<<_XEN_PCIB_AERHANDLER)
358c2ecf20Sopenharmony_ci#define	_XEN_PCIB_active		(2)
368c2ecf20Sopenharmony_ci#define	XEN_PCIB_active			(1<<_XEN_PCIB_active)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* xen_pci_op commands */
398c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_conf_read		(0)
408c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_conf_write		(1)
418c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_enable_msi		(2)
428c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_disable_msi		(3)
438c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_enable_msix		(4)
448c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_disable_msix		(5)
458c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_aer_detected		(6)
468c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_aer_resume		(7)
478c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_aer_mmio		(8)
488c2ecf20Sopenharmony_ci#define	XEN_PCI_OP_aer_slotreset	(9)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* xen_pci_op error numbers */
518c2ecf20Sopenharmony_ci#define	XEN_PCI_ERR_success		(0)
528c2ecf20Sopenharmony_ci#define	XEN_PCI_ERR_dev_not_found	(-1)
538c2ecf20Sopenharmony_ci#define	XEN_PCI_ERR_invalid_offset	(-2)
548c2ecf20Sopenharmony_ci#define	XEN_PCI_ERR_access_denied	(-3)
558c2ecf20Sopenharmony_ci#define	XEN_PCI_ERR_not_implemented	(-4)
568c2ecf20Sopenharmony_ci/* XEN_PCI_ERR_op_failed - backend failed to complete the operation */
578c2ecf20Sopenharmony_ci#define XEN_PCI_ERR_op_failed		(-5)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/*
608c2ecf20Sopenharmony_ci * it should be PAGE_SIZE-sizeof(struct xen_pci_op))/sizeof(struct msix_entry))
618c2ecf20Sopenharmony_ci * Should not exceed 128
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_ci#define SH_INFO_MAX_VEC			128
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistruct xen_msix_entry {
668c2ecf20Sopenharmony_ci	uint16_t vector;
678c2ecf20Sopenharmony_ci	uint16_t entry;
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_cistruct xen_pci_op {
708c2ecf20Sopenharmony_ci	/* IN: what action to perform: XEN_PCI_OP_* */
718c2ecf20Sopenharmony_ci	uint32_t cmd;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	/* OUT: will contain an error number (if any) from errno.h */
748c2ecf20Sopenharmony_ci	int32_t err;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	/* IN: which device to touch */
778c2ecf20Sopenharmony_ci	uint32_t domain; /* PCI Domain/Segment */
788c2ecf20Sopenharmony_ci	uint32_t bus;
798c2ecf20Sopenharmony_ci	uint32_t devfn;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	/* IN: which configuration registers to touch */
828c2ecf20Sopenharmony_ci	int32_t offset;
838c2ecf20Sopenharmony_ci	int32_t size;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	/* IN/OUT: Contains the result after a READ or the value to WRITE */
868c2ecf20Sopenharmony_ci	uint32_t value;
878c2ecf20Sopenharmony_ci	/* IN: Contains extra infor for this operation */
888c2ecf20Sopenharmony_ci	uint32_t info;
898c2ecf20Sopenharmony_ci	/*IN:  param for msi-x */
908c2ecf20Sopenharmony_ci	struct xen_msix_entry msix_entries[SH_INFO_MAX_VEC];
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/*used for pcie aer handling*/
948c2ecf20Sopenharmony_cistruct xen_pcie_aer_op {
958c2ecf20Sopenharmony_ci	/* IN: what action to perform: XEN_PCI_OP_* */
968c2ecf20Sopenharmony_ci	uint32_t cmd;
978c2ecf20Sopenharmony_ci	/*IN/OUT: return aer_op result or carry error_detected state as input*/
988c2ecf20Sopenharmony_ci	int32_t err;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	/* IN: which device to touch */
1018c2ecf20Sopenharmony_ci	uint32_t domain; /* PCI Domain/Segment*/
1028c2ecf20Sopenharmony_ci	uint32_t bus;
1038c2ecf20Sopenharmony_ci	uint32_t devfn;
1048c2ecf20Sopenharmony_ci};
1058c2ecf20Sopenharmony_cistruct xen_pci_sharedinfo {
1068c2ecf20Sopenharmony_ci	/* flags - XEN_PCIF_* */
1078c2ecf20Sopenharmony_ci	uint32_t flags;
1088c2ecf20Sopenharmony_ci	struct xen_pci_op op;
1098c2ecf20Sopenharmony_ci	struct xen_pcie_aer_op aer_op;
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#endif /* __XEN_PCI_COMMON_H__ */
113