[ERD][APR-103] [COMMON]chub: suppport dump on reset
authorBoojin Kim <boojin.kim@samsung.com>
Mon, 12 Nov 2018 09:35:12 +0000 (18:35 +0900)
committerhskang <hs1218.kang@samsung.com>
Sun, 21 Apr 2019 09:08:44 +0000 (18:08 +0900)
chub driver requests to dump to sensor hal

Change-Id: I97650a22c686ae72e932311d2db973c09c4b9167
Signed-off-by: Boojin Kim <boojin.kim@samsung.com>
drivers/staging/nanohub/chub.c
drivers/staging/nanohub/chub_dbg.c
drivers/staging/nanohub/chub_dbg.h
drivers/staging/nanohub/main.c
drivers/staging/nanohub/main.h

index dc5842c20b0e641a236bb54d7345e266ff69adfe..2514bbbbb779ac0d9bdb39c93eee55ba91fb2317 100644 (file)
@@ -230,7 +230,7 @@ static int contexthub_ipc_drv_init(struct contexthub_ipc_info *chub)
        chub->dd_log =
            log_register_buffer(chub_dev, 1, chub->dd_log_buffer, "dd", 0);
 #endif
-       ret = chub_dbg_init(chub_dev);
+       ret = chub_dbg_init(chub);
        if (ret)
                dev_err(chub_dev, "%s: fails. ret:%d\n", __func__, ret);
 
@@ -920,7 +920,7 @@ out:
 int contexthub_reset(struct contexthub_ipc_info *ipc, bool force_load, int dump)
 {
        int ret;
-       int trycnt;
+       int trycnt = 0;
 
        dev_info(ipc->dev, "%s: force:%d, status:%d, in-reset:%d, user:%d\n",
                __func__, force_load, atomic_read(&ipc->chub_status), atomic_read(&ipc->in_reset), atomic_read(&ipc->in_use_ipc));
@@ -936,13 +936,15 @@ int contexthub_reset(struct contexthub_ipc_info *ipc, bool force_load, int dump)
                msleep(WAIT_CHUB_MS);
                if (++trycnt > RESET_WAIT_TRY_CNT) {
                        dev_info(ipc->dev, "%s: cann't get lock. force reset: %d\n", __func__, atomic_read(&ipc->in_use_ipc));
-                       break;
+                       atomic_dec(&ipc->in_reset);
+                       mutex_unlock(&reset_mutex);
+                       return -EINVAL;
                }
                dev_info(ipc->dev, "%s: wait for ipc user free: %d\n", __func__, atomic_read(&ipc->in_use_ipc));
        } while (atomic_read(&ipc->in_use_ipc));
 
        if (dump)
-               chub_dbg_dump_hw(ipc, dump);
+               chub_dbg_dump_hw(ipc, ipc->cur_err);
 
        dev_info(ipc->dev, "%s: start reset status:%d\n", __func__, atomic_read(&ipc->chub_status));
        if (!ipc->block_reset) {
@@ -1000,6 +1002,7 @@ int contexthub_download_image(struct contexthub_ipc_info *ipc, enum ipc_region r
        const struct firmware *entry;
        int ret;
 
+       dev_info(ipc->dev, "%s: enter for bl:%d\n", reg == IPC_REG_BL);
        if (reg == IPC_REG_BL)
                ret = request_firmware(&entry, "bl.unchecked.bin", ipc->dev);
        else if (reg == IPC_REG_OS)
@@ -1377,7 +1380,7 @@ static ssize_t chub_reset(struct device *dev,
                                const char *buf, size_t count)
 {
        struct contexthub_ipc_info *ipc = dev_get_drvdata(dev);
-       int ret = contexthub_reset(ipc, 1, 0);
+       int ret = contexthub_reset(ipc, 1, 1);
 
        return ret < 0 ? ret : count;
 }
index cf3f4b47c5b25efb09a14e33187fd7f91d6cb696..ebe7f58513c69b3ac5358c638411d97d0097e24d 100644 (file)
@@ -62,9 +62,6 @@ static void chub_dbg_dump_gpr(struct contexthub_ipc_info *ipc)
                                  i * 4);
                p_dump->gpr[GPR_PC_INDEX] =
                    readl(ipc->chub_dumpgrp + REG_CHUB_DUMPGPR_PCR);
-
-               for (i = 0; i <= GPR_PC_INDEX; i++)
-                       pr_info("R%d: 0x%x\n", i, p_dump->gpr[i]);
        }
 }
 
@@ -73,7 +70,7 @@ static u32 get_dbg_dump_size(void)
        return sizeof(struct dbg_dump) + ipc_get_chub_mem_size();
 };
 
-#ifdef CONFIG_CONTEXTHUB_DEBUG
+#if defined(CONFIG_CONTEXTHUB_DEBUG) && defined(SUPPORT_DUMP_ON_DRIVER)
 static void chub_dbg_write_file(struct device *dev, char *name, void *buf, int size)
 {
        struct file *filp;
@@ -140,7 +137,6 @@ static void chub_dbg_dump_status(struct contexthub_ipc_info *ipc)
                atomic_read(&data->wakeup_lock_cnt),
                atomic_read(&data->wakeup_acquired),
                atomic_read(&ipc->irq1_apInt), nanohub_irq1_fired(data));
-
 #endif
 
        /* print error status */
@@ -163,6 +159,12 @@ void chub_dbg_dump_hw(struct contexthub_ipc_info *ipc, enum chub_err_type reason
        chub_dbg_dump_gpr(ipc);
        chub_dbg_dump_ram(ipc, reason);
 
+#ifdef CONFIG_CHRE_SENSORHUB_HAL
+       nanohub_add_dump_request(ipc->data);
+#endif
+
+#ifdef SUPPORT_DUMP_ON_DRIVER
+       /* dosen't support on android-p */
        if (p_dbg_dump) {
 #ifdef CONFIG_CONTEXTHUB_DEBUG
                /* write file */
@@ -183,6 +185,7 @@ void chub_dbg_dump_hw(struct contexthub_ipc_info *ipc, enum chub_err_type reason
 
        /* dump log and status with ipc */
        chub_dbg_dump_status(ipc);
+#endif
 }
 
 int chub_dbg_check_and_download_image(struct contexthub_ipc_info *ipc)
@@ -231,8 +234,7 @@ static ssize_t chub_bin_sram_read(struct file *file, struct kobject *kobj,
 {
        struct device *dev = kobj_to_dev(kobj);
 
-       dev_dbg(dev, "%s(%lld, %zu)\n", __func__, off, size);
-
+       dev_info(dev, "%s(%p: %lld, %zu)\n", __func__, battr->private, off, size);
        memcpy_fromio(buf, battr->private + off, size);
        return size;
 }
@@ -243,17 +245,27 @@ static ssize_t chub_bin_dram_read(struct file *file, struct kobject *kobj,
 {
        struct device *dev = kobj_to_dev(kobj);
 
-       dev_dbg(dev, "%s(%lld, %zu)\n", __func__, off, size);
+       dev_info(dev, "%s(%p: %lld, %zu)\n", __func__, battr->private, off, size);
+       memcpy(buf, battr->private + off, size);
+       return size;
+}
+
+static ssize_t chub_bin_dumped_sram_read(struct file *file, struct kobject *kobj,
+                                 struct bin_attribute *battr, char *buf,
+                                 loff_t off, size_t size)
+{
        memcpy(buf, battr->private + off, size);
        return size;
 }
 
 static BIN_ATTR_RO(chub_bin_sram, 0);
 static BIN_ATTR_RO(chub_bin_dram, 0);
+static BIN_ATTR_RO(chub_bin_dumped_sram, 0);
 
 static struct bin_attribute *chub_bin_attrs[] = {
        &bin_attr_chub_bin_sram,
        &bin_attr_chub_bin_dram,
+       &bin_attr_chub_bin_dumped_sram,
 };
 
 #define SIZE_UTC_NAME (16)
@@ -489,19 +501,33 @@ void *chub_dbg_get_memory(enum dbg_dump_area area)
        return addr;
 }
 
-int chub_dbg_init(struct device *dev)
+int chub_dbg_init(struct contexthub_ipc_info *chub)
 {
        int i, ret = 0;
        enum dbg_dump_area area;
 
-       if (!chub_rmem)
+       struct device *dev;
+       struct device *sensor_dev = NULL;
+
+       if (!chub_rmem || !chub)
                return -EINVAL;
 
-       bin_attr_chub_bin_sram.size = ipc_get_chub_mem_size();
-       bin_attr_chub_bin_sram.private = ipc_get_base(IPC_REG_DUMP);
+       sensor_dev = dev = chub->dev;
+#ifdef CONFIG_CHRE_SENSORHUB_HAL
+       if (chub->data)
+               sensor_dev = chub->data->io[ID_NANOHUB_SENSOR].dev;
+#endif
+
+       pr_info("%s: %s: %s\n", __func__, dev_name(dev), dev_name(sensor_dev));
+
+       bin_attr_chub_bin_dumped_sram.size = ipc_get_chub_mem_size();
+       bin_attr_chub_bin_dumped_sram.private = p_dbg_dump->sram;
 
        bin_attr_chub_bin_dram.size = sizeof(struct dbg_dump);
-       bin_attr_chub_bin_dram.private = p_dbg_dump;
+       bin_attr_chub_bin_dram.private= p_dbg_dump;
+
+       bin_attr_chub_bin_sram.size = ipc_get_chub_mem_size();
+       bin_attr_chub_bin_sram.private = ipc_get_base(IPC_REG_DUMP);
 
        if (chub_rmem->size < get_dbg_dump_size())
                dev_err(dev,
@@ -511,9 +537,9 @@ int chub_dbg_init(struct device *dev)
        for (i = 0; i < ARRAY_SIZE(chub_bin_attrs); i++) {
                struct bin_attribute *battr = chub_bin_attrs[i];
 
-               ret = device_create_bin_file(dev, battr);
+               ret = device_create_bin_file(sensor_dev, battr);
                if (ret < 0)
-                       dev_warn(dev, "Failed to create file: %s\n",
+                       dev_warn(sensor_dev, "Failed to create file: %s\n",
                                 battr->attr.name);
        }
 
@@ -558,9 +584,10 @@ int chub_dbg_init(struct device *dev)
        p_dbg_dump->info[area].size = bin_attr_chub_bin_sram.size;
 
        dev_dbg(dev,
-               "%s(%pa) is mapped on %p (sram %p) with size of %u, dump size %u\n",
+               "%s(%pa) is mapped on %p (sram %p: startoffset:%d) with size of %u, dump size %u\n",
                "dump buffer", &chub_rmem->base, phys_to_virt(chub_rmem->base),
                &p_dbg_dump->sram[p_dbg_dump->sram_start],
+               p_dbg_dump->sram_start,
                (u32)chub_rmem->size, get_dbg_dump_size());
 
        return ret;
index 729248fd8ce2067966ab70d2dbc4d6a26df25477..50d09e094cbf3c90fc50b0e6ba3e331d46353e3b 100644 (file)
@@ -21,7 +21,7 @@ enum dbg_dump_area {
        DBG_AREA_MAX
 };
 
-int chub_dbg_init(struct device *dev);
+int chub_dbg_init(struct contexthub_ipc_info *chub);
 void *chub_dbg_get_memory(enum dbg_dump_area area);
 void chub_dbg_dump_hw(struct contexthub_ipc_info *ipc, enum chub_err_type reason);
 void chub_dbg_print_hw(struct contexthub_ipc_info *ipc);
index bbc95877e7f8892cc240aa0c85ee65a373b67cce..e6df06264490dee9a3dcfa7c2f0bdc7b448d09c7 100644 (file)
@@ -175,6 +175,20 @@ static inline bool nanohub_io_has_buf(struct nanohub_io *io)
        return !list_empty(&io->buf_list);
 }
 
+#ifdef CONFIG_NANOHUB_MAILBOX
+#define EVT_DEBUG_DUMP                   0x00007F02  /* defined on sensorhal */
+
+int nanohub_is_reset_notify_io(struct nanohub_buf *buf)
+{
+       if (buf) {
+               uint32_t *buffer = (uint32_t *)buf->buffer;
+               if (*buffer == EVT_DEBUG_DUMP)
+                       return true;
+       }
+       return false;
+}
+#endif
+
 static struct nanohub_buf *nanohub_io_get_buf(struct nanohub_io *io,
                                              bool wait)
 {
@@ -1079,7 +1093,6 @@ static ssize_t nanohub_unlock_bl(struct device *dev,
 }
 #endif
 
-
 #ifdef CONFIG_NANOHUB_MAILBOX
 static int chub_get_chipid(struct contexthub_ipc_info *ipc)
 
@@ -1130,6 +1143,22 @@ static ssize_t chub_chipid_store(struct device *dev,
                return 0;
        }
 }
+
+void nanohub_add_dump_request(struct nanohub_data *data)
+{
+       struct nanohub_io *io = &data->io[ID_NANOHUB_SENSOR];
+       struct nanohub_buf *buf = nanohub_io_get_buf(&data->free_pool, false);
+       uint32_t *buffer;
+
+       if (buf) {
+               buffer = (uint32_t *)buf->buffer;
+               *buffer = EVT_DEBUG_DUMP;
+               nanohub_io_put_buf(io, buf);
+               wake_lock_timeout(&data->wakelock_read, msecs_to_jiffies(250));
+       } else {
+               pr_err("%s: cann't get io buf\n", __func__);
+       }
+}
 #endif
 
 static struct device_attribute attributes[] = {
@@ -1293,7 +1322,17 @@ static ssize_t nanohub_read(struct file *file, char *buffer, size_t length,
        else
                ret = buf->length;
 
+#ifdef CONFIG_NANOHUB_MAILBOX
+       if (nanohub_is_reset_notify_io(buf)) {
+               io = &io->data->free_pool;
+               spin_lock(&io->buf_wait.lock);
+               list_add_tail(&buf->list, &io->buf_list);
+               spin_unlock(&io->buf_wait.lock);
+       } else
+               nanohub_io_put_buf(&data->free_pool, buf);
+#else
        nanohub_io_put_buf(&data->free_pool, buf);
+#endif
 
        return ret;
 }
@@ -1438,7 +1477,10 @@ static void nanohub_process_buffer(struct nanohub_data *data,
        }
        if (event_id == APP_TO_HOST_EVENTID) {
                wakeup = true;
+#ifndef CONFIG_NANOHUB_MAILBOX
+               /* chub doesn't enable nanohal. use sensorhal io */
                io = &data->io[ID_NANOHUB_COMMS];
+#endif
        }
 
        nanohub_io_put_buf(io, *buf);
index 2d97f7a3bdaa53474e76dc564a50c73f36c6e423..3cdd0cf92542af7cd9d0e9057f4793aa5f22e4ae 100644 (file)
@@ -193,6 +193,10 @@ static inline int nanohub_irq2_fired(struct nanohub_data *data)
 }
 #endif
 
+#ifdef CONFIG_NANOHUB_MAILBOX
+void nanohub_add_dump_request(struct nanohub_data *data);
+#endif
+
 static inline int request_wakeup_timeout(struct nanohub_data *data, int timeout)
 {
        return request_wakeup_ex(data, timeout, KEY_WAKEUP, LOCK_MODE_NORMAL);