xref: /kvmtool/powerpc/spapr_pci.h (revision 4123ca555b1d466b08c630763a378b4d53de9ec5)
1 /*
2  * SPAPR PHB definitions
3  *
4  * Modifications by Matt Evans <matt@ozlabs.org>, IBM Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published
8  * by the Free Software Foundation.
9  */
10 
11 #ifndef SPAPR_PCI_H
12 #define SPAPR_PCI_H
13 
14 #include "kvm/kvm.h"
15 #include "spapr.h"
16 #include <inttypes.h>
17 
18 /* With XICS, we can easily accomodate 1 IRQ per PCI device. */
19 
20 #define SPAPR_PCI_NUM_LSI 256
21 
22 struct spapr_phb {
23 	uint64_t buid;
24 	uint64_t mem_addr;
25 	uint64_t mem_size;
26 	uint64_t io_addr;
27 	uint64_t io_size;
28 };
29 
30 void spapr_create_phb(struct kvm *kvm,
31                       const char *busname, uint64_t buid,
32                       uint64_t mem_win_addr, uint64_t mem_win_size,
33                       uint64_t io_win_addr, uint64_t io_win_size);
34 
35 int spapr_populate_pci_devices(struct kvm *kvm,
36                                uint32_t xics_phandle,
37                                void *fdt);
38 
spapr_phb_mmio(struct kvm_cpu * vcpu,u64 phys_addr,u8 * data,u32 len,u8 is_write)39 static inline bool spapr_phb_mmio(struct kvm_cpu *vcpu, u64 phys_addr, u8 *data, u32 len, u8 is_write)
40 {
41 	if ((phys_addr >= SPAPR_PCI_IO_WIN_ADDR) &&
42 	    (phys_addr < SPAPR_PCI_IO_WIN_ADDR +
43 	     SPAPR_PCI_IO_WIN_SIZE)) {
44 		return kvm__emulate_io(vcpu, phys_addr - SPAPR_PCI_IO_WIN_ADDR,
45 				       data, is_write ? KVM_EXIT_IO_OUT :
46 				       KVM_EXIT_IO_IN,
47 				       len, 1);
48 	} else if ((phys_addr >= SPAPR_PCI_MEM_WIN_ADDR) &&
49 		   (phys_addr < SPAPR_PCI_MEM_WIN_ADDR +
50 		    SPAPR_PCI_MEM_WIN_SIZE)) {
51 		return kvm__emulate_mmio(vcpu, phys_addr - SPAPR_PCI_MEM_WIN_ADDR,
52 					 data, len, is_write);
53 	}
54 	return false;
55 }
56 
57 #endif
58