mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
arch/esp32_himemcdev: Multiple instances of struct file for the same file
share the f_inode, ensuring that the mapping status is associated with the file entity rather than a single descriptor. Avoid redundant mapping operations caused by multiple descriptors operating on the same file. Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
This commit is contained in:
@@ -62,7 +62,7 @@ static size_t g_ram_offset; /* used by himem map/unmap */
|
|||||||
|
|
||||||
static void *g_himem_ptr; /* mapped himem pointer */
|
static void *g_himem_ptr; /* mapped himem pointer */
|
||||||
|
|
||||||
static struct file *g_mapped_filep; /* for multi device */
|
static struct inode *g_mapped_inode; /* for multi device */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Priavte Functions
|
* Priavte Functions
|
||||||
@@ -120,7 +120,8 @@ static int himem_chardev_read_write(int is_write, struct file *filep,
|
|||||||
length, dev->size);
|
length, dev->size);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if ((mmap_offset != g_ram_offset) || (g_mapped_filep != filep))
|
if ((mmap_offset != g_ram_offset) || \
|
||||||
|
(g_mapped_inode != filep->f_inode))
|
||||||
{
|
{
|
||||||
if (g_ram_offset != HIMEM_UNMAPPED)
|
if (g_ram_offset != HIMEM_UNMAPPED)
|
||||||
{
|
{
|
||||||
@@ -134,7 +135,7 @@ static int himem_chardev_read_write(int is_write, struct file *filep,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
g_ram_offset = HIMEM_UNMAPPED;
|
g_ram_offset = HIMEM_UNMAPPED;
|
||||||
g_mapped_filep = NULL;
|
g_mapped_inode = NULL;
|
||||||
}
|
}
|
||||||
ret = esp_himem_map(dev->mem_handle, g_range_handle,
|
ret = esp_himem_map(dev->mem_handle, g_range_handle,
|
||||||
mmap_offset * ESP_HIMEM_BLKSZ,
|
mmap_offset * ESP_HIMEM_BLKSZ,
|
||||||
@@ -145,7 +146,7 @@ static int himem_chardev_read_write(int is_write, struct file *filep,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
g_ram_offset = mmap_offset;
|
g_ram_offset = mmap_offset;
|
||||||
g_mapped_filep = filep;
|
g_mapped_inode = filep->f_inode;
|
||||||
}
|
}
|
||||||
himem_ptr = g_himem_ptr + priv->offset % ESP_HIMEM_BLKSZ;
|
himem_ptr = g_himem_ptr + priv->offset % ESP_HIMEM_BLKSZ;
|
||||||
copy_range = ESP_HIMEM_BLKSZ - priv->offset % ESP_HIMEM_BLKSZ;
|
copy_range = ESP_HIMEM_BLKSZ - priv->offset % ESP_HIMEM_BLKSZ;
|
||||||
@@ -273,7 +274,7 @@ int himem_chardev_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_ram_offset = HIMEM_UNMAPPED;
|
g_ram_offset = HIMEM_UNMAPPED;
|
||||||
g_mapped_filep = NULL;
|
g_mapped_inode = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +383,7 @@ int himem_chardev_unregister(char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_ram_offset = HIMEM_UNMAPPED;
|
g_ram_offset = HIMEM_UNMAPPED;
|
||||||
g_mapped_filep = NULL;
|
g_mapped_inode = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = esp_himem_free(dev->mem_handle);
|
ret = esp_himem_free(dev->mem_handle);
|
||||||
|
|||||||
Reference in New Issue
Block a user