wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Support for type PCI configuration cycles. |
| 3 | * based on pci_indirect.c |
| 4 | * |
| 5 | * Copyright (C) 2002 Daniel Engström, Omicron Ceti AB, daniel@omicron.se. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | |
| 15 | #ifdef CONFIG_PCI |
| 16 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 17 | #include <asm/io.h> |
| 18 | #include <pci.h> |
| 19 | |
wdenk | ea909b7 | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 20 | #define cfg_read(val, addr, op) *val = op((int)(addr)) |
| 21 | #define cfg_write(val, addr, op) op((val), (int)(addr)) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 22 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 23 | #define TYPE1_PCI_OP(rw, size, type, op, mask) \ |
| 24 | static int \ |
| 25 | type1_##rw##_config_##size(struct pci_controller *hose, \ |
| 26 | pci_dev_t dev, int offset, type val) \ |
| 27 | { \ |
| 28 | outl(dev | (offset & 0xfc) | 0x80000000, (int)hose->cfg_addr); \ |
| 29 | cfg_##rw(val, hose->cfg_data + (offset & mask), op); \ |
| 30 | return 0; \ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | |
| 34 | TYPE1_PCI_OP(read, byte, u8 *, inb, 3) |
| 35 | TYPE1_PCI_OP(read, word, u16 *, inw, 2) |
| 36 | TYPE1_PCI_OP(read, dword, u32 *, inl, 0) |
| 37 | |
| 38 | TYPE1_PCI_OP(write, byte, u8, outb, 3) |
| 39 | TYPE1_PCI_OP(write, word, u16, outw, 2) |
| 40 | TYPE1_PCI_OP(write, dword, u32, outl, 0) |
| 41 | |
| 42 | void pci_setup_type1(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data) |
| 43 | { |
| 44 | pci_set_ops(hose, |
| 45 | type1_read_config_byte, |
| 46 | type1_read_config_word, |
| 47 | type1_read_config_dword, |
| 48 | type1_write_config_byte, |
| 49 | type1_write_config_word, |
| 50 | type1_write_config_dword); |
| 51 | |
| 52 | hose->cfg_addr = (unsigned int *) cfg_addr; |
| 53 | hose->cfg_data = (unsigned char *) cfg_data; |
| 54 | } |
| 55 | |
| 56 | #endif |