1 /*
2  * This program is free software; you can redistribute it and/or modify it
3  * under the terms and conditions of the GNU General Public License,
4  * version 2, as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope it will be useful, but WITHOUT
7  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
9  * more details.
10  *
11  * You should have received a copy of the GNU General Public License along with
12  * this program; If not, see <http://www.gnu.org/licenses/>.
13  */
14 
15 #ifndef _ATS_H_
16 #define _ATS_H_
17 
18 #include <xen/pci_regs.h>
19 
20 #define ATS_REG_CAP    4
21 #define ATS_REG_CTL    6
22 #define ATS_QUEUE_DEPTH_MASK     0x1f
23 #define ATS_ENABLE               (1<<15)
24 
25 extern bool ats_enabled;
26 
27 int enable_ats_device(struct pci_dev *pdev, struct list_head *ats_list);
28 void disable_ats_device(struct pci_dev *pdev);
29 
pci_ats_enabled(int seg,int bus,int devfn)30 static inline int pci_ats_enabled(int seg, int bus, int devfn)
31 {
32     u32 value;
33     int pos;
34 
35     pos = pci_find_ext_capability(PCI_SBDF(seg, bus, devfn),
36                                   PCI_EXT_CAP_ID_ATS);
37     BUG_ON(!pos);
38 
39     value = pci_conf_read16(PCI_SBDF(seg, bus, devfn), pos + ATS_REG_CTL);
40 
41     return value & ATS_ENABLE;
42 }
43 
pci_ats_device(int seg,int bus,int devfn)44 static inline int pci_ats_device(int seg, int bus, int devfn)
45 {
46     if ( !ats_enabled )
47         return 0;
48 
49     return pci_find_ext_capability(PCI_SBDF(seg, bus, devfn),
50                                    PCI_EXT_CAP_ID_ATS);
51 }
52 
53 #endif /* _ATS_H_ */
54 
55