From patchwork Thu Apr 9 21:47:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 46986 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3172C21416 for ; Thu, 9 Apr 2015 21:47:42 +0000 (UTC) Received: by lamp14 with SMTP id p14sf79216lam.3 for ; Thu, 09 Apr 2015 14:47:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=MiX9O9IbPeP7sVFxwoSjfTJcrQ2AzoWLHgIdUN6aHpU=; b=hiXixZKmhosZFH9sNYxSYr2pI+OXPbJBChp2omshLrhc93/oIeRHdsJUcXx3raeNDs 5oZnNVZyy07fUJ2vIbyTsK9/SkS90Fdlu0DFN0YGE/pwXw1h/4hR+1/pGQPMj8q//9Pu NnJ7utFScWSE3yQu4ZXVThEk+ytjh5hFHBQQG0qCMYC+MIZ0JoVbgypCwOKMQnmsF18Q qE7JHYw4KRQrWZCmq+OUDatd1+CU5KAO44Rv/WA3Y+mwGRnM9/1vIBdWVEWcJQ4fXhBG TGIQbef21vQttaMZtA9SpwqU8B64c/UGhHOKVfWEpECARlrnT+V9fOjkq7JLW1EYKACY AAXw== X-Gm-Message-State: ALoCoQnFCVAy2tVNviHssPMqOBLXydOC1F2EwXaqpuc8Ir7uyZHuJRPjhR3s7dnrErf7qvYm4hkR X-Received: by 10.112.142.1 with SMTP id rs1mr6234520lbb.19.1428616061171; Thu, 09 Apr 2015 14:47:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.197.34 with SMTP id ir2ls364864lac.84.gmail; Thu, 09 Apr 2015 14:47:41 -0700 (PDT) X-Received: by 10.112.125.193 with SMTP id ms1mr30387495lbb.31.1428616061025; Thu, 09 Apr 2015 14:47:41 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id aa5si3376lbc.64.2015.04.09.14.47.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 14:47:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by layy10 with SMTP id y10so403180lay.0 for ; Thu, 09 Apr 2015 14:47:40 -0700 (PDT) X-Received: by 10.112.184.70 with SMTP id es6mr29475302lbc.117.1428616060841; Thu, 09 Apr 2015 14:47:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.67.65 with SMTP id l1csp724358lbt; Thu, 9 Apr 2015 14:47:39 -0700 (PDT) X-Received: by 10.68.132.169 with SMTP id ov9mr58621036pbb.109.1428616057882; Thu, 09 Apr 2015 14:47:37 -0700 (PDT) Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com. [209.85.220.48]) by mx.google.com with ESMTPS id 1si23223554pdh.152.2015.04.09.14.47.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 14:47:37 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.48 as permitted sender) client-ip=209.85.220.48; Received: by pabsx10 with SMTP id sx10so544735pab.3 for ; Thu, 09 Apr 2015 14:47:37 -0700 (PDT) X-Received: by 10.70.130.198 with SMTP id og6mr9757543pdb.153.1428616056976; Thu, 09 Apr 2015 14:47:36 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id x3sm14670pdo.0.2015.04.09.14.47.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Apr 2015 14:47:36 -0700 (PDT) From: John Stultz To: projectara-software-dev Cc: Johan Hovold , Alex Elder , Greg Kroah-Hartman , John Stultz Subject: [PATCH] gbsim: update bridge protocol Date: Thu, 9 Apr 2015 14:47:28 -0700 Message-Id: <1428616048-25079-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Johan Hovold Store the cport id in the pad bytes of the message header rather than prepending it to the data buffer. This protocol change has been done to address DMA and alignment issues in the AP without adding additional overhead. Cc: Alex Elder Cc: Greg Kroah-Hartman CC: Johan Hovold Signed-off-by: Johan Hovold [jstultz: rebased & minor fixups to merge w/ i2s changes] Signed-off-by: John Stultz --- cport.c | 18 ++++++++++++++---- gbsim.h | 5 ----- gpio.c | 45 ++++++++++++++++++++++----------------------- i2c.c | 22 +++++++++++----------- i2s.c | 40 +++++++++++++++++++--------------------- pwm.c | 31 ++++++++++++++++--------------- 6 files changed, 82 insertions(+), 79 deletions(-) diff --git a/cport.c b/cport.c index d339c9a..70f2a91 100644 --- a/cport.c +++ b/cport.c @@ -75,19 +75,29 @@ static void exec_subdev_handler(unsigned int id, __u8 *rbuf, size_t size) void cport_handler(__u8 *rbuf, size_t size) { - /* FIXME pass cport_msg directly? */ - struct cport_msg *cmsg = (struct cport_msg *)rbuf; + struct op_header *hdr = (void *)rbuf; unsigned int id; - id = cmsg->cport; + if (size < sizeof(*hdr)) { + gbsim_error("short message received\n"); + return; + } + + /* + * Retreive and clear the cport id stored in the header pad bytes. + */ + id = hdr->pad[1] << 8 | hdr->pad[0]; + hdr->pad[0] = 0; + hdr->pad[1] = 0; /* FIXME: can identify module from our cport connection */ gbsim_debug("AP -> Module %d CPort %d %s request\n ", cport_to_module_id(id), id, get_protocol(id)); + if (verbose) - gbsim_dump(cmsg->data, size - 1); + gbsim_dump(rbuf, size); exec_subdev_handler(id, rbuf, size); diff --git a/gbsim.h b/gbsim.h index 48ee400..f4dcc84 100644 --- a/gbsim.h +++ b/gbsim.h @@ -53,11 +53,6 @@ extern struct gbsim_info info; #define PROTOCOL_STATUS_RETRY 0x04 #define PROTOCOL_STATUS_BAD 0xff -struct cport_msg { - __u8 cport; - __u8 data[0]; -}; - struct op_header { __le16 size; __le16 id; diff --git a/gpio.c b/gpio.c index a071018..d9005e0 100644 --- a/gpio.c +++ b/gpio.c @@ -45,20 +45,20 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) struct op_header *oph; char *tbuf; struct op_msg *op_req, *op_rsp; - struct cport_msg *cport_req, *cport_rsp; tbuf = malloc(4 * 1024); if (!tbuf) { gbsim_error("failed to allocate gpio handler tx buf\n"); return; } - cport_req = (struct cport_msg *)rbuf; - op_req = (struct op_msg *)cport_req->data; - cport_rsp = (struct cport_msg *)tbuf; - cport_rsp->cport = cport; - op_rsp = (struct op_msg *)cport_rsp->data; + op_req = (struct op_msg *)rbuf; + op_rsp = (struct op_msg *)tbuf; oph = (struct op_header *)&op_req->header; - + + /* Store the cport id in the header pad bytes */ + op_rsp->header.pad[0] = cport & 0xff; + op_rsp->header.pad[1] = (cport >> 8) & 0xff; + switch (oph->type) { case GB_GPIO_TYPE_PROTOCOL_VERSION: op_rsp->header.size = sizeof(struct op_header) + @@ -72,7 +72,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, op_rsp->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_LINE_COUNT: op_rsp->header.size = sizeof(struct op_header) + @@ -85,7 +85,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, op_rsp->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_ACTIVATE: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -96,7 +96,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->gpio_act_req.which); if (verbose) gbsim_dump((__u8 *)op_req, op_req->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_DEACTIVATE: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -107,7 +107,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->gpio_deact_req.which); if (verbose) gbsim_dump((__u8 *)op_req, op_req->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_GET_DIRECTION: op_rsp->header.size = sizeof(struct op_header) + @@ -123,7 +123,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->gpio_get_dir_req.which, op_rsp->gpio_get_dir_rsp.direction); if (verbose) gbsim_dump((__u8 *)op_rsp, op_rsp->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_DIRECTION_IN: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -138,7 +138,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) libsoc_gpio_set_direction(gpios[op_req->gpio_dir_output_req.which], INPUT); else gpio_dir[op_req->gpio_dir_output_req.which] = 0; - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_DIRECTION_OUT: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -153,7 +153,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) libsoc_gpio_set_direction(gpios[op_req->gpio_dir_output_req.which], OUTPUT); else gpio_dir[op_req->gpio_dir_output_req.which] = 1; - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_GET_VALUE: op_rsp->header.size = sizeof(struct op_header) + @@ -169,7 +169,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->gpio_get_val_req.which, op_rsp->gpio_get_val_rsp.value); if (verbose) gbsim_dump((__u8 *)op_rsp, op_rsp->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_SET_VALUE: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -182,7 +182,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) gbsim_dump((__u8 *)op_req, op_req->header.size); if (bbb_backend) libsoc_gpio_set_level(gpios[op_req->gpio_set_val_req.which], op_req->gpio_set_val_req.value); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_SET_DEBOUNCE: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -193,7 +193,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->gpio_set_db_req.which, op_req->gpio_set_db_req.usec); if (verbose) gbsim_dump((__u8 *)op_req, op_req->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_IRQ_TYPE: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -205,7 +205,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) op_req->gpio_irq_type_req.type); if (verbose) gbsim_dump((__u8 *)op_req, op_req->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_IRQ_ACK: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -216,7 +216,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport, cport_to_module_id(cport)); if (verbose) gbsim_dump((__u8 *)op_req, op_req->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_IRQ_MASK: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -227,7 +227,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport, cport_to_module_id(cport)); if (verbose) gbsim_dump((__u8 *)op_req, op_req->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); break; case GB_GPIO_TYPE_IRQ_UNMASK: op_rsp->header.size = sizeof(struct op_header) + 0; @@ -238,7 +238,7 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) cport, cport_to_module_id(cport)); if (verbose) gbsim_dump((__u8 *)op_req, op_req->header.size); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, op_rsp->header.size); #define TEST_HACK #ifdef TEST_HACK op_req->header.size = sizeof(struct op_header) + 1; @@ -246,10 +246,9 @@ void gpio_handler(unsigned int cport, __u8 *rbuf, size_t size) op_req->header.type = GB_GPIO_TYPE_IRQ_EVENT; op_req->header.result = 0; op_req->gpio_irq_event_req.which = 1; - cport_req->cport = cport; gbsim_debug("Module %d -> AP CPort %d GPIO protocol IRQ event request\n ", cport_to_module_id(cport), cport); - write(cport_in, cport_req, op_req->header.size + 1); + write(cport_in, op_req, op_req->header.size); #endif break; case OP_RESPONSE | GB_GPIO_TYPE_IRQ_EVENT: diff --git a/i2c.c b/i2c.c index 4cc840e..69f35ce 100644 --- a/i2c.c +++ b/i2c.c @@ -34,7 +34,6 @@ void i2c_handler(unsigned int cport, __u8 *rbuf, size_t size) struct op_header *oph; char *tbuf; struct op_msg *op_req, *op_rsp; - struct cport_msg *cport_req, *cport_rsp; int i, op_count; __u8 *write_data; bool read_op; @@ -47,12 +46,13 @@ void i2c_handler(unsigned int cport, __u8 *rbuf, size_t size) gbsim_error("failed to allocate i2c handler tx buf\n"); return; } - cport_req = (struct cport_msg *)rbuf; - op_req = (struct op_msg *)cport_req->data; - cport_rsp = (struct cport_msg *)tbuf; - cport_rsp->cport = cport; - op_rsp = (struct op_msg *)cport_rsp->data; + op_req = (struct op_msg *)rbuf; + op_rsp = (struct op_msg *)tbuf; oph = (struct op_header *)&op_req->header; + + /* Store the cport id in the header pad bytes */ + op_rsp->header.pad[0] = cport & 0xff; + op_rsp->header.pad[1] = (cport >> 8) & 0xff; switch (oph->type) { case OP_I2C_PROTOCOL_VERSION: @@ -68,7 +68,7 @@ void i2c_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case OP_I2C_PROTOCOL_FUNCTIONALITY: sz = sizeof(struct op_header) + @@ -82,7 +82,7 @@ void i2c_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case OP_I2C_PROTOCOL_TIMEOUT: sz = sizeof(struct op_header) + 0; @@ -94,7 +94,7 @@ void i2c_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case OP_I2C_PROTOCOL_RETRIES: sz = sizeof(struct op_header) + 0; @@ -106,7 +106,7 @@ void i2c_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case OP_I2C_PROTOCOL_TRANSFER: op_count = le16toh(op_req->i2c_xfer_req.op_count); @@ -174,7 +174,7 @@ void i2c_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; default: diff --git a/i2s.c b/i2s.c index 9616b22..aa18fa0 100644 --- a/i2s.c +++ b/i2s.c @@ -26,7 +26,6 @@ void i2s_mgmt_handler(unsigned int cport, __u8 *rbuf, size_t size) struct op_header *oph; char *tbuf; struct op_msg *op_req, *op_rsp; - struct cport_msg *cport_req, *cport_rsp; struct gb_i2s_mgmt_configuration *conf; size_t sz; @@ -35,13 +34,14 @@ void i2s_mgmt_handler(unsigned int cport, __u8 *rbuf, size_t size) gbsim_error("failed to allocate i2s handler tx buf\n"); return; } - cport_req = (struct cport_msg *)rbuf; - op_req = (struct op_msg *)cport_req->data; - cport_rsp = (struct cport_msg *)tbuf; - cport_rsp->cport = cport; - op_rsp = (struct op_msg *)cport_rsp->data; + op_req = (struct op_msg *)rbuf; + op_rsp = (struct op_msg *)tbuf; oph = (struct op_header *)&op_req->header; + /* Store the cport id in the header pad bytes */ + op_rsp->header.pad[0] = cport & 0xff; + op_rsp->header.pad[1] = (cport >> 8) & 0xff; + switch (oph->type) { case GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS: sz = sizeof(struct op_header) + @@ -73,13 +73,11 @@ void i2s_mgmt_handler(unsigned int cport, __u8 *rbuf, size_t size) conf->ll_wclk_rx_edge = GB_I2S_MGMT_EDGE_RISING; conf->ll_data_offset = 1; - - gbsim_debug("Module %d -> AP CPort %d I2S GET_CONFIGURATION response\n ", cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_I2S_MGMT_TYPE_SET_CONFIGURATION: sz = sizeof(struct op_header); @@ -93,7 +91,7 @@ void i2s_mgmt_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE: sz = sizeof(struct op_header); @@ -107,7 +105,7 @@ void i2s_mgmt_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_I2S_MGMT_TYPE_SET_START_DELAY: sz = sizeof(struct op_header); @@ -121,7 +119,7 @@ void i2s_mgmt_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_I2S_MGMT_TYPE_ACTIVATE_CPORT: sz = sizeof(struct op_header); @@ -135,7 +133,7 @@ void i2s_mgmt_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT: sz = sizeof(struct op_header); @@ -149,7 +147,7 @@ void i2s_mgmt_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; default: gbsim_error("i2s mgmt operation type %02x not supported\n", oph->type); @@ -164,7 +162,6 @@ void i2s_data_handler(unsigned int cport, __u8 *rbuf, size_t size) struct op_header *oph; char *tbuf; struct op_msg *op_req, *op_rsp; - struct cport_msg *cport_req, *cport_rsp; size_t sz; tbuf = malloc(4 * 1024); @@ -172,13 +169,14 @@ void i2s_data_handler(unsigned int cport, __u8 *rbuf, size_t size) gbsim_error("failed to allocate i2s handler tx buf\n"); return; } - cport_req = (struct cport_msg *)rbuf; - op_req = (struct op_msg *)cport_req->data; - cport_rsp = (struct cport_msg *)tbuf; - cport_rsp->cport = cport; - op_rsp = (struct op_msg *)cport_rsp->data; + op_req = (struct op_msg *)rbuf; + op_rsp = (struct op_msg *)tbuf; oph = (struct op_header *)&op_req->header; + /* Store the cport id in the header pad bytes */ + op_rsp->header.pad[0] = cport & 0xff; + op_rsp->header.pad[1] = (cport >> 8) & 0xff; + switch (oph->type) { case GB_I2S_DATA_TYPE_SEND_DATA: sz = sizeof(struct op_header); @@ -192,7 +190,7 @@ void i2s_data_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; default: gbsim_error("i2s data operation type %02x not supported\n", oph->type); diff --git a/pwm.c b/pwm.c index ed16cab..daac695 100644 --- a/pwm.c +++ b/pwm.c @@ -37,7 +37,6 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) struct op_header *oph; char *tbuf; struct op_msg *op_req, *op_rsp; - struct cport_msg *cport_req, *cport_rsp; size_t sz; __u32 duty; __u32 period; @@ -47,13 +46,15 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) gbsim_error("failed to allocate i2c handler tx buf\n"); return; } - cport_req = (struct cport_msg *)rbuf; - op_req = (struct op_msg *)cport_req->data; - cport_rsp = (struct cport_msg *)tbuf; - cport_rsp->cport = cport; - op_rsp = (struct op_msg *)cport_rsp->data; + + op_req = (struct op_msg *)rbuf; + op_rsp = (struct op_msg *)tbuf; oph = (struct op_header *)&op_req->header; - + + /* Store the cport id in the header pad bytes */ + op_rsp->header.pad[0] = cport & 0xff; + op_rsp->header.pad[1] = (cport >> 8) & 0xff; + switch (oph->type) { case GB_PWM_TYPE_PROTOCOL_VERSION: sz = sizeof(struct op_header) + @@ -68,7 +69,7 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_PWM_TYPE_PWM_COUNT: sz = sizeof(struct op_header) + sizeof(struct pwm_count_rsp); @@ -81,7 +82,7 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_PWM_TYPE_ACTIVATE: sz = sizeof(struct op_header) + 0; @@ -93,7 +94,7 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->pwm_act_req.which); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_PWM_TYPE_DEACTIVATE: sz = sizeof(struct op_header) + 0; @@ -105,7 +106,7 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->pwm_deact_req.which); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_PWM_TYPE_CONFIG: sz = sizeof(struct op_header) + 0; @@ -123,7 +124,7 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->pwm_cfg_req.which, duty, period); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, op_rsp->header.size + 1); + write(cport_in, op_rsp, sz); break; case GB_PWM_TYPE_POLARITY: sz = sizeof(struct op_header) + 0; @@ -144,7 +145,7 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) op_req->pwm_pol_req.polarity ? "inverse" : "normal"); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_PWM_TYPE_ENABLE: sz = sizeof(struct op_header) + 0; @@ -159,7 +160,7 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->pwm_enb_req.which); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; case GB_PWM_TYPE_DISABLE: sz = sizeof(struct op_header) + 0; @@ -174,7 +175,7 @@ void pwm_handler(unsigned int cport, __u8 *rbuf, size_t size) cport_to_module_id(cport), cport, op_req->pwm_dis_req.which); if (verbose) gbsim_dump((__u8 *)op_rsp, sz); - write(cport_in, cport_rsp, sz + 1); + write(cport_in, op_rsp, sz); break; default: gbsim_error("pwm operation type %02x not supported\n", oph->type);