indirect_pci.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * BK Id: %F% %I% %G% %U% %#%
  3.  */
  4. /*
  5.  * Support for indirect PCI bridges.
  6.  *
  7.  * Copyright (C) 1998 Gabriel Paubert.
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version
  12.  * 2 of the License, or (at your option) any later version.
  13.  */
  14. #include <linux/kernel.h>
  15. #include <linux/pci.h>
  16. #include <linux/delay.h>
  17. #include <linux/string.h>
  18. #include <linux/init.h>
  19. #include <linux/bootmem.h>
  20. #include <asm/io.h>
  21. #include <asm/prom.h>
  22. #include <asm/pci-bridge.h>
  23. #include <asm/machdep.h>
  24. #define cfg_read(val, addr, type, op) *val = op((type)(addr))
  25. #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
  26. #define INDIRECT_PCI_OP(rw, size, type, op, mask)  
  27. static int  
  28. indirect_##rw##_config_##size(struct pci_dev *dev, int offset, type val) 
  29. {  
  30. struct pci_controller *hose = dev->sysdata;  
  31.  
  32. out_be32(hose->cfg_addr,   
  33.  ((offset & 0xfc) << 24) | (dev->devfn << 16)  
  34.  | (dev->bus->number << 8) | 0x80);  
  35. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op);  
  36. return PCIBIOS_SUCCESSFUL;      
  37. }
  38. INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
  39. INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
  40. INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
  41. INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
  42. INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
  43. INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
  44. static struct pci_ops indirect_pci_ops =
  45. {
  46. indirect_read_config_byte,
  47. indirect_read_config_word,
  48. indirect_read_config_dword,
  49. indirect_write_config_byte,
  50. indirect_write_config_word,
  51. indirect_write_config_dword
  52. };
  53. void __init
  54. setup_indirect_pci(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  55. {
  56. hose->ops = &indirect_pci_ops;
  57. hose->cfg_addr = (unsigned int *) ioremap(cfg_addr, 4);
  58. hose->cfg_data = (unsigned char *) ioremap(cfg_data, 4);
  59. }