Just took a quick look over this and I basically agree with the comments from Robin. What I don't understand is why you're even trying to do all these hacky things. It seems like the controller should simply set dma_pfn_offset for each device hanging off it, and all the supported architectures should be updated to obey that if they don't do so yet, and you're done without needing this giant mess.