Skip to content

Commit

Permalink
replacing IOREMAP_NO_CACHE with ioremap_wc
Browse files Browse the repository at this point in the history
This change adapts the code to be compliant with the new kernel requirements by using ioremap_wc for write-combining mappings, which is recommended for device memory mappings that do not require caching. This adjustment ensures that the driver remains functional and efficient under the updated kernel API
  • Loading branch information
ruck314 committed Feb 27, 2024
1 parent 881ebe0 commit 0ac92ad
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions rce_memmap/driver/src/rce_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@
#include <linux/slab.h>
#include <linux/version.h>

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
/* 'ioremap_nocache' was deprecated in kernels >= 5.6, so instead we use 'ioremap' which
is no-cache by default since kernels 2.6.25. */
# define IOREMAP_NO_CACHE(address, size) ioremap(address, size)
#else /* KERNEL_VERSION < 2.6.25 */
# define IOREMAP_NO_CACHE(address, size) ioremap_nocache(address, size)
#endif

// Module Name
#define MOD_NAME "rce_memmap"

Expand Down Expand Up @@ -125,7 +117,7 @@ int Map_Init(void) {
dev.maps->next = NULL;

// Map space
dev.maps->base = IOREMAP_NO_CACHE(dev.maps->addr, MAP_SIZE);
dev.maps->base = ioremap_wc(dev.maps->addr, MAP_SIZE);
if (! dev.maps->base ) {
printk(KERN_ERR MOD_NAME " Init: Could not map memory addr %p with size 0x%x.\n",(void *)dev.maps->addr,MAP_SIZE);
kfree(dev.maps);
Expand Down Expand Up @@ -213,7 +205,7 @@ uint8_t * Map_Find(uint32_t addr) {
new->addr = (addr / MAP_SIZE) * MAP_SIZE;

// Map space
new->base = IOREMAP_NO_CACHE(new->addr, MAP_SIZE);
new->base = ioremap_wc(new->addr, MAP_SIZE);
if (! new->base ) {
printk(KERN_ERR MOD_NAME " Map_Find: Could not map memory addr %p (%p) with size 0x%x.\n",(void *)new->addr,(void*)addr,MAP_SIZE);
kfree(new);
Expand Down

0 comments on commit 0ac92ad

Please sign in to comment.