You can build a custom memory controller in gem5 but it requires multiple steps. I recommend following the code in Ramulator2 repository to see how you can build a custom memory model: https://github.com/CMU-SAFARI/ramulator2/tree/main/resources/gem5_wrappers.
Ideally, I recommend building your memory controller by adding a custom one to Ramulator2 or a similar memory simulation framework that works with gem5.