PCI: dwc: Add common pme_turn_off message by using outbound iATU
Subsystems (5)
Frank Li
maintainerv2 cover PCI: dwc: Add common pme_turn_off message by using outbound iATU
Involve an new and common mathod to send pme_turn_off() message. Previously pme_turn_off() implement by platform related special register to trigge it.
But Yoshihiro give good idea by using iATU to send out message. Previously Yoshihiro provide patches to raise INTx message by dummy write to outbound iATU.
Use similar mathod to send out pme_turn_off message.
Previous two patches is picked from Yoshihiro' big patch serialise.
PCI: dwc: Change arguments of dw_pcie_prog_outbound_atu()
PCI: Add INTx Mechanism Messages macros
PCI: Add PME_TURN_OFF message macro
dt-bindings: PCI: dwc: Add 'msg" register region, Add "msg" region to use to map PCI msg.
PCI: dwc: Add common pme_turn_off message method
Using common pme_turn_off() message if platform have not define their.
---
Changes in v2:
- Add my sign off at PCI: dwc: Add outbound MSG TLPs support
- Add Bjorn review tag at Add INTx Mechanism Messages macros
- using PME_Turn_Off match PCIe spec
- ref to pcie spec v6.1
- using section number.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Frank Li (3):
PCI: Add PME_TURN_OFF message macro
dt-bindings: PCI: dwc: Add 'msg" register region
PCI: dwc: Add common send PME_Turn_Off message method
Yoshihiro Shimoda (3):
PCI: Add INTx Mechanism Messages macros
PCI: dwc: Consolidate args of dw_pcie_prog_outbound_atu() into a structure
PCI: dwc: Add outbound MSG TLPs support
.../devicetree/bindings/pci/snps,dw-pcie.yaml | 4 + drivers/pci/controller/dwc/pcie-designware-ep.c | 21 +++-- drivers/pci/controller/dwc/pcie-designware-host.c | 103 +++++++++++++++++---- drivers/pci/controller/dwc/pcie-designware.c | 62 ++++++------- drivers/pci/controller/dwc/pcie-designware.h | 22 ++++- drivers/pci/pci.h | 20 ++++ 6 files changed, 168 insertions(+), 64 deletions(-)
---
base-commit: e08fc59eee9991afa467d406d684d46d543299a9
change-id: 20240130-pme_msg-dd2d81ee9886
Best regards,
Signature · 1 line
Frank Li <[email protected]>
Frank Li
maintainerPATCH v2 1/6 PCI: Add INTx Mechanism Messages macros
From: Yoshihiro Shimoda <[email protected]>
Add "Message Routing" and "INTx Mechanism Messages" macros to enable a PCIe driver to send messages for INTx Interrupt Signaling.
The "Message Routing" is in the section 2.2.8, and the "INTx Mechanism Messages" is in the section 2.2.8.1 on the PCI Express Base Specification, Rev 6.1.
--- drivers/pci/pci.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/pci/pci.h +18 -0
@@ -22,6 +22,24 @@*/ #define PCIE_PME_TO_L2_TIMEOUT_US 10000 +/* Message Routing (r[2:0]) */ +#define PCI_MSG_TYPE_R_RC 0 +#define PCI_MSG_TYPE_R_ADDR 1 +#define PCI_MSG_TYPE_R_ID 2 +#define PCI_MSG_TYPE_R_BC 3 +#define PCI_MSG_TYPE_R_LOCAL 4 +#define PCI_MSG_TYPE_R_GATHER 5 + +/* INTx Mechanism Messages */ +#define PCI_MSG_CODE_ASSERT_INTA 0x20 +#define PCI_MSG_CODE_ASSERT_INTB 0x21 +#define PCI_MSG_CODE_ASSERT_INTC 0x22 +#define PCI_MSG_CODE_ASSERT_INTD 0x23 +#define PCI_MSG_CODE_DEASSERT_INTA 0x24 +#define PCI_MSG_CODE_DEASSERT_INTB 0x25 +#define PCI_MSG_CODE_DEASSERT_INTC 0x26 +#define PCI_MSG_CODE_DEASSERT_INTD 0x27 +extern const unsigned char pcie_link_speed[];extern bool pci_early_dump;
Signature · 1 line
2.34.1
Frank Li
maintainerPATCH v2 2/6 PCI: dwc: Consolidate args of dw_pcie_prog_outbound_atu() into a structure
In reply to Frank LiFrom: Yoshihiro Shimoda <[email protected]>
This is a preparation before adding the Msg-type outbound iATU mapping. The respective update will require two more arguments added to __dw_pcie_prog_outbound_atu(). That will make the already complicated function prototype even more hard to comprehend accepting _eight_ arguments. In order to prevent that and keep the code more-or-less readable all the outbound iATU-related arguments are moved to the new config-structure: struct dw_pcie_ob_atu_cfg pointer to which shall be passed to dw_pcie_prog_outbound_atu(). The structure is supposed to be locally defined and populated with the outbound iATU settings implied by the caller context.
As a result of the denoted change there is no longer need in having the two distinctive methods for the Host and End-point outbound iATU setups since the corresponding code can directly call the dw_pcie_prog_outbound_atu() method with the config-structure populated. Thus dw_pcie_prog_ep_outbound_atu() is dropped.
--- drivers/pci/controller/dwc/pcie-designware-ep.c | 21 +++++---- drivers/pci/controller/dwc/pcie-designware-host.c | 52 ++++++++++++++++------- drivers/pci/controller/dwc/pcie-designware.c | 49 ++++++++------------- drivers/pci/controller/dwc/pcie-designware.h | 15 +++++-- 4 files changed, 77 insertions(+), 60 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +13 -8
@@ -159,9 +159,8 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, u8 func_no, int type,return 0 ; } -static int dw_pcie_ep_outbound_atu (struct dw_pcie_ep *ep,u8 func_no, -phys_addr_t phys_addr, -u64 pci_addr,size_t size) +static int dw_pcie_ep_outbound_atu (struct dw_pcie_ep *ep, +struct dw_pcie_ob_atu_cfg *atu) {struct dw_pcie *pci =to_dw_pcie_from_ep (ep);u32 free_win;
@@ -173,13 +172,13 @@ static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, u8 func_no,return -EINVAL ; } - ret =dw_pcie_prog_ep_outbound_atu (pci, func_no, free_win,PCIE_ATU_TYPE_MEM , - phys_addr, pci_addr, size); + atu->index = free_win; + ret =dw_pcie_prog_outbound_atu (pci, atu);if (ret)return ret;set_bit (free_win, ep->ob_window_map); - ep->outbound_addr[free_win] = phys_addr; + ep->outbound_addr[free_win] = atu->cpu_addr;return 0 ; }
@@ -279,8 +278,14 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,int ret;struct dw_pcie_ep *ep =epc_get_drvdata (epc);struct dw_pcie *pci =to_dw_pcie_from_ep (ep); - - ret =dw_pcie_ep_outbound_atu (ep, func_no, addr, pci_addr, size); +struct dw_pcie_ob_atu_cfg atu = {0 }; + + atu.func_no = func_no; + atu.type =PCIE_ATU_TYPE_MEM ; + atu.cpu_addr = addr; + atu.pci_addr = pci_addr; + atu.size = size; + ret =dw_pcie_ep_outbound_atu (ep, &atu);if (ret) {dev_err (pci->dev,"Failed to enable address\n" );return ret;
drivers/pci/controller/dwc/pcie-designware-host.c +36 -16
106 lines not on this page · raw message
drivers/pci/controller/dwc/pcie-designware.c +17 -32
94 lines not on this page · raw message
drivers/pci/controller/dwc/pcie-designware.h +11 -4
@@ -299,6 +299,15 @@ enum dw_pcie_ltssm { DW_PCIE_LTSSM_UNKNOWN = 0xFFFFFFFF, }; +struct dw_pcie_ob_atu_cfg { +int index; +int type; +u8 func_no; +u64 cpu_addr; +u64 pci_addr; +u64 size; +}; +struct dw_pcie_host_ops {int (*init)(struct dw_pcie_rp *pp);void (*deinit)(struct dw_pcie_rp *pp);
@@ -434,10 +443,8 @@ void dw_pcie_write_dbi2(struct dw_pcie *pci, u32 reg, size_t size, u32 val);int dw_pcie_link_up (struct dw_pcie *pci);void dw_pcie_upconfig_setup (struct dw_pcie *pci);int dw_pcie_wait_for_link (struct dw_pcie *pci); -int dw_pcie_prog_outbound_atu (struct dw_pcie *pci,int index,int type, -u64 cpu_addr,u64 pci_addr,u64 size); -int dw_pcie_prog_ep_outbound_atu (struct dw_pcie *pci,u8 func_no,int index, -int type,u64 cpu_addr,u64 pci_addr,u64 size); +int dw_pcie_prog_outbound_atu (struct dw_pcie *pci, +const struct dw_pcie_ob_atu_cfg *atu);int dw_pcie_prog_inbound_atu (struct dw_pcie *pci,int index,int type,u64 cpu_addr,u64 pci_addr,u64 size); int dw_pcie_prog_ep_inbound_atu(struct dw_pcie *pci, u8 func_no, int index,
Signature · 1 line
2.34.1
Frank Li
maintainerPATCH v2 3/6 PCI: dwc: Add outbound MSG TLPs support
In reply to Frank LiFrom: Yoshihiro Shimoda <[email protected]>
Add "code" and "routing" into struct dw_pcie_ob_atu_cfg for triggering INTx IRQs by iATU in the PCIe endpoint mode in near the future. PCIE_ATU_INHIBIT_PAYLOAD is set to issue TLP type of Msg instead of MsgD. So, this implementation supports the data-less messages only for now.
--- drivers/pci/controller/dwc/pcie-designware.c | 9 +++++++-- drivers/pci/controller/dwc/pcie-designware.h | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/pci/controller/dwc/pcie-designware.c +7 -2
@@ -499,7 +499,7 @@ int dw_pcie_prog_outbound_atu(struct dw_pcie *pci,dw_pcie_writel_atu_ob (pci, atu->index,PCIE_ATU_UPPER_TARGET ,upper_32_bits (atu->pci_addr)); - val = atu->type |PCIE_ATU_FUNC_NUM (atu->func_no); + val = atu->type | atu->routing |PCIE_ATU_FUNC_NUM (atu->func_no);if (upper_32_bits (limit_addr) >upper_32_bits (cpu_addr) && dw_pcie_ver_is_ge(pci, 460A)) val |=PCIE_ATU_INCREASE_REGION_SIZE ;
@@ -507,7 +507,12 @@ int dw_pcie_prog_outbound_atu(struct dw_pcie *pci, val =dw_pcie_enable_ecrc (val);dw_pcie_writel_atu_ob (pci, atu->index,PCIE_ATU_REGION_CTRL1 , val); -dw_pcie_writel_atu_ob (pci, atu->index,PCIE_ATU_REGION_CTRL2 ,PCIE_ATU_ENABLE ); + val =PCIE_ATU_ENABLE ; +if (atu->type ==PCIE_ATU_TYPE_MSG ) { +/* The data-less messages only for now */ + val |=PCIE_ATU_INHIBIT_PAYLOAD | atu->code; + } +dw_pcie_writel_atu_ob (pci, atu->index,PCIE_ATU_REGION_CTRL2 , val);/* * Make sure ATU enable takes effect before any subsequent config
drivers/pci/controller/dwc/pcie-designware.h +4 -0
@@ -148,11 +148,13 @@#define PCIE_ATU_TYPE_IO 0x2#define PCIE_ATU_TYPE_CFG0 0x4#define PCIE_ATU_TYPE_CFG1 0x5 +#define PCIE_ATU_TYPE_MSG 0x10#define PCIE_ATU_TD BIT(8)#define PCIE_ATU_FUNC_NUM (pf) ((pf) << 20)#define PCIE_ATU_REGION_CTRL2 0x004#define PCIE_ATU_ENABLE BIT(31)#define PCIE_ATU_BAR_MODE_ENABLE BIT(30) +#define PCIE_ATU_INHIBIT_PAYLOAD BIT(22)#define PCIE_ATU_FUNC_NUM_MATCH_EN BIT(19)#define PCIE_ATU_LOWER_BASE 0x008#define PCIE_ATU_UPPER_BASE 0x00C
@@ -303,6 +305,8 @@ struct dw_pcie_ob_atu_cfg {int index;int type;u8 func_no; +u8 code; +u8 routing;u64 cpu_addr;u64 pci_addr;u64 size;
Signature · 1 line
2.34.1
Frank Li
maintainerPATCH v2 4/6 PCI: Add PME_TURN_OFF message macro
In reply to Frank LiAdd PME_TURN_OFF macros to enable a PCIe host driver to send PME messages.
--- drivers/pci/pci.h | 2 ++ 1 file changed, 2 insertions(+)
drivers/pci/pci.h +2 -0
@@ -40,6 +40,8 @@#define PCI_MSG_CODE_DEASSERT_INTC 0x26#define PCI_MSG_CODE_DEASSERT_INTD 0x27 +#define PCI_MSG_CODE_PME_TURN_OFF 0x19 +extern const unsigned char pcie_link_speed[];extern bool pci_early_dump;
Signature · 1 line
2.34.1
Frank Li
maintainerPATCH v2 5/6 dt-bindings: PCI: dwc: Add 'msg" register region
In reply to Frank LiAdd an outbound iATU-capable memory-region which will be used to send PCIe message (such as PME_Turn_Off) to peripheral. So all platforms can use common method to send out PME_Turn_Off message by using one outbound iATU.
--- Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml +4 -0
@@ -101,6 +101,10 @@ properties: Outbound iATU-capable memory-region which will be used to access the peripheral PCIe devices configuration space. const: config + - description: + Outbound iATU-capable memory-region which will be used to send + PCIe message (such as PME_Turn_Off) to peripheral. + const: msg - description: Vendor-specific CSR names. Consider using the generic names above for new bindings.
Signature · 1 line
2.34.1
Re: [PATCH v2 5/6] dt-bindings: PCI: dwc: Add 'msg" register region
Still has mismatched quotes in subject.
Frank Li
maintainerPATCH v2 6/6 PCI: dwc: Add common send PME_Turn_Off message method
In reply to Frank LiSet outbound ATU map memory write to send PCI message. So one MMIO write can trigger a PCI message, such as PME_Turn_Off.
Add common dw_pcie_send_pme_turn_off_by_atu() function.
Call dw_pcie_send_pme_turn_off_by_atu() to send out PME_Turn_Off message in general dw_pcie_suspend_noirq() if there are not platform callback pme_turn_off() exist.
--- drivers/pci/controller/dwc/pcie-designware-host.c | 51 +++++++++++++++++++++-- drivers/pci/controller/dwc/pcie-designware.c | 8 ++++ drivers/pci/controller/dwc/pcie-designware.h | 3 ++ 3 files changed, 58 insertions(+), 4 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +47 -4
@@ -728,6 +728,8 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp)dev_warn (pci->dev,"Ranges exceed outbound iATU size (%d)\n" , pci->num_ob_windows); + pci->msg_atu_index = i; + i =0 ;resource_list_for_each_entry (entry, &pp->bridge->dma_ranges) {if (resource_type (entry->res) !=IORESOURCE_MEM )
@@ -833,11 +835,49 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp) }EXPORT_SYMBOL_GPL (dw_pcie_setup_rc); +static int dw_pcie_send_pme_turn_off_by_atu (struct dw_pcie *pci) +{ +struct dw_pcie_ob_atu_cfg atu = {0 }; +void __iomem *m; +int ret =0 ; + +if (pci->num_ob_windows <= pci->msg_atu_index) +return -EINVAL ; + + atu.code =PCI_MSG_CODE_PME_TURN_OFF ; + atu.routing =PCI_MSG_TYPE_R_BC ; + atu.type =PCIE_ATU_TYPE_MSG ; + atu.size = pci->msg_io_size; + +if (!atu.size) { +dev_dbg (pci->dev, +"atu memory map windows is zero, please check 'msg' reg in dts\n" ); +return -ENOMEM ; + } + + atu.cpu_addr = pci->msg_io_base; + + ret =dw_pcie_prog_outbound_atu (pci, &atu); +if (ret) +return ret; + + m =ioremap (atu.cpu_addr,PAGE_SIZE ); +if (!m) +return -ENOMEM ; + +/* A dummy write is converted to a Msg TLP */ +writel (0 , m); + +iounmap (m); + +return ret; +} +int dw_pcie_suspend_noirq (struct dw_pcie *pci) {u8 offset =dw_pcie_find_capability (pci,PCI_CAP_ID_EXP );u32 val; -int ret; +int ret =0 ;/* * If L1SS is supported, then do not put the link into L2 as some
@@ -849,10 +889,13 @@ int dw_pcie_suspend_noirq(struct dw_pcie *pci)if (dw_pcie_get_ltssm (pci) <=DW_PCIE_LTSSM_DETECT_ACT )return 0 ; -if (!pci->pp.ops->pme_turn_off) -return 0 ; +if (pci->pp.ops->pme_turn_off) + pci->pp.ops->pme_turn_off (&pci->pp); +else + ret =dw_pcie_send_pme_turn_off_by_atu (pci); - pci->pp.ops->pme_turn_off (&pci->pp); +if (ret) +return ret; ret = read_poll_timeout(dw_pcie_get_ltssm, val, val == DW_PCIE_LTSSM_L2_IDLE, PCIE_PME_TO_L2_TIMEOUT_US/10,
drivers/pci/controller/dwc/pcie-designware.c +8 -0
@@ -155,6 +155,14 @@ int dw_pcie_get_resources(struct dw_pcie *pci) } } +if (!pci->msg_io_base) { + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"msg" ); +if (res) { + pci->msg_io_base = res->start; + pci->msg_io_size = res->end - res->start +1 ; + } + } +/* LLDD is supposed to manually switch the clocks and resets state */ if (dw_pcie_cap_is (pci,REQ_RES )) { ret =dw_pcie_get_clocks (pci);
drivers/pci/controller/dwc/pcie-designware.h +3 -0
@@ -424,6 +424,9 @@ struct dw_pcie {struct reset_control_bulk_data core_rsts[DW_PCIE_NUM_CORE_RSTS ];struct gpio_desc *pe_rst;bool suspended; +int msg_atu_index; +phys_addr_t msg_io_base; +size_t msg_io_size; };#define to_dw_pcie_from_pp (port) container_of((port), struct dw_pcie, pp)
Signature · 1 line
2.34.1
Re: [PATCH v2 6/6] PCI: dwc: Add common send PME_Turn_Off message method
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_suspend_noirq(struct dw_pcie *pci) · line 895
Quoted 12 lines · Frank Li
Set outbound ATU map memory write to send PCI message. So one MMIO write can trigger a PCI message, such as
PME_Turn_Off.Add common
dw_pcie_send_pme_turn_off_by_atu()function.
...drivers/pci/controller/dwc/pcie-designware-host.c +4
-2-if (!pci->pp.ops->pme_turn_off) -return 0 ; +if (pci->pp.ops->pme_turn_off) + pci->pp.ops->pme_turn_off (&pci->pp); +else + ret =dw_pcie_send_pme_turn_off_by_atu (pci);
I think it's nice if function names match the function pointer names.
E.g., we currently already have:
.pme_turn_off = ls_pcie_send_turnoff_msg,
.pme_turn_off = ls1021a_pcie_send_turnoff_msg,
.pme_turn_off = ls1043a_pcie_send_turnoff_msg,
which is slightly annoying because it's always useful to compare implementations, but "git grep pme_turn_off" doesn't find the actual functions, so I wish these were named "ls_pcie_pme_turn_off()", etc.
You don't have to fix those existing layerscape ones now, but I think the same applies to dw_pcie_send_pme_turn_off_by_atu(): it would be nice if it were named something like "dw_pcie_pme_turn_off()" so grep/cscope would find it easily.
Bjorn
Frank Li
maintainerRe: [PATCH v2 6/6] PCI: dwc: Add common send PME_Turn_Off message method
Quoted 22 lines · Bjorn Helgaas
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_suspend_noirq(struct dw_pcie *pci) · line 895
Quoted 12 lines · Frank Li
Set outbound ATU map memory write to send PCI message. So one MMIO write can trigger a PCI message, such as
PME_Turn_Off.Add common
dw_pcie_send_pme_turn_off_by_atu()function.
...drivers/pci/controller/dwc/pcie-designware-host.c +4
-2-if (!pci->pp.ops->pme_turn_off) -return 0 ; +if (pci->pp.ops->pme_turn_off) + pci->pp.ops->pme_turn_off (&pci->pp); +else + ret =dw_pcie_send_pme_turn_off_by_atu (pci);I think it's nice if function names match the function pointer names.
E.g., we currently already have:
.pme_turn_off =
ls_pcie_send_turnoff_msg,
.pme_turn_off =ls1021a_pcie_send_turnoff_msg,
.pme_turn_off =ls1043a_pcie_send_turnoff_msg,
Quoted 8 lines
which is slightly annoying because it's always useful to compare implementations, but "git grep
pme_turn_off" doesn't find the actual functions, so I wish these were named "ls_pcie_pme_turn_off()", etc.You don't have to fix those existing layerscape ones now, but I think the same applies to
dw_pcie_send_pme_turn_off_by_atu(): it would be nice if it were named something like "dw_pcie_pme_turn_off()" so grep/cscope would find it easily.
Okay, these funcition can be removed because this patch. But It takes some time to test it at these platform. Add need dts update also. There are still long road.
Frank
Quoted 2 lines
Bjorn