Skip to content

Commit 9a277fa

Browse files
jannaumarcan
authored andcommitted
dcp/afk: Retry harder to init afk endpoints/services
Extend start_interface() with the number of expected services so it can stop when all services are initialized. Fixes failed display init on some devices in stage 1 due to a too slow IOP which does not manage to send service announce messages in 20 mailbox / ringbuffer query operations. Proper fix for this is to let the endpoint implementations drive the initialization via afk_epic_work() until the expected services are found. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 1ea7342 commit 9a277fa

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
lines changed

src/afk.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,10 @@ static const afk_epic_service_ops_t *afk_match_service(afk_epic_ep_t *ep, const
705705
return NULL;
706706
}
707707

708-
int afk_epic_start_interface(afk_epic_ep_t *epic, void *intf, size_t txsize, size_t rxsize)
708+
int afk_epic_start_interface(afk_epic_ep_t *epic, void *intf, int expected, size_t txsize,
709+
size_t rxsize)
709710
{
710-
int channels = 0;
711+
int services = 0;
711712
struct afk_qe *msg;
712713
struct epic_announce *announce;
713714

@@ -721,7 +722,7 @@ int afk_epic_start_interface(afk_epic_ep_t *epic, void *intf, size_t txsize, siz
721722
break;
722723
}
723724

724-
for (int tries = 0; tries < 20; tries += 1) {
725+
for (int tries = 0; tries < 500; tries += 1) {
725726
s64 epic_unit = -1;
726727
char *epic_name = NULL;
727728
char *epic_class = NULL;
@@ -810,11 +811,12 @@ int afk_epic_start_interface(afk_epic_ep_t *epic, void *intf, size_t txsize, siz
810811
free(epic_name);
811812
free(epic_class);
812813

813-
channels++;
814814
afk_epic_rx_ack(epic);
815+
if (++services >= expected)
816+
break;
815817
}
816818

817-
if (!channels) {
819+
if (!services) {
818820
printf("AFK[ep:%02x]: too many unexpected messages, giving up\n", epic->ep);
819821
return -1;
820822
}
@@ -829,7 +831,7 @@ int afk_epic_start_interface(afk_epic_ep_t *epic, void *intf, size_t txsize, siz
829831
return -1;
830832
}
831833

832-
dprintf("AFK[ep:%02x]: started interface with %d services\n", epic->ep, channels);
834+
dprintf("AFK[ep:%02x]: started interface with %d services\n", epic->ep, services);
833835

834836
return 0;
835837
}

src/afk.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ afk_epic_ep_t *afk_epic_start_ep(afk_epic_t *afk, int endpoint, const afk_epic_s
4343
int afk_epic_shutdown_ep(afk_epic_ep_t *epic);
4444

4545
int afk_epic_work(afk_epic_t *afk, int endpoint);
46-
int afk_epic_start_interface(afk_epic_ep_t *epic, void *intf, size_t insize, size_t outsize);
46+
int afk_epic_start_interface(afk_epic_ep_t *epic, void *intf, int expected, size_t insize,
47+
size_t outsize);
4748
int afk_epic_command(afk_epic_ep_t *epic, int channel, u16 sub_type, void *txbuf, size_t txsize,
4849
void *rxbuf, size_t *rxsize);
4950

src/dcp/dpav_ep.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include "../types.h"
1515
#include "../utils.h"
1616

17-
#define DCP_DPAV_ENDPOINT 0x24
18-
#define TXBUF_LEN 0x4000
19-
#define RXBUF_LEN 0x4000
17+
#define DCP_DPAV_ENDPOINT 0x24
18+
#define DCP_DPAV_NUM_SERVICES 4
19+
20+
#define TXBUF_LEN 0x4000
21+
#define RXBUF_LEN 0x4000
2022

2123
typedef struct dcp_dpav_if {
2224
afk_epic_ep_t *epic;
@@ -53,7 +55,8 @@ dcp_dpav_if_t *dcp_dpav_init(dcp_dev_t *dcp)
5355
goto err_free;
5456
}
5557

56-
int err = afk_epic_start_interface(dpav->epic, dpav, TXBUF_LEN, RXBUF_LEN);
58+
int err =
59+
afk_epic_start_interface(dpav->epic, dpav, DCP_DPAV_NUM_SERVICES, TXBUF_LEN, RXBUF_LEN);
5760
if (err < 0) {
5861
printf("dpav: failed to initialize DPAV interface\n");
5962
goto err_shutdown;

src/dcp/dptx_port_ep.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
#include "../types.h"
1414
#include "../utils.h"
1515

16-
#define DCP_DPTX_PORT_ENDPOINT 0x2a
17-
#define TXBUF_LEN 0x4000
18-
#define RXBUF_LEN 0x4000
16+
#define DCP_DPTX_PORT_ENDPOINT 0x2a
17+
#define DCP_DPTX_PORT_NUM_SERVICES 2
18+
19+
#define TXBUF_LEN 0x4000
20+
#define RXBUF_LEN 0x4000
1921

2022
struct dcpdptx_connection_cmd {
2123
u32 unk;
@@ -557,7 +559,8 @@ dcp_dptx_if_t *dcp_dptx_init(dcp_dev_t *dcp)
557559
goto err_free;
558560
}
559561

560-
int err = afk_epic_start_interface(dptx->epic, dptx, TXBUF_LEN, RXBUF_LEN);
562+
int err = afk_epic_start_interface(dptx->epic, dptx, DCP_DPTX_PORT_NUM_SERVICES, TXBUF_LEN,
563+
RXBUF_LEN);
561564
if (err < 0) {
562565
printf("dcp-dptx: failed to initialize DPTXRemotePort interface\n");
563566
goto err_shutdown;

src/dcp/system_ep.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include "../types.h"
1515
#include "../utils.h"
1616

17-
#define DCP_SYSTEM_ENDPOINT 0x20
18-
#define TXBUF_LEN 0x4000
19-
#define RXBUF_LEN 0x4000
17+
#define DCP_SYSTEM_ENDPOINT 0x20
18+
#define DCP_SYSTEM_NUM_SERVICES 2
19+
20+
#define TXBUF_LEN 0x4000
21+
#define RXBUF_LEN 0x4000
2022

2123
typedef struct dcp_system_if {
2224
afk_epic_ep_t *epic;
@@ -121,7 +123,8 @@ dcp_system_if_t *dcp_system_init(dcp_dev_t *dcp)
121123
goto err_free;
122124
}
123125

124-
int err = afk_epic_start_interface(system->epic, system, TXBUF_LEN, RXBUF_LEN);
126+
int err = afk_epic_start_interface(system->epic, system, DCP_SYSTEM_NUM_SERVICES, TXBUF_LEN,
127+
RXBUF_LEN);
125128

126129
if (err < 0 || !system->sys_service) {
127130
printf("dcp-system: failed to initialize system-service\n");

src/dcp_iboot.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include "string.h"
99
#include "utils.h"
1010

11-
#define DCP_IBOOT_ENDPOINT 0x23
11+
#define DCP_IBOOT_ENDPOINT 0x23
12+
#define DCP_IBOOT_NUM_SERVICES 1
1213

1314
#define TXBUF_LEN 0x4000
1415
#define RXBUF_LEN 0x4000
@@ -137,7 +138,8 @@ dcp_iboot_if_t *dcp_ib_init(dcp_dev_t *dcp)
137138
goto err_free;
138139
}
139140

140-
int err = afk_epic_start_interface(iboot->epic, iboot, TXBUF_LEN, RXBUF_LEN);
141+
int err =
142+
afk_epic_start_interface(iboot->epic, iboot, DCP_IBOOT_NUM_SERVICES, TXBUF_LEN, RXBUF_LEN);
141143

142144
if (err < 0 || !iboot->enabled) {
143145
printf("dcp-iboot: failed to initialize disp0 service\n");

0 commit comments

Comments
 (0)