{"action":"created","issue":{"url":"https://api.github.com/repos/OP-TEE/optee_os/issues/1496","repository_url":"https://api.github.com/repos/OP-TEE/optee_os","labels_url":"https://api.github.com/repos/OP-TEE/optee_os/issues/1496/labels{/name}","comments_url":"https://api.github.com/repos/OP-TEE/optee_os/issues/1496/comments","events_url":"https://api.github.com/repos/OP-TEE/optee_os/issues/1496/events","html_url":"https://github.com/OP-TEE/optee_os/issues/1496","id":223950339,"number":1496,"title":"Accessing GPIO from TA in Raspberry Pi 3","user":{"login":"utkarshagrawalwsu","id":26235979,"avatar_url":"https://avatars1.githubusercontent.com/u/26235979?v=3","gravatar_id":"","url":"https://api.github.com/users/utkarshagrawalwsu","html_url":"https://github.com/utkarshagrawalwsu","followers_url":"https://api.github.com/users/utkarshagrawalwsu/followers","following_url":"https://api.github.com/users/utkarshagrawalwsu/following{/other_user}","gists_url":"https://api.github.com/users/utkarshagrawalwsu/gists{/gist_id}","starred_url":"https://api.github.com/users/utkarshagrawalwsu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/utkarshagrawalwsu/subscriptions","organizations_url":"https://api.github.com/users/utkarshagrawalwsu/orgs","repos_url":"https://api.github.com/users/utkarshagrawalwsu/repos","events_url":"https://api.github.com/users/utkarshagrawalwsu/events{/privacy}","received_events_url":"https://api.github.com/users/utkarshagrawalwsu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2017-04-24T21:02:59Z","updated_at":"2017-04-28T03:46:36Z","closed_at":null,"body":"Hello,\r\n\r\nI have been trying to access the Raspberry Pi3 GPIO from TA. What would be a secure manner to do so?\r\n\r\nI tried using the `sysfs` method mentioned in the following link:\r\n[http://elinux.org/RPi_GPIO_Code_Samples#sysfs](http://elinux.org/RPi_GPIO_Code_Samples#sysfs)\r\nBut it requires the use of C file operations. Does OP-TEE support file operations in TA?\r\n\r\nThank You"},"comment":{"url":"https://api.github.com/repos/OP-TEE/optee_os/issues/comments/297899988","html_url":"https://github.com/OP-TEE/optee_os/issues/1496#issuecomment-297899988","issue_url":"https://api.github.com/repos/OP-TEE/optee_os/issues/1496","id":297899988,"user":{"login":"vchong","id":7334750,"avatar_url":"https://avatars2.githubusercontent.com/u/7334750?v=3","gravatar_id":"","url":"https://api.github.com/users/vchong","html_url":"https://github.com/vchong","followers_url":"https://api.github.com/users/vchong/followers","following_url":"https://api.github.com/users/vchong/following{/other_user}","gists_url":"https://api.github.com/users/vchong/gists{/gist_id}","starred_url":"https://api.github.com/users/vchong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vchong/subscriptions","organizations_url":"https://api.github.com/users/vchong/orgs","repos_url":"https://api.github.com/users/vchong/repos","events_url":"https://api.github.com/users/vchong/events{/privacy}","received_events_url":"https://api.github.com/users/vchong/received_events","type":"User","site_admin":false},"created_at":"2017-04-28T03:46:36Z","updated_at":"2017-04-28T03:46:36Z","body":"@utkarshagrawalwsu You're welcome! Sounds like you made good progress! :) I only browsed through the spec so can't say for sure if the bits selection is right or not (although it looks ok from a quick glance). You'll have to trial and error until you find the right combinations.\r\n\r\nOff the top of my head, several things to look at.\r\n\r\n> mmc0: timeout waiting for hardware interrupt\r\n\r\nNot sure if this is related, but is it possible to disable interrupt on the pin? I don't see any interrupt related registers for gpio, but they might be located elsewhere. There are mentions of `gpio_int` in the spec, but I didn't look further.\r\n\r\n> What base address should I use for the GPIO? Should it be the virtual address(0x3F000000 + 0x200000) or the physical address(0x7E200000)?\r\n\r\nI wish the article explained how Dom managed to find out 0x3F200000 for rpi3, but it's not the va. It is actually the pa. 0x7E200000 is the bus address. Read Section 1, especially 1.2 and 1.3, of the spec too, not just the gpio section. The address mapping is multiple layered and hard to figure out (at least for me). I think the pa (0x3F200000) should be used, since there's no dma engines involved, but I might be wrong.\r\n\r\nIf using pa, and it doesn't work (you might get a core dump), you might also to consider trying something like:\r\n`register_phys_mem(MEM_AREA_IO_SEC, 0x3F200000, CORE_MMU_DEVICE_SIZE);`\r\n\r\nand translate the base address from pa to va before using them in your functions. Something like:\r\n```\r\nvaddr_t nsec_periph_base(paddr_t pa)\r\n{\r\n\tif (cpu_mmu_enabled())\r\n\t\treturn (vaddr_t)phys_to_virt(pa, MEM_AREA_IO_NSEC);\r\n\treturn (vaddr_t)pa;\r\n}\r\n\r\nvaddr_t base_addr_GPFSEL0 = nsec_periph_base(0x3F200004);\r\nvaddr_t base_addr_GPSET0 = nsec_periph_base(0x3F20001C);\r\n```\r\n\r\nAgain, mostly guesswork here so you'll have to play around a bit to see what works."}}
{"actor":{"display_login":"vchong"}}