{"action":"opened","number":375,"pull_request":{"url":"https://api.github.com/repos/Harvey-OS/harvey/pulls/375","id":98284275,"html_url":"https://github.com/Harvey-OS/harvey/pull/375","diff_url":"https://github.com/Harvey-OS/harvey/pull/375.diff","patch_url":"https://github.com/Harvey-OS/harvey/pull/375.patch","issue_url":"https://api.github.com/repos/Harvey-OS/harvey/issues/375","number":375,"state":"open","locked":false,"title":"Acpica interrupt support","user":{"login":"sanderssj","id":6250092,"avatar_url":"https://avatars.githubusercontent.com/u/6250092?v=3","gravatar_id":"","url":"https://api.github.com/users/sanderssj","html_url":"https://github.com/sanderssj","followers_url":"https://api.github.com/users/sanderssj/followers","following_url":"https://api.github.com/users/sanderssj/following{/other_user}","gists_url":"https://api.github.com/users/sanderssj/gists{/gist_id}","starred_url":"https://api.github.com/users/sanderssj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sanderssj/subscriptions","organizations_url":"https://api.github.com/users/sanderssj/orgs","repos_url":"https://api.github.com/users/sanderssj/repos","events_url":"https://api.github.com/users/sanderssj/events{/privacy}","received_events_url":"https://api.github.com/users/sanderssj/received_events","type":"User","site_admin":false},"body":"This pull request adds support for letting the acpica library, in user space, handle interrupts. This is accomplished by making a real acpi interrupt handler in the kernel that caches the acpica interrupt status register so that when the acpica library reads that address, it gets the cached value. The kernel interrupt handler posts a note a user process that has registered to receive interrupts. Writes from the acpica library affect the cached value (because the kernel interrupt handle has already reset the real status register). This code assumes that every bit in the acpi status register (pm1a)  behaves the same way; i.e. a bit is set when the interrupt has occurred, and gets cleared by writing a 1 to that bit.\r\n\r\nThe acpica os code is modified to include a note handler to identify the acpi interrupt note and call the acpica handler.\r\n\r\nBelow you can find an example program which sets handlers for the power button and acpi pm timer interrupts to demonstrate how it works. You can simulate a working power off event with qemu by running the qemu console and using the command 'system_powerdown'. \r\n\r\nI'm sure this code isn't perfect--I think there are ways to miss interrupts and there will need to be synchronization around the pm1a status register. I haven't tried this on real hardware yet either. I have left comments in other areas I'm not sure about.\r\n\r\nHopefully this is at least a starting point for a more robust solution.\r\n\r\ntestsleep.c:\r\n```\r\n#include <acpi.h>\r\n#include <accommon.h>\r\n#include <acnamesp.h>\r\n\r\n\r\nvoid\r\nfail(char *msg)\r\n{\r\n\tfprint(2, \"%s\\n\", msg);\r\n\texits(\"FAIL\");\r\n}\r\n\r\nUINT32\r\nshutdownhandler(void *ctxt)\r\n{\r\n\tACPI_STATUS status;\r\n\r\n\tsyslog(1, \"acpi\", \"acpi event: power button\");\r\n\tstatus = AcpiEnterSleepStatePrep(5);\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to prep for sleep\");\r\n\tstatus = AcpiEnterSleepState(5);\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to go to sleep\");\r\n\treturn 0;\r\n}\r\n\r\nUINT32\r\ntimerhandler(void *ctxt)\r\n{\r\n\tsyslog(1, \"acpi\", \"acpi event: pm timer\");\r\n\treturn 0;\r\n}\r\n\r\n/* The order of initialization comes from the ACPICA Programmer's Reference */\r\nvoid main(int argc, char *argv[])\r\n{\r\n\tACPI_STATUS status;\r\n\textern UINT32 AcpiDbgLevel;\r\n\r\n\tstatus = AcpiInitializeSubsystem();\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to init subsystem\");\r\n\tstatus = AcpiInitializeTables(NULL, 4, 0);\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to init tables\");\r\n\tstatus = AcpiLoadTables();\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to load tables\");\r\n\tstatus = AcpiEnableSubsystem(ACPI_FULL_INITIALIZATION);\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to enable subsystem\");\r\n\t/* ACPI Handlers should be installed at this time */\r\n\tstatus = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION);\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to initialize objects\");\r\n\t/* Other ACPI initialization can occur here including:\r\n\t * \tEnumerating devices using _HID method\r\n\t * \tLoading, configuring, installing device drivers\r\n\t *\tDevice Driver install handlers for other address spaces\r\n\t *\tEnumerating PCI devices and loading PCIConfig handlers\r\n\t */\r\n\t//AcpiDbgLevel |= ACPI_LV_VERBOSITY1 | ACPI_LV_FUNCTIONS;\r\n\t//status = AcpiInstallGlobalEventHandler(shutdownhandler, nil);\r\n\tstatus = AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON, shutdownhandler, nil);\r\n\tstatus = AcpiInstallFixedEventHandler(ACPI_EVENT_PMTIMER, timerhandler, nil);\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to install fixed event handler\");\r\n\tprint(\"Fixed Event Handler installed!\\n\");\r\n\tstatus = AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON, 0);\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to enable power button\");\r\n\tstatus = AcpiEnableEvent(ACPI_EVENT_PMTIMER, 0);\r\n\tif (ACPI_FAILURE(status))\r\n\t\tfail(\"failed to enable pmtimer\");\r\n\twhile (1)\r\n\t\tsleep(30*1000);\r\n\tstatus = AcpiTerminate();\r\n        if (ACPI_FAILURE(status))\r\n                fail(\"failed to terminate acpi\");\r\n        exits(nil);\r\n}\r\n```","created_at":"2016-12-16T06:21:18Z","updated_at":"2016-12-16T06:21:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Harvey-OS/harvey/pulls/375/commits","review_comments_url":"https://api.github.com/repos/Harvey-OS/harvey/pulls/375/comments","review_comment_url":"https://api.github.com/repos/Harvey-OS/harvey/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Harvey-OS/harvey/issues/375/comments","statuses_url":"https://api.github.com/repos/Harvey-OS/harvey/statuses/612006d68cd9ce8758461c6e70dc20af74ced533","head":{"label":"sanderssj:acpica-interrupts","ref":"acpica-interrupts","sha":"612006d68cd9ce8758461c6e70dc20af74ced533","user":{"login":"sanderssj","id":6250092,"avatar_url":"https://avatars.githubusercontent.com/u/6250092?v=3","gravatar_id":"","url":"https://api.github.com/users/sanderssj","html_url":"https://github.com/sanderssj","followers_url":"https://api.github.com/users/sanderssj/followers","following_url":"https://api.github.com/users/sanderssj/following{/other_user}","gists_url":"https://api.github.com/users/sanderssj/gists{/gist_id}","starred_url":"https://api.github.com/users/sanderssj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sanderssj/subscriptions","organizations_url":"https://api.github.com/users/sanderssj/orgs","repos_url":"https://api.github.com/users/sanderssj/repos","events_url":"https://api.github.com/users/sanderssj/events{/privacy}","received_events_url":"https://api.github.com/users/sanderssj/received_events","type":"User","site_admin":false},"repo":{"id":74803565,"name":"harvey","full_name":"sanderssj/harvey","owner":{"login":"sanderssj","id":6250092,"avatar_url":"https://avatars.githubusercontent.com/u/6250092?v=3","gravatar_id":"","url":"https://api.github.com/users/sanderssj","html_url":"https://github.com/sanderssj","followers_url":"https://api.github.com/users/sanderssj/followers","following_url":"https://api.github.com/users/sanderssj/following{/other_user}","gists_url":"https://api.github.com/users/sanderssj/gists{/gist_id}","starred_url":"https://api.github.com/users/sanderssj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sanderssj/subscriptions","organizations_url":"https://api.github.com/users/sanderssj/orgs","repos_url":"https://api.github.com/users/sanderssj/repos","events_url":"https://api.github.com/users/sanderssj/events{/privacy}","received_events_url":"https://api.github.com/users/sanderssj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sanderssj/harvey","description":"A distributed operating system","fork":true,"url":"https://api.github.com/repos/sanderssj/harvey","forks_url":"https://api.github.com/repos/sanderssj/harvey/forks","keys_url":"https://api.github.com/repos/sanderssj/harvey/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sanderssj/harvey/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sanderssj/harvey/teams","hooks_url":"https://api.github.com/repos/sanderssj/harvey/hooks","issue_events_url":"https://api.github.com/repos/sanderssj/harvey/issues/events{/number}","events_url":"https://api.github.com/repos/sanderssj/harvey/events","assignees_url":"https://api.github.com/repos/sanderssj/harvey/assignees{/user}","branches_url":"https://api.github.com/repos/sanderssj/harvey/branches{/branch}","tags_url":"https://api.github.com/repos/sanderssj/harvey/tags","blobs_url":"https://api.github.com/repos/sanderssj/harvey/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sanderssj/harvey/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sanderssj/harvey/git/refs{/sha}","trees_url":"https://api.github.com/repos/sanderssj/harvey/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sanderssj/harvey/statuses/{sha}","languages_url":"https://api.github.com/repos/sanderssj/harvey/languages","stargazers_url":"https://api.github.com/repos/sanderssj/harvey/stargazers","contributors_url":"https://api.github.com/repos/sanderssj/harvey/contributors","subscribers_url":"https://api.github.com/repos/sanderssj/harvey/subscribers","subscription_url":"https://api.github.com/repos/sanderssj/harvey/subscription","commits_url":"https://api.github.com/repos/sanderssj/harvey/commits{/sha}","git_commits_url":"https://api.github.com/repos/sanderssj/harvey/git/commits{/sha}","comments_url":"https://api.github.com/repos/sanderssj/harvey/comments{/number}","issue_comment_url":"https://api.github.com/repos/sanderssj/harvey/issues/comments{/number}","contents_url":"https://api.github.com/repos/sanderssj/harvey/contents/{+path}","compare_url":"https://api.github.com/repos/sanderssj/harvey/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sanderssj/harvey/merges","archive_url":"https://api.github.com/repos/sanderssj/harvey/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sanderssj/harvey/downloads","issues_url":"https://api.github.com/repos/sanderssj/harvey/issues{/number}","pulls_url":"https://api.github.com/repos/sanderssj/harvey/pulls{/number}","milestones_url":"https://api.github.com/repos/sanderssj/harvey/milestones{/number}","notifications_url":"https://api.github.com/repos/sanderssj/harvey/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sanderssj/harvey/labels{/name}","releases_url":"https://api.github.com/repos/sanderssj/harvey/releases{/id}","deployments_url":"https://api.github.com/repos/sanderssj/harvey/deployments","created_at":"2016-11-26T04:03:24Z","updated_at":"2016-11-26T04:03:48Z","pushed_at":"2016-12-16T06:01:38Z","git_url":"git://github.com/sanderssj/harvey.git","ssh_url":"git@github.com:sanderssj/harvey.git","clone_url":"https://github.com/sanderssj/harvey.git","svn_url":"https://github.com/sanderssj/harvey","homepage":"https://harvey-os.org/","size":123376,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Harvey-OS:master","ref":"master","sha":"db95c645d8bb13b4b063a8a33a2c06af25191162","user":{"login":"Harvey-OS","id":13330702,"avatar_url":"https://avatars.githubusercontent.com/u/13330702?v=3","gravatar_id":"","url":"https://api.github.com/users/Harvey-OS","html_url":"https://github.com/Harvey-OS","followers_url":"https://api.github.com/users/Harvey-OS/followers","following_url":"https://api.github.com/users/Harvey-OS/following{/other_user}","gists_url":"https://api.github.com/users/Harvey-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/Harvey-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Harvey-OS/subscriptions","organizations_url":"https://api.github.com/users/Harvey-OS/orgs","repos_url":"https://api.github.com/users/Harvey-OS/repos","events_url":"https://api.github.com/users/Harvey-OS/events{/privacy}","received_events_url":"https://api.github.com/users/Harvey-OS/received_events","type":"Organization","site_admin":false},"repo":{"id":39068568,"name":"harvey","full_name":"Harvey-OS/harvey","owner":{"login":"Harvey-OS","id":13330702,"avatar_url":"https://avatars.githubusercontent.com/u/13330702?v=3","gravatar_id":"","url":"https://api.github.com/users/Harvey-OS","html_url":"https://github.com/Harvey-OS","followers_url":"https://api.github.com/users/Harvey-OS/followers","following_url":"https://api.github.com/users/Harvey-OS/following{/other_user}","gists_url":"https://api.github.com/users/Harvey-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/Harvey-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Harvey-OS/subscriptions","organizations_url":"https://api.github.com/users/Harvey-OS/orgs","repos_url":"https://api.github.com/users/Harvey-OS/repos","events_url":"https://api.github.com/users/Harvey-OS/events{/privacy}","received_events_url":"https://api.github.com/users/Harvey-OS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Harvey-OS/harvey","description":"A distributed operating system","fork":false,"url":"https://api.github.com/repos/Harvey-OS/harvey","forks_url":"https://api.github.com/repos/Harvey-OS/harvey/forks","keys_url":"https://api.github.com/repos/Harvey-OS/harvey/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Harvey-OS/harvey/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Harvey-OS/harvey/teams","hooks_url":"https://api.github.com/repos/Harvey-OS/harvey/hooks","issue_events_url":"https://api.github.com/repos/Harvey-OS/harvey/issues/events{/number}","events_url":"https://api.github.com/repos/Harvey-OS/harvey/events","assignees_url":"https://api.github.com/repos/Harvey-OS/harvey/assignees{/user}","branches_url":"https://api.github.com/repos/Harvey-OS/harvey/branches{/branch}","tags_url":"https://api.github.com/repos/Harvey-OS/harvey/tags","blobs_url":"https://api.github.com/repos/Harvey-OS/harvey/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Harvey-OS/harvey/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Harvey-OS/harvey/git/refs{/sha}","trees_url":"https://api.github.com/repos/Harvey-OS/harvey/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Harvey-OS/harvey/statuses/{sha}","languages_url":"https://api.github.com/repos/Harvey-OS/harvey/languages","stargazers_url":"https://api.github.com/repos/Harvey-OS/harvey/stargazers","contributors_url":"https://api.github.com/repos/Harvey-OS/harvey/contributors","subscribers_url":"https://api.github.com/repos/Harvey-OS/harvey/subscribers","subscription_url":"https://api.github.com/repos/Harvey-OS/harvey/subscription","commits_url":"https://api.github.com/repos/Harvey-OS/harvey/commits{/sha}","git_commits_url":"https://api.github.com/repos/Harvey-OS/harvey/git/commits{/sha}","comments_url":"https://api.github.com/repos/Harvey-OS/harvey/comments{/number}","issue_comment_url":"https://api.github.com/repos/Harvey-OS/harvey/issues/comments{/number}","contents_url":"https://api.github.com/repos/Harvey-OS/harvey/contents/{+path}","compare_url":"https://api.github.com/repos/Harvey-OS/harvey/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Harvey-OS/harvey/merges","archive_url":"https://api.github.com/repos/Harvey-OS/harvey/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Harvey-OS/harvey/downloads","issues_url":"https://api.github.com/repos/Harvey-OS/harvey/issues{/number}","pulls_url":"https://api.github.com/repos/Harvey-OS/harvey/pulls{/number}","milestones_url":"https://api.github.com/repos/Harvey-OS/harvey/milestones{/number}","notifications_url":"https://api.github.com/repos/Harvey-OS/harvey/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Harvey-OS/harvey/labels{/name}","releases_url":"https://api.github.com/repos/Harvey-OS/harvey/releases{/id}","deployments_url":"https://api.github.com/repos/Harvey-OS/harvey/deployments","created_at":"2015-07-14T10:27:38Z","updated_at":"2016-12-11T04:05:21Z","pushed_at":"2016-12-16T05:52:13Z","git_url":"git://github.com/Harvey-OS/harvey.git","ssh_url":"git@github.com:Harvey-OS/harvey.git","clone_url":"https://github.com/Harvey-OS/harvey.git","svn_url":"https://github.com/Harvey-OS/harvey","homepage":"https://harvey-os.org/","size":151231,"stargazers_count":464,"watchers_count":464,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":41,"mirror_url":null,"open_issues_count":18,"forks":41,"open_issues":18,"watchers":464,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Harvey-OS/harvey/pulls/375"},"html":{"href":"https://github.com/Harvey-OS/harvey/pull/375"},"issue":{"href":"https://api.github.com/repos/Harvey-OS/harvey/issues/375"},"comments":{"href":"https://api.github.com/repos/Harvey-OS/harvey/issues/375/comments"},"review_comments":{"href":"https://api.github.com/repos/Harvey-OS/harvey/pulls/375/comments"},"review_comment":{"href":"https://api.github.com/repos/Harvey-OS/harvey/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Harvey-OS/harvey/pulls/375/commits"},"statuses":{"href":"https://api.github.com/repos/Harvey-OS/harvey/statuses/612006d68cd9ce8758461c6e70dc20af74ced533"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":2,"additions":279,"deletions":32,"changed_files":2}}
{"actor":{"display_login":"sanderssj"}}