PCI: dwc: Add common pme_turn_off message by using outbound iATU
Subsystems (4)
Frank Li
maintainerv6 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 v6:
- Move PCIE_MSG_CODE_PME_TURN_OFF ahead before INTx to keep the codes sorted.
- Added reason why not alloc_resesource in commit messag.
- Change title PCI: dwc: Add generic MSG TLP support for sending PME_Turn_Off when system suspend.
- Rework commit message
"Instead of relying on the vendor specific implementations to send thePME_Turn_Off message, let's introduce a generic way of sending the message using the MSG TLP.
This is achieved by reserving a region for MSG TLP of size 'pci->region_align', at the end of the first IORESOURCE_MEM window of the host bridge. And then sending the PME_Turn_Off message during system suspend with the help of iATU.
It should be noted that this generic implementation is optional for the glue drivers and can be overridden by a custom 'pme_turn_off' callback.
- using devm_request_resource()
- using mani's suggest comments
/*
* Allocate the resource for MSG TLP before programming the iATU
* outbound window in dw_pcie_setup_rc(). Since the allocation depends
* on the value of 'region_align', this has to be done after
* dw_pcie_iatu_detect().
*/
- Add comments, about use_atu_msg, need glue driver set it.
- m -> mem in dw_pcie_pme_turn_off()
- remove redundant check() if (!atu.size) in dw_pcie_pme_turn_off().
- The reason can't adjust windows->end
This windows already reported to pci system before this function. It is not good to modify window-res-end. It just add child resource like below.
windows is root resource, which will create may child when call request_resource.
bridge -> windows child1 -> msg child2 -> pci ep1 child3 -> pci_ep2. ...
Although you see whole bridge window, 'msg' already used and put under root resource, new pci devices will never use 'msg' resource.
If change windows->res->end here, I worry about it may broken resource tree.
Detail below thread:
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Default disable allocate TLP message memory windows. If driver need use this feature, need set use_atu_msg = true before call dw_host_init().
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Remove dt-binding patch. Needn't change any dts file and binding doc. Reserve a region at end of first IORESOURCE_MEM window by call request_resource(). So PCIe stack will not use this reserve region to any
PCIe devices.
I tested it by reserve at begin of IORESOURCE_MEM window. PCIe stack
will skip it as expection.
Fixed a issue, forget set iATU index when sent PME_turn_off.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- fix 'MSG"
- Add pcie spec ref in head file
- using function name dw_pci_pme_turn_off()
- Using PCIE_ prefix macro
- Link to v2: https://lore.kernel.org/r/[email protected]
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 (2):
PCI: Add PCIE_MSG_CODE_PME_TURN_OFF message macro
PCI: dwc: Add generic MSG TLP support for sending PME_Turn_Off when system suspend
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
drivers/pci/controller/dwc/pcie-designware-ep.c | 21 ++-- drivers/pci/controller/dwc/pcie-designware-host.c | 146 +++++++++++++++++++--- drivers/pci/controller/dwc/pcie-designware.c | 54 ++++---- drivers/pci/controller/dwc/pcie-designware.h | 22 +++- drivers/pci/pci.h | 20 +++ 5 files changed, 199 insertions(+), 64 deletions(-)
---
base-commit: ef6a734484e939cf67bc41c45bc936a78ea210f0
change-id: 20240130-pme_msg-dd2d81ee9886
Best regards,
---
Frank Li <[email protected]>
Frank Li
maintainerPATCH v6 1/5 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]) See: PCIe r6.0, sec 2.2.8 */ +#define PCIE_MSG_TYPE_R_RC 0 +#define PCIE_MSG_TYPE_R_ADDR 1 +#define PCIE_MSG_TYPE_R_ID 2 +#define PCIE_MSG_TYPE_R_BC 3 +#define PCIE_MSG_TYPE_R_LOCAL 4 +#define PCIE_MSG_TYPE_R_GATHER 5 + +/* INTx Mechanism Messages See: PCIe r6.0, sec 2.2.8.1 */ +#define PCIE_MSG_CODE_ASSERT_INTA 0x20 +#define PCIE_MSG_CODE_ASSERT_INTB 0x21 +#define PCIE_MSG_CODE_ASSERT_INTC 0x22 +#define PCIE_MSG_CODE_ASSERT_INTD 0x23 +#define PCIE_MSG_CODE_DEASSERT_INTA 0x24 +#define PCIE_MSG_CODE_DEASSERT_INTB 0x25 +#define PCIE_MSG_CODE_DEASSERT_INTC 0x26 +#define PCIE_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 v6 2/5 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
@@ -160,9 +160,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;
@@ -174,13 +173,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 ; }
@@ -280,8 +279,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 v6 3/5 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 v6 4/5 PCI: Add PCIE_MSG_CODE_PME_TURN_OFF message macro
In reply to Frank LiAdd PCIE_MSG_CODE_PME_TURN_OFF macros to enable a PCIe host driver to send PME_Turn_Off messages.
--- drivers/pci/pci.h | 2 ++ 1 file changed, 2 insertions(+)
drivers/pci/pci.h +2 -0
@@ -30,6 +30,8 @@#define PCIE_MSG_TYPE_R_LOCAL 4#define PCIE_MSG_TYPE_R_GATHER 5 +#define PCIE_MSG_CODE_PME_TURN_OFF 0x19 +/* INTx Mechanism Messages See: PCIe r6.0, sec 2.2.8.1 */ #define PCIE_MSG_CODE_ASSERT_INTA 0x20#define PCIE_MSG_CODE_ASSERT_INTB 0x21
Signature · 1 line
2.34.1
Re: [PATCH v6 4/5] PCI: Add PCIE_MSG_CODE_PME_TURN_OFF message macro
Quoted 13 lines · Frank Li
Add
PCIE_MSG_CODE_PME_TURN_OFFmacros to enable a PCIe host driver to sendPME_Turn_Offmessages.Signed-off-by Frank Li <[email protected]>--- drivers/pci/pci.h | 2 ++ 1 file changed, 2 insertions(+)drivers/pci/pci.h +0
-0
drivers/pci/pci.h line 33
Quoted 4 lines
drivers/pci/pci.h +1
-0@@ -30,6 +30,8 @@#define PCIE_MSG_TYPE_R_LOCAL 4#define PCIE_MSG_TYPE_R_GATHER 5 +#define PCIE_MSG_CODE_PME_TURN_OFF 0x19
This is defined in PCIe r6.0, sec 2.2.8.2, so move this below the INTx #defines so they're all in the order of the spec sections and add the spec citation to follow the same style as the surrounding #defines, i.e.,
/* Power Management Messages; PCIe r6.0, sec 2.2.8.2 */ #define PCIE_MSG_CODE_PME_TURN_OFF 0x19
While you're at it, tweak the [1/5] comments to be:
/* Message Routing (r[2:0]); PCIe r6.0, sec 2.2.8 */ /* INTx Mechanism Messages; PCIe r6.0, sec 2.2.8.1 */
since the "Message Routing See: PCIe ..." comments are run together and need some punctuation between the text and the citation.
With these,
Quoted 7 lines
drivers/pci/pci.h +0
-0/* INTx Mechanism Messages See: PCIe r6.0, sec 2.2.8.1 */ #define PCIE_MSG_CODE_ASSERT_INTA 0x20#define PCIE_MSG_CODE_ASSERT_INTB 0x21Signature · 2 lines
-- 2.34.1
Re: [PATCH v6 4/5] PCI: Add PCIE_MSG_CODE_PME_TURN_OFF message macro
Quoted 17 lines · Bjorn Helgaas
Quoted 16 lines · Frank Li
Add
PCIE_MSG_CODE_PME_TURN_OFFmacros to enable a PCIe host driver to sendPME_Turn_Offmessages.Signed-off-by Frank Li <[email protected]>--- drivers/pci/pci.h | 2 ++ 1 file changed, 2 insertions(+)drivers/pci/pci.h +0
-0@@ -30,6 +30,8 @@#define PCIE_MSG_TYPE_R_LOCAL 4#define PCIE_MSG_TYPE_R_GATHER 5
Quoted 4 lines
drivers/pci/pci.h line 33
Quoted 1 line
drivers/pci/pci.h +1
-0+#define PCIE_MSG_CODE_PME_TURN_OFF 0x19This is defined in PCIe r6.0, sec 2.2.8.2, so move this below the INTx #defines so they're all in the order of the spec sections and add the
I think it was me who suggested moving this up to keep it sorted in ascending order :/
- Mani
Quoted 25 lines
spec citation to follow the same style as the surrounding #defines, i.e.,
/* Power Management Messages; PCIe r6.0, sec 2.2.8.2 */ #define PCIE_MSG_CODE_PME_TURN_OFF 0x19While you're at it, tweak the [1/5] comments to be:
/* Message Routing (r[2:0]); PCIe r6.0, sec 2.2.8 */ /* INTx Mechanism Messages; PCIe r6.0, sec 2.2.8.1 */
since the "Message Routing See: PCIe ..." comments are run together and need some punctuation between the text and the citation.
With these,
Acked-by Bjorn Helgaas <[email protected]>Quoted 7 lines
drivers/pci/pci.h +0
-0/* INTx Mechanism Messages See: PCIe r6.0, sec 2.2.8.1 */ #define PCIE_MSG_CODE_ASSERT_INTA 0x20#define PCIE_MSG_CODE_ASSERT_INTB 0x21Signature · 2 lines
-- 2.34.1
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Re: [PATCH v6 4/5] PCI: Add PCIE_MSG_CODE_PME_TURN_OFF message macro
Quoted 18 lines · Manivannan Sadhasivam
Quoted 17 lines · Bjorn Helgaas
Quoted 16 lines · Frank Li
Add
PCIE_MSG_CODE_PME_TURN_OFFmacros to enable a PCIe host driver to sendPME_Turn_Offmessages.Signed-off-by Frank Li <[email protected]>--- drivers/pci/pci.h | 2 ++ 1 file changed, 2 insertions(+)drivers/pci/pci.h +0
-0@@ -30,6 +30,8 @@#define PCIE_MSG_TYPE_R_LOCAL 4#define PCIE_MSG_TYPE_R_GATHER 5
Quoted 7 lines
Quoted 4 lines
drivers/pci/pci.h line 33
Quoted 1 line
drivers/pci/pci.h +1
-0+#define PCIE_MSG_CODE_PME_TURN_OFF 0x19This is defined in PCIe r6.0, sec 2.2.8.2, so move this below the INTx #defines so they're all in the order of the spec sections and add the
I think it was me who suggested moving this up to keep it sorted in ascending order :/
OK, the order you suggested is fine.
Quoted 6 lines
Quoted 6 lines
spec citation to follow the same style as the surrounding #defines, i.e.,
/* Power Management Messages; PCIe r6.0, sec 2.2.8.2 */ #define PCIE_MSG_CODE_PME_TURN_OFF 0x19
Quoted 7 lines
Quoted 7 lines
While you're at it, tweak the [1/5] comments to be:
/* Message Routing (r[2:0]); PCIe r6.0, sec 2.2.8 */ /* INTx Mechanism Messages; PCIe r6.0, sec 2.2.8.1 */
since the "Message Routing See: PCIe ..." comments are run together and need some punctuation between the text and the citation.
But please do add and tweak the comments.
Quoted 3 lines
Quoted 3 lines
With these,
Acked-by Bjorn Helgaas <[email protected]>
Still fine to add this :)
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
drivers/pci/pci.h +0
-0/* INTx Mechanism Messages See: PCIe r6.0, sec 2.2.8.1 */ #define PCIE_MSG_CODE_ASSERT_INTA 0x20#define PCIE_MSG_CODE_ASSERT_INTB 0x21Signature · 2 lines
-- 2.34.1Signature · 1 line
மணிவண்ணன் சதாசிவம்
Frank Li
maintainerPATCH v6 5/5 PCI: dwc: Add generic MSG TLP support for sending PME_Turn_Off when system suspend
In reply to Frank LiInstead of relying on the vendor specific implementations to send the PME_Turn_Off message, let's introduce a generic way of sending the message using the MSG TLP.
This is achieved by reserving a region for MSG TLP of size 'pci->region_align', at the end of the first IORESOURCE_MEM window of the host bridge. And then sending the PME_Turn_Off message during system suspend with the help of iATU.
The reserve space at end is a little bit better than alloc_resource() because the below reasons.
- alloc_resource() will allocate space at begin of IORESOURCE_MEM window. There will be a hole when first Endpoint Device (EP) try to alloc a bigger space then 'region_align' size.
- Keep EP device's IORESOURCE_MEM space unchange with/without this patch.
It should be noted that this generic implementation is optional for the glue drivers and can be overridden by a custom 'pme_turn_off' callback.
--- drivers/pci/controller/dwc/pcie-designware-host.c | 94 ++++++++++++++++++++++- drivers/pci/controller/dwc/pcie-designware.h | 3 + 2 files changed, 93 insertions(+), 4 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +90 -4
@@ -398,6 +398,31 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)return 0 ; } +static void dw_pcie_host_request_msg_tlp_res (struct dw_pcie_rp *pp) +{ +struct dw_pcie *pci =to_dw_pcie_from_pp (pp); +struct resource_entry *win; +struct resource *res; + + win =resource_list_first_type (&pp->bridge->windows,IORESOURCE_MEM ); +if (win) { + res =devm_kzalloc (pci->dev,sizeof (*res),GFP_KERNEL ); +if (!res) +return ; + +/* Reserve last region_align block as message TLP space */ + res->start = win->res->end - pci->region_align +1 ; + res->end = win->res->end; + res->name ="msg" ; + res->flags = win->res->flags |IORESOURCE_BUSY ; + +if (!devm_request_resource (pci->dev, win->res, res)) + pp->msg_res = res; +else +devm_kfree (pci->dev, res); + } +} +int dw_pcie_host_init (struct dw_pcie_rp *pp) {struct dw_pcie *pci =to_dw_pcie_from_pp (pp);
@@ -484,6 +509,16 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)dw_pcie_iatu_detect (pci); +/* +* Allocate the resource for MSG TLP before programming the iATU outbound window in +* dw_pcie_setup_rc(). Since the allocation depends on the value of 'region_align', this has +* to be done after dw_pcie_iatu_detect(). +* +* Glue driver need set use_atu_msg before dw_pcie_host_init() if want MSG TLP feature. +*/ +if (pp->use_atu_msg) +dw_pcie_host_request_msg_tlp_res (pp); + ret =dw_pcie_edma_detect (pci);if (ret) goto err_free_msi;
@@ -541,6 +576,11 @@ void dw_pcie_host_deinit(struct dw_pcie_rp *pp)dw_pcie_edma_remove (pci); +if (pp->msg_res) { +release_resource (pp->msg_res); +devm_kfree (pci->dev, pp->msg_res); + } +if (pp->has_msi_ctrl)dw_pcie_free_msi (pp);
@@ -702,6 +742,10 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) atu.pci_addr = entry->res->start - entry->offset; atu.size =resource_size (entry->res); +/* MSG TLB window resource reserve at one of end of IORESOURCE_MEM resource */ +if (pp->msg_res && pp->msg_res->parent == entry->res) + atu.size -=resource_size (pp->msg_res); + ret =dw_pcie_prog_outbound_atu (pci, &atu);if (ret) { dev_err(pci->dev, "Failed to set MEM range %pr\n",
@@ -733,6 +777,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); + pp->msg_atu_index = i; + i =0 ;resource_list_for_each_entry (entry, &pp->bridge->dma_ranges) {if (resource_type (entry->res) !=IORESOURCE_MEM )
@@ -838,11 +884,48 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp) }EXPORT_SYMBOL_GPL (dw_pcie_setup_rc); +/* Using message outbound ATU to send out PME_Turn_Off message for dwc PCIe controller */ +static int dw_pcie_pme_turn_off (struct dw_pcie *pci) +{ +struct dw_pcie_ob_atu_cfg atu = {0 }; +void __iomem *mem; +int ret; + +if (pci->num_ob_windows <= pci->pp.msg_atu_index) +return -EINVAL ; + +if (!pci->pp.msg_res) +return -EINVAL ; + + atu.code =PCIE_MSG_CODE_PME_TURN_OFF ; + atu.routing =PCIE_MSG_TYPE_R_BC ; + atu.type =PCIE_ATU_TYPE_MSG ; + atu.size =resource_size (pci->pp.msg_res); + atu.index = pci->pp.msg_atu_index; + + atu.cpu_addr = pci->pp.msg_res->start; + + ret =dw_pcie_prog_outbound_atu (pci, &atu); +if (ret) +return ret; + + mem =ioremap (atu.cpu_addr, pci->region_align); +if (!mem) +return -ENOMEM ; + +/* A dummy write is converted to a Msg TLP */ +writel (0 , mem); + +iounmap (mem); + +return 0 ; +} +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
@@ -854,10 +937,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_pme_turn_off (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.h +3 -0
@@ -341,6 +341,9 @@ struct dw_pcie_rp {struct pci_host_bridge *bridge;raw_spinlock_t lock;DECLARE_BITMAP (msi_irq_in_use,MAX_MSI_IRQS ); +bool use_atu_msg; +int msg_atu_index; +struct resource *msg_res; };struct dw_pcie_ep_ops {
Signature · 1 line
2.34.1
Re: [PATCH v6 5/5] PCI: dwc: Add generic MSG TLP support for sending PME_Turn_Off when system suspend
Quoted 9 lines · Frank Li
Instead of relying on the vendor specific implementations to send the
PME_Turn_Offmessage, let's introduce a generic way of sending the message using the MSG TLP.This is achieved by reserving a region for MSG TLP of size '
pci->region_align', at the end of the firstIORESOURCE_MEMwindow of the host bridge. And then sending thePME_Turn_Offmessage during system suspend with the help of iATU.
Quoted 7 lines
The reserve space at end is a little bit better than
alloc_resource()because the below reasons.
-alloc_resource()will allocate space at begin ofIORESOURCE_MEMwindow. There will be a hole when first Endpoint Device (EP) try to alloc a bigger space then 'region_align' size.
- Keep EP device'sIORESOURCE_MEMspace unchange with/without this patch.
I'd rewrite the above sentence as:
'The reason for reserving the MSG TLP region at the end of the IORESOURCE_MEM is to avoid generating holes in between. Because, when the region is allocated using allocate_resource(), memory will be allocated from the start of the window. Later, if memory gets allocated for an endpoint of size bigger than 'region_align', there will be a hole between MSG TLP region and endpoint memory.'
Quoted 20 lines
It should be noted that this generic implementation is optional for the glue drivers and can be overridden by a custom '
pme_turn_off' callback.Signed-off-by Frank Li <[email protected]>--- drivers/pci/controller/dwc/pcie-designware-host.c | 94 ++++++++++++++++++++++- drivers/pci/controller/dwc/pcie-designware.h | 3 + 2 files changed, 93 insertions(+), 4 deletions(-)drivers/pci/controller/dwc/pcie-designware-host.c +3
-0@@ -398,6 +398,31 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)return 0 ; } +static void dw_pcie_host_request_msg_tlp_res (struct dw_pcie_rp *pp) +{ +struct dw_pcie *pci =to_dw_pcie_from_pp (pp);
drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) · line 413
Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-host.c +10
-0+struct resource_entry *win; +struct resource *res; + + win =resource_list_first_type (&pp->bridge->windows,IORESOURCE_MEM ); +if (win) { + res =devm_kzalloc (pci->dev,sizeof (*res),GFP_KERNEL ); +if (!res) +return ; + +/* Reserve last region_align block as message TLP space */
/* * Allocate MSG TLP region of size 'region_align' at the end of * the host bridge window. */
drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) · line 422
Quoted 9 lines
drivers/pci/controller/dwc/pcie-designware-host.c +9
-0+ res->start = win->res->end - pci->region_align +1 ; + res->end = win->res->end; + res->name ="msg" ; + res->flags = win->res->flags |IORESOURCE_BUSY ; + +if (!devm_request_resource (pci->dev, win->res, res)) + pp->msg_res = res; +else +devm_kfree (pci->dev, res);
You are explicitly freeing 'msg_res' everywhere. So either drop devm_ or rely on devm to free the memory.
Quoted 7 lines
drivers/pci/controller/dwc/pcie-designware-host.c +3
-0+ } +} +int dw_pcie_host_init (struct dw_pcie_rp *pp) {struct dw_pcie *pci =to_dw_pcie_from_pp (pp);
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct dw_pcie_rp *pp) · line 515
Quoted 7 lines
drivers/pci/controller/dwc/pcie-designware-host.c +4
-0@@ -484,6 +509,16 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)dw_pcie_iatu_detect (pci); +/* +* Allocate the resource for MSG TLP before programming the iATU outbound window in +* dw_pcie_setup_rc(). Since the allocation depends on the value of 'region_align', this has +* to be done after dw_pcie_iatu_detect().
Please wrap the comments to 80 columns.
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct dw_pcie_rp *pp) · line 517
Quoted 2 lines
drivers/pci/controller/dwc/pcie-designware-host.c +2
-0+* +* Glue driver need set use_atu_msg before dw_pcie_host_init() if want MSG TLP feature.
How about,
* Glue drivers need to set 'use_atu_msg' before dw_pcie_host_init() to
* make use of the generic MSG TLP implementation.
Quoted 20 lines
drivers/pci/controller/dwc/pcie-designware-host.c +9
-0+*/ +if (pp->use_atu_msg) +dw_pcie_host_request_msg_tlp_res (pp); + ret =dw_pcie_edma_detect (pci);if (ret) goto err_free_msi;@@ -541,6 +576,11 @@ void dw_pcie_host_deinit(struct dw_pcie_rp *pp)dw_pcie_edma_remove (pci); +if (pp->msg_res) { +release_resource (pp->msg_res); +devm_kfree (pci->dev, pp->msg_res); + } +if (pp->has_msi_ctrl)dw_pcie_free_msi (pp);
drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) · line 745
Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1
-0@@ -702,6 +742,10 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) atu.pci_addr = entry->res->start - entry->offset; atu.size =resource_size (entry->res); +/* MSG TLB window resource reserve at one of end of IORESOURCE_MEM resource */
How about,
/* Adjust iATU size if MSG TLP region was allocated before */ if (pp->msg_res && pp->msg_res->parent == entry->res) atu.size = resource_size(entry->res) - resource_size(pp->msg_res); else atu.size = resource_size(entry->res);
Quoted 16 lines
drivers/pci/controller/dwc/pcie-designware-host.c +5
-0+if (pp->msg_res && pp->msg_res->parent == entry->res) + atu.size -=resource_size (pp->msg_res); + ret =dw_pcie_prog_outbound_atu (pci, &atu);if (ret) { dev_err(pci->dev, "Failed to set MEM range %pr\n",@@ -733,6 +777,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); + pp->msg_atu_index = i; + i =0 ;resource_list_for_each_entry (entry, &pp->bridge->dma_ranges) {if (resource_type (entry->res) !=IORESOURCE_MEM )
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 887
Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1
-0@@ -838,11 +884,48 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp) }EXPORT_SYMBOL_GPL (dw_pcie_setup_rc); +/* Using message outbound ATU to send out PME_Turn_Off message for dwc PCIe controller */
No need of this comment.
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 895
Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-host.c +8
-0+static int dw_pcie_pme_turn_off (struct dw_pcie *pci) +{ +struct dw_pcie_ob_atu_cfg atu = {0 }; +void __iomem *mem; +int ret; + +if (pci->num_ob_windows <= pci->pp.msg_atu_index) +return -EINVAL ;
return -ENOSPC;
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 898
Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware-host.c +3
-0+ +if (!pci->pp.msg_res) +return -EINVAL ;
return -ENOSPC;
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Frank Li
maintainerRe: [PATCH v6 5/5] PCI: dwc: Add generic MSG TLP support for sending PME_Turn_Off when system suspend
Quoted 84 lines · Manivannan Sadhasivam
Quoted 9 lines · Frank Li
Instead of relying on the vendor specific implementations to send the
PME_Turn_Offmessage, let's introduce a generic way of sending the message using the MSG TLP.This is achieved by reserving a region for MSG TLP of size '
pci->region_align', at the end of the firstIORESOURCE_MEMwindow of the host bridge. And then sending thePME_Turn_Offmessage during system suspend with the help of iATU.Quoted 7 lines
The reserve space at end is a little bit better than
alloc_resource()because the below reasons.
-alloc_resource()will allocate space at begin ofIORESOURCE_MEMwindow. There will be a hole when first Endpoint Device (EP) try to alloc a bigger space then 'region_align' size.
- Keep EP device'sIORESOURCE_MEMspace unchange with/without this patch.I'd rewrite the above sentence as:
'The reason for reserving the MSG TLP region at the end of the
IORESOURCE_MEMis to avoid generating holes in between. Because, when the region is allocated usingallocate_resource(), memory will be allocated from the start of the window. Later, if memory gets allocated for an endpoint of size bigger than 'region_align', there will be a hole between MSG TLP region and endpoint memory.'Quoted 20 lines
It should be noted that this generic implementation is optional for the glue drivers and can be overridden by a custom '
pme_turn_off' callback.Signed-off-by Frank Li <[email protected]>--- drivers/pci/controller/dwc/pcie-designware-host.c | 94 ++++++++++++++++++++++- drivers/pci/controller/dwc/pcie-designware.h | 3 + 2 files changed, 93 insertions(+), 4 deletions(-)drivers/pci/controller/dwc/pcie-designware-host.c +3
-0@@ -398,6 +398,31 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)return 0 ; } +static void dw_pcie_host_request_msg_tlp_res (struct dw_pcie_rp *pp) +{ +struct dw_pcie *pci =to_dw_pcie_from_pp (pp);drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) · line 413
Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-host.c +10
-0+struct resource_entry *win; +struct resource *res; + + win =resource_list_first_type (&pp->bridge->windows,IORESOURCE_MEM ); +if (win) { + res =devm_kzalloc (pci->dev,sizeof (*res),GFP_KERNEL ); +if (!res) +return ; + +/* Reserve last region_align block as message TLP space */ /* * Allocate MSG TLP region of size 'region_align' at the end of * the host bridge window. */drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) · line 422
Quoted 9 lines
drivers/pci/controller/dwc/pcie-designware-host.c +9
-0+ res->start = win->res->end - pci->region_align +1 ; + res->end = win->res->end; + res->name ="msg" ; + res->flags = win->res->flags |IORESOURCE_BUSY ; + +if (!devm_request_resource (pci->dev, win->res, res)) + pp->msg_res = res; +else +devm_kfree (pci->dev, res);You are explicitly freeing '
msg_res' everywhere. So either dropdevm_or rely on devm to free the memory.Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-host.c +3
-0+ } +} +int dw_pcie_host_init (struct dw_pcie_rp *pp) {struct dw_pcie *pci =to_dw_pcie_from_pp (pp);@@ -484,6 +509,16 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct dw_pcie_rp *pp) · line 515
Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware-host.c +4
-0dw_pcie_iatu_detect (pci); +/* +* Allocate the resource for MSG TLP before programming the iATU outbound window in +* dw_pcie_setup_rc(). Since the allocation depends on the value of 'region_align', this has +* to be done after dw_pcie_iatu_detect(). Please wrap the comments to 80 columns.
New code style is 100 columns. does comments still stick to 80 columns?
Quoted 86 lines
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct dw_pcie_rp *pp) · line 517
Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware-host.c +2
-0+* +* Glue driver need set use_atu_msg before dw_pcie_host_init() if want MSG TLP feature. How about,
* Glue drivers need to set '
use_atu_msg' beforedw_pcie_host_init()to
* make use of the generic MSG TLP implementation.Quoted 20 lines
drivers/pci/controller/dwc/pcie-designware-host.c +9
-0+*/ +if (pp->use_atu_msg) +dw_pcie_host_request_msg_tlp_res (pp); + ret =dw_pcie_edma_detect (pci);if (ret) goto err_free_msi;@@ -541,6 +576,11 @@ void dw_pcie_host_deinit(struct dw_pcie_rp *pp)dw_pcie_edma_remove (pci); +if (pp->msg_res) { +release_resource (pp->msg_res); +devm_kfree (pci->dev, pp->msg_res); + } +if (pp->has_msi_ctrl)dw_pcie_free_msi (pp);drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) · line 745
Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1
-0@@ -702,6 +742,10 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) atu.pci_addr = entry->res->start - entry->offset; atu.size =resource_size (entry->res); +/* MSG TLB window resource reserve at one of end of IORESOURCE_MEM resource */ How about,
/* Adjust iATU size if MSG TLP region was allocated before */ if (pp->msg_res && pp->msg_res->parent == entry->res) atu.size = resource_size(entry->res) - resource_size(pp->msg_res); else atu.size = resource_size(entry->res);Quoted 16 lines
drivers/pci/controller/dwc/pcie-designware-host.c +5
-0+if (pp->msg_res && pp->msg_res->parent == entry->res) + atu.size -=resource_size (pp->msg_res); + ret =dw_pcie_prog_outbound_atu (pci, &atu);if (ret) { dev_err(pci->dev, "Failed to set MEM range %pr\n",@@ -733,6 +777,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); + pp->msg_atu_index = i; + i =0 ;resource_list_for_each_entry (entry, &pp->bridge->dma_ranges) {if (resource_type (entry->res) !=IORESOURCE_MEM )drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 887
Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1
-0@@ -838,11 +884,48 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp) }EXPORT_SYMBOL_GPL (dw_pcie_setup_rc); +/* Using message outbound ATU to send out PME_Turn_Off message for dwc PCIe controller */ No need of this comment.
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 895
Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-host.c +8
-0+static int dw_pcie_pme_turn_off (struct dw_pcie *pci) +{ +struct dw_pcie_ob_atu_cfg atu = {0 }; +void __iomem *mem; +int ret; + +if (pci->num_ob_windows <= pci->pp.msg_atu_index) +return -EINVAL ;return -ENOSPC;drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 898
Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware-host.c +3
-0+ +if (!pci->pp.msg_res) +return -EINVAL ;return -ENOSPC;- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Re: [PATCH v6 5/5] PCI: dwc: Add generic MSG TLP support for sending PME_Turn_Off when system suspend
Quoted 87 lines · Frank Li
Quoted 86 lines · Manivannan Sadhasivam
Quoted 9 lines · Frank Li
Instead of relying on the vendor specific implementations to send the
PME_Turn_Offmessage, let's introduce a generic way of sending the message using the MSG TLP.This is achieved by reserving a region for MSG TLP of size '
pci->region_align', at the end of the firstIORESOURCE_MEMwindow of the host bridge. And then sending thePME_Turn_Offmessage during system suspend with the help of iATU.Quoted 7 lines
The reserve space at end is a little bit better than
alloc_resource()because the below reasons.
-alloc_resource()will allocate space at begin ofIORESOURCE_MEMwindow. There will be a hole when first Endpoint Device (EP) try to alloc a bigger space then 'region_align' size.
- Keep EP device'sIORESOURCE_MEMspace unchange with/without this patch.I'd rewrite the above sentence as:
'The reason for reserving the MSG TLP region at the end of the
IORESOURCE_MEMis to avoid generating holes in between. Because, when the region is allocated usingallocate_resource(), memory will be allocated from the start of the window. Later, if memory gets allocated for an endpoint of size bigger than 'region_align', there will be a hole between MSG TLP region and endpoint memory.'Quoted 20 lines
It should be noted that this generic implementation is optional for the glue drivers and can be overridden by a custom '
pme_turn_off' callback.Signed-off-by Frank Li <[email protected]>--- drivers/pci/controller/dwc/pcie-designware-host.c | 94 ++++++++++++++++++++++- drivers/pci/controller/dwc/pcie-designware.h | 3 + 2 files changed, 93 insertions(+), 4 deletions(-)drivers/pci/controller/dwc/pcie-designware-host.c +3
-0@@ -398,6 +398,31 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp)return 0 ; } +static void dw_pcie_host_request_msg_tlp_res (struct dw_pcie_rp *pp) +{ +struct dw_pcie *pci =to_dw_pcie_from_pp (pp);drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) · line 413
Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-host.c +10
-0+struct resource_entry *win; +struct resource *res; + + win =resource_list_first_type (&pp->bridge->windows,IORESOURCE_MEM ); +if (win) { + res =devm_kzalloc (pci->dev,sizeof (*res),GFP_KERNEL ); +if (!res) +return ; + +/* Reserve last region_align block as message TLP space */ /* * Allocate MSG TLP region of size 'region_align' at the end of * the host bridge window. */drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) · line 422
Quoted 9 lines
drivers/pci/controller/dwc/pcie-designware-host.c +9
-0+ res->start = win->res->end - pci->region_align +1 ; + res->end = win->res->end; + res->name ="msg" ; + res->flags = win->res->flags |IORESOURCE_BUSY ; + +if (!devm_request_resource (pci->dev, win->res, res)) + pp->msg_res = res; +else +devm_kfree (pci->dev, res);You are explicitly freeing '
msg_res' everywhere. So either dropdevm_or rely on devm to free the memory.Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-host.c +3
-0+ } +} +int dw_pcie_host_init (struct dw_pcie_rp *pp) {struct dw_pcie *pci =to_dw_pcie_from_pp (pp);@@ -484,6 +509,16 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)dw_pcie_iatu_detect (pci);
Quoted 9 lines
Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct dw_pcie_rp *pp) · line 515
Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +4
-0+/* +* Allocate the resource for MSG TLP before programming the iATU outbound window in +* dw_pcie_setup_rc(). Since the allocation depends on the value of 'region_align', this has +* to be done after dw_pcie_iatu_detect(). Please wrap the comments to 80 columns.
New code style is 100 columns. does comments still stick to 80 columns?
That's only applicable for code and not comments. I also learned that some time back.
- Mani
Quoted 86 lines
Quoted 86 lines
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct dw_pcie_rp *pp) · line 517
Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware-host.c +2
-0+* +* Glue driver need set use_atu_msg before dw_pcie_host_init() if want MSG TLP feature. How about,
* Glue drivers need to set '
use_atu_msg' beforedw_pcie_host_init()to
* make use of the generic MSG TLP implementation.Quoted 20 lines
drivers/pci/controller/dwc/pcie-designware-host.c +9
-0+*/ +if (pp->use_atu_msg) +dw_pcie_host_request_msg_tlp_res (pp); + ret =dw_pcie_edma_detect (pci);if (ret) goto err_free_msi;@@ -541,6 +576,11 @@ void dw_pcie_host_deinit(struct dw_pcie_rp *pp)dw_pcie_edma_remove (pci); +if (pp->msg_res) { +release_resource (pp->msg_res); +devm_kfree (pci->dev, pp->msg_res); + } +if (pp->has_msi_ctrl)dw_pcie_free_msi (pp);drivers/pci/controller/dwc/pcie-designware-host.c static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) · line 745
Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1
-0@@ -702,6 +742,10 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp) atu.pci_addr = entry->res->start - entry->offset; atu.size =resource_size (entry->res); +/* MSG TLB window resource reserve at one of end of IORESOURCE_MEM resource */ How about,
/* Adjust iATU size if MSG TLP region was allocated before */ if (pp->msg_res && pp->msg_res->parent == entry->res) atu.size = resource_size(entry->res) - resource_size(pp->msg_res); else atu.size = resource_size(entry->res);Quoted 16 lines
drivers/pci/controller/dwc/pcie-designware-host.c +5
-0+if (pp->msg_res && pp->msg_res->parent == entry->res) + atu.size -=resource_size (pp->msg_res); + ret =dw_pcie_prog_outbound_atu (pci, &atu);if (ret) { dev_err(pci->dev, "Failed to set MEM range %pr\n",@@ -733,6 +777,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); + pp->msg_atu_index = i; + i =0 ;resource_list_for_each_entry (entry, &pp->bridge->dma_ranges) {if (resource_type (entry->res) !=IORESOURCE_MEM )drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 887
Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1
-0@@ -838,11 +884,48 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp) }EXPORT_SYMBOL_GPL (dw_pcie_setup_rc); +/* Using message outbound ATU to send out PME_Turn_Off message for dwc PCIe controller */ No need of this comment.
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 895
Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-host.c +8
-0+static int dw_pcie_pme_turn_off (struct dw_pcie *pci) +{ +struct dw_pcie_ob_atu_cfg atu = {0 }; +void __iomem *mem; +int ret; + +if (pci->num_ob_windows <= pci->pp.msg_atu_index) +return -EINVAL ;return -ENOSPC;drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_setup_rc(struct dw_pcie_rp *pp) · line 898
Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware-host.c +3
-0+ +if (!pci->pp.msg_res) +return -EINVAL ;return -ENOSPC;- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Re: [PATCH v6 5/5] PCI: dwc: Add generic MSG TLP support for sending PME_Turn_Off when system suspend
In reply to Frank LiQuoted 10 lines · Frank Li
Quoted 7 lines · Manivannan Sadhasivam
drivers/pci/controller/dwc/pcie-designware-host.c int dw_pcie_host_init(struct dw_pcie_rp *pp) · line 515
Quoted 4 lines · Frank Li
drivers/pci/controller/dwc/pcie-designware-host.c +4
-0+/* +* Allocate the resource for MSG TLP before programming the iATU outbound window in +* dw_pcie_setup_rc(). Since the allocation depends on the value of 'region_align', this has +* to be done after dw_pcie_iatu_detect(). Please wrap the comments to 80 columns.
New code style is 100 columns. does comments still stick to 80 columns?
I care more about files being consistent internally than I do about adhering to a new 100 column rule.
With very few exceptions, pcie-designware-host.c fits in 80 columns. I think there's no point in adding a comment using 100 columns. That leadds to either a window sized to accommodate 100 columns, where 20 columns are wasted for all the existing code and comments, or a window sized for 80 columns, where the new comment looks ugly. Neither is attractive.
Bjorn