Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * read/write operation to the PCI config space of CS5536
0004  *
0005  * Copyright (C) 2007 Lemote, Inc.
0006  * Author : jlliu, liujl@lemote.com
0007  *
0008  * Copyright (C) 2009 Lemote, Inc.
0009  * Author: Wu Zhangjin, wuzhangjin@gmail.com
0010  *
0011  *  the Virtual Support Module(VSM) for virtulizing the PCI
0012  *  configure space are defined in cs5536_modulename.c respectively,
0013  *
0014  *  after this virtulizing, user can access the PCI configure space
0015  *  directly as a normal multi-function PCI device which follows
0016  *  the PCI-2.2 spec.
0017  */
0018 
0019 #include <linux/types.h>
0020 #include <cs5536/cs5536_pci.h>
0021 #include <cs5536/cs5536_vsm.h>
0022 
0023 enum {
0024     CS5536_FUNC_START = -1,
0025     CS5536_ISA_FUNC,
0026     reserved_func,
0027     CS5536_IDE_FUNC,
0028     CS5536_ACC_FUNC,
0029     CS5536_OHCI_FUNC,
0030     CS5536_EHCI_FUNC,
0031     CS5536_FUNC_END,
0032 };
0033 
0034 static const cs5536_pci_vsm_write vsm_conf_write[] = {
0035     [CS5536_ISA_FUNC]   = pci_isa_write_reg,
0036     [reserved_func]     = NULL,
0037     [CS5536_IDE_FUNC]   = pci_ide_write_reg,
0038     [CS5536_ACC_FUNC]   = pci_acc_write_reg,
0039     [CS5536_OHCI_FUNC]  = pci_ohci_write_reg,
0040     [CS5536_EHCI_FUNC]  = pci_ehci_write_reg,
0041 };
0042 
0043 static const cs5536_pci_vsm_read vsm_conf_read[] = {
0044     [CS5536_ISA_FUNC]   = pci_isa_read_reg,
0045     [reserved_func]     = NULL,
0046     [CS5536_IDE_FUNC]   = pci_ide_read_reg,
0047     [CS5536_ACC_FUNC]   = pci_acc_read_reg,
0048     [CS5536_OHCI_FUNC]  = pci_ohci_read_reg,
0049     [CS5536_EHCI_FUNC]  = pci_ehci_read_reg,
0050 };
0051 
0052 /*
0053  * write to PCI config space and transfer it to MSR write.
0054  */
0055 void cs5536_pci_conf_write4(int function, int reg, u32 value)
0056 {
0057     if ((function <= CS5536_FUNC_START) || (function >= CS5536_FUNC_END))
0058         return;
0059     if ((reg < 0) || (reg > 0x100) || ((reg & 0x03) != 0))
0060         return;
0061 
0062     if (vsm_conf_write[function] != NULL)
0063         vsm_conf_write[function](reg, value);
0064 }
0065 
0066 /*
0067  * read PCI config space and transfer it to MSR access.
0068  */
0069 u32 cs5536_pci_conf_read4(int function, int reg)
0070 {
0071     u32 data = 0;
0072 
0073     if ((function <= CS5536_FUNC_START) || (function >= CS5536_FUNC_END))
0074         return 0;
0075     if ((reg < 0) || ((reg & 0x03) != 0))
0076         return 0;
0077     if (reg > 0x100)
0078         return 0xffffffff;
0079 
0080     if (vsm_conf_read[function] != NULL)
0081         data = vsm_conf_read[function](reg);
0082 
0083     return data;
0084 }