drivers/pci: Create pci_map_bar function
It is no longer always true that the pci bus address can be used as the virtual address for pci accesses. pci_map_bar() is created to return the virtual address for a pci region. Signed-off-by: Becky Bruce <beckyb@kernel.crashing.org>
This commit is contained in:
		
							parent
							
								
									2ecca34017
								
							
						
					
					
						commit
						6e61fae4d3
					
				| 
						 | 
					@ -116,6 +116,25 @@ PCI_READ_VIA_DWORD_OP(word, u16 *, 0x02)
 | 
				
			||||||
PCI_WRITE_VIA_DWORD_OP(byte, u8, 0x03, 0x000000ff)
 | 
					PCI_WRITE_VIA_DWORD_OP(byte, u8, 0x03, 0x000000ff)
 | 
				
			||||||
PCI_WRITE_VIA_DWORD_OP(word, u16, 0x02, 0x0000ffff)
 | 
					PCI_WRITE_VIA_DWORD_OP(word, u16, 0x02, 0x0000ffff)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Get a virtual address associated with a BAR region */
 | 
				
			||||||
 | 
					void *pci_map_bar(pci_dev_t pdev, int bar, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						pci_addr_t pci_bus_addr;
 | 
				
			||||||
 | 
						u32 bar_response;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* read BAR address */
 | 
				
			||||||
 | 
						pci_read_config_dword(pdev, bar, &bar_response);
 | 
				
			||||||
 | 
						pci_bus_addr = (pci_addr_t)(bar_response & ~0xf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Pass "0" as the length argument to pci_bus_to_virt.  The arg
 | 
				
			||||||
 | 
						 * isn't actualy used on any platform because u-boot assumes a static
 | 
				
			||||||
 | 
						 * linear mapping.  In the future, this could read the BAR size
 | 
				
			||||||
 | 
						 * and pass that as the size if needed.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						return pci_bus_to_virt(pdev, pci_bus_addr, flags, 0, MAP_NOCACHE);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -454,11 +454,30 @@ extern pci_addr_t pci_hose_phys_to_bus(struct pci_controller* hose,
 | 
				
			||||||
#define pci_bus_to_phys(dev, addr, flags) \
 | 
					#define pci_bus_to_phys(dev, addr, flags) \
 | 
				
			||||||
	pci_hose_bus_to_phys(pci_bus_to_hose(PCI_BUS(dev)), (addr), (flags))
 | 
						pci_hose_bus_to_phys(pci_bus_to_hose(PCI_BUS(dev)), (addr), (flags))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define pci_phys_to_mem(dev, addr)	pci_phys_to_bus((dev), (addr), PCI_REGION_MEM)
 | 
					#define pci_virt_to_bus(dev, addr, flags) \
 | 
				
			||||||
#define pci_mem_to_phys(dev, addr)	pci_bus_to_phys((dev), (addr), PCI_REGION_MEM)
 | 
						pci_hose_phys_to_bus(pci_bus_to_hose(PCI_BUS(dev)), \
 | 
				
			||||||
 | 
								     (virt_to_phys(addr)), (flags))
 | 
				
			||||||
 | 
					#define pci_bus_to_virt(dev, addr, flags, len, map_flags) \
 | 
				
			||||||
 | 
						map_physmem(pci_hose_bus_to_phys(pci_bus_to_hose(PCI_BUS(dev)), \
 | 
				
			||||||
 | 
										 (addr), (flags)), \
 | 
				
			||||||
 | 
							    (len), (map_flags))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define pci_phys_to_mem(dev, addr) \
 | 
				
			||||||
 | 
						pci_phys_to_bus((dev), (addr), PCI_REGION_MEM)
 | 
				
			||||||
 | 
					#define pci_mem_to_phys(dev, addr) \
 | 
				
			||||||
 | 
						pci_bus_to_phys((dev), (addr), PCI_REGION_MEM)
 | 
				
			||||||
#define pci_phys_to_io(dev, addr)  pci_phys_to_bus((dev), (addr), PCI_REGION_IO)
 | 
					#define pci_phys_to_io(dev, addr)  pci_phys_to_bus((dev), (addr), PCI_REGION_IO)
 | 
				
			||||||
#define pci_io_to_phys(dev, addr)  pci_bus_to_phys((dev), (addr), PCI_REGION_IO)
 | 
					#define pci_io_to_phys(dev, addr)  pci_bus_to_phys((dev), (addr), PCI_REGION_IO)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define pci_virt_to_mem(dev, addr) \
 | 
				
			||||||
 | 
						pci_virt_to_bus((dev), (addr), PCI_REGION_MEM)
 | 
				
			||||||
 | 
					#define pci_mem_to_virt(dev, addr, len, map_flags) \
 | 
				
			||||||
 | 
						pci_bus_to_virt((dev), (addr), PCI_REGION_MEM, (len), (map_flags))
 | 
				
			||||||
 | 
					#define pci_virt_to_io(dev, addr) \
 | 
				
			||||||
 | 
						pci_virt_to_bus((dev), (addr), PCI_REGION_IO)
 | 
				
			||||||
 | 
					#define pci_io_to_virt(dev, addr, len, map_flags) \
 | 
				
			||||||
 | 
						pci_bus_to_virt((dev), (addr), PCI_REGION_IO, (len), (map_flags))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern int pci_hose_read_config_byte(struct pci_controller *hose,
 | 
					extern int pci_hose_read_config_byte(struct pci_controller *hose,
 | 
				
			||||||
				     pci_dev_t dev, int where, u8 *val);
 | 
									     pci_dev_t dev, int where, u8 *val);
 | 
				
			||||||
extern int pci_hose_read_config_word(struct pci_controller *hose,
 | 
					extern int pci_hose_read_config_word(struct pci_controller *hose,
 | 
				
			||||||
| 
						 | 
					@ -488,6 +507,7 @@ extern int pci_hose_write_config_byte_via_dword(struct pci_controller *hose,
 | 
				
			||||||
extern int pci_hose_write_config_word_via_dword(struct pci_controller *hose,
 | 
					extern int pci_hose_write_config_word_via_dword(struct pci_controller *hose,
 | 
				
			||||||
						pci_dev_t dev, int where, u16 val);
 | 
											pci_dev_t dev, int where, u16 val);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void *pci_map_bar(pci_dev_t pdev, int bar, int flags);
 | 
				
			||||||
extern void pci_register_hose(struct pci_controller* hose);
 | 
					extern void pci_register_hose(struct pci_controller* hose);
 | 
				
			||||||
extern struct pci_controller* pci_bus_to_hose(int bus);
 | 
					extern struct pci_controller* pci_bus_to_hose(int bus);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue