sysmem wip

Change-Id: I5f0fcf2fea2cc802341100b9787143bc3be2d5bf
diff --git a/SYSMEM b/SYSMEM
new file mode 100644
index 0000000..dd04230
--- /dev/null
+++ b/SYSMEM
@@ -0,0 +1,59 @@
+./board/vim2/vim-sysmem.cc:48:  if ((status = pbus_.ProtocolDeviceAdd(ZX_PROTOCOL_SYSMEM, &sysmem_dev)) != ZX_OK) {
+./board/x86/sysmem.c:57:    if ((status = pbus_protocol_device_add(pbus, ZX_PROTOCOL_SYSMEM, &sysmem_dev)) != ZX_OK) {
+./board/sherlock/sherlock-sysmem.cc:53:  zx_status_t status = pbus_.ProtocolDeviceAdd(ZX_PROTOCOL_SYSMEM, &sysmem_dev);
+./board/gauss/gauss-sysmem.c:45:    if ((status = pbus_protocol_device_add(&bus->pbus, ZX_PROTOCOL_SYSMEM, &sysmem_dev)) != ZX_OK) {
+./board/machina/machina-sysmem.c:46:    if ((status = pbus_protocol_device_add(&bus->pbus, ZX_PROTOCOL_SYSMEM, &sysmem_dev)) != ZX_OK) {
+./board/astro/astro-sysmem.cc:53:  zx_status_t status = pbus_.ProtocolDeviceAdd(ZX_PROTOCOL_SYSMEM, &sysmem_dev);
+./board/mt8167s_ref/mt8167-sysmem.cc:50:  zx_status_t status = pbus_.ProtocolDeviceAdd(ZX_PROTOCOL_SYSMEM, &sysmem_dev);
+./board/qemu/qemu-sysmem.c:47:    if ((status = pbus_protocol_device_add(&bus->pbus, ZX_PROTOCOL_SYSMEM, &sysmem_dev)) != ZX_OK) {
+./board/hikey960/hikey960-sysmem.c:48:    if ((status = pbus_protocol_device_add(&hikey->pbus, ZX_PROTOCOL_SYSMEM, &sysmem_dev)) != ZX_OK) {
+
+./board/x86/pciroot.cc:203:  zx_status_t status = device_get_protocol(dev->platform_bus, ZX_PROTOCOL_SYSMEM, &sysmem);
+./board/x86/pciroot.cc:222:  zx_status_t status = device_get_protocol(platform_bus_, ZX_PROTOCOL_SYSMEM, &sysmem);
+./board/x86/acpi-nswalk.c:437:    zx_status_t st = device_get_protocol(dev->platform_bus, ZX_PROTOCOL_SYSMEM, &sysmem);
+./board/x86/acpi-nswalk.c:453:    zx_status_t st = device_get_protocol(dev->platform_bus, ZX_PROTOCOL_SYSMEM, &sysmem);
+
+./display/intel-i915/intel-i915.cc:2134:  zx_status_t status = device_get_protocol(parent(), ZX_PROTOCOL_SYSMEM, &sysmem_);
+
+./bus/platform/platform-bus.cc:59:    case ZX_PROTOCOL_SYSMEM: {
+./bus/platform/platform-bus.cc:234:    case ZX_PROTOCOL_SYSMEM:
+./bus/pci/kpci/proxy.c:377:    if (proto_id == ZX_PROTOCOL_SYSMEM) {
+
+
+
+ddk.protocol.acpi/acpi.banjo:    ConnectSysmem(handle<channel> connection) -> (zx.status s);
+ddk.protocol.acpi/acpi.banjo:    RegisterSysmemHeap(uint64 heap, handle<channel> connection) -> (zx.status s);
+
+ddk.protocol.display.controller/display-controller.banjo:    GetSysmemConnection(handle<channel> sysmem_handle) -> (zx.status s);
+ddk.protocol.goldfish.pipe/goldfish-pipe.banjo:    ConnectSysmem(handle<channel> connection) -> (zx.status s);
+ddk.protocol.goldfish.pipe/goldfish-pipe.banjo:    RegisterSysmemHeap(uint64 heap, handle<channel> connection) -> (zx.status s);
+
+ddk.protocol.pciroot/pciroot.banjo:    ConnectSysmem(handle connection) -> (zx.status s);
+
+
+
+
+./board/x86/pciroot.cc:200:static zx_status_t pciroot_op_connect_sysmem(void* context, zx_handle_t handle) {
+./board/x86/pciroot.cc:427:    .connect_sysmem = pciroot_op_connect_sysmem,
+
+./board/x86/acpi-nswalk.c:432:static zx_status_t acpi_op_connect_sysmem(void* ctx, zx_handle_t handle) {
+./board/x86/acpi-nswalk.c:471:    .connect_sysmem = acpi_op_connect_sysmem,
+./bus/pci/kpci/kpci.c:173:static zx_status_t kpci_connect_sysmem(pci_msg_t* req, kpci_device_t* device, zx_handle_t ch) {
+./bus/pci/kpci/kpci.c:176:        zx_status_t status = pciroot_connect_sysmem(&device->pciroot, req->handle);
+./bus/pci/kpci/kpci.c:207:    [PCI_OP_CONNECT_SYSMEM] = kpci_connect_sysmem,
+
+./board/x86/pciroot.cc:220:zx_status_t Pciroot::PcirootConnectSysmem(zx::handle handle) {
+./board/x86/include/pciroot.h:35:  zx_status_t PcirootConnectSysmem(zx::handle handle);
+./display/goldfish-display/display.cc:566:  zx_status_t status = pipe_.ConnectSysmem(std::move(connection));
+./misc/goldfish/pipe-device.h:51:  zx_status_t GoldfishPipeConnectSysmem(zx::channel connection);
+./misc/goldfish/pipe-device.cc:239:zx_status_t PipeDevice::GoldfishPipeConnectSysmem(zx::channel connection) {
+./misc/goldfish/pipe-device.cc:240:  TRACE_DURATION("gfx", "PipeDevice::GoldfishPipeConnectSysmem");
+./misc/goldfish/pipe-device.cc:242:  return acpi_.ConnectSysmem(std::move(connection));
+./bus/pci/test/fakes/fake_pciroot.h:48:  zx_status_t PcirootConnectSysmem(zx::handle handle) { return ZX_ERR_NOT_SUPPORTED; }
+
+./board/x86/acpi-nswalk.c:448:static zx_status_t acpi_op_register_sysmem_heap(void* ctx, uint64_t heap, zx_handle_t handle) {
+./board/x86/acpi-nswalk.c:472:    .register_sysmem_heap = acpi_op_register_sysmem_heap,
+
+./board/x86/acpi-nswalk.c:448:static zx_status_t acpi_op_register_sysmem_heap(void* ctx, uint64_t heap, zx_handle_t handle) {
+./board/x86/acpi-nswalk.c:472:    .register_sysmem_heap = acpi_op_register_sysmem_heap,
+
diff --git a/zircon/system/banjo/ddk.protocol.acpi/acpi.banjo b/zircon/system/banjo/ddk.protocol.acpi/acpi.banjo
index c0e6376..82728f6 100644
--- a/zircon/system/banjo/ddk.protocol.acpi/acpi.banjo
+++ b/zircon/system/banjo/ddk.protocol.acpi/acpi.banjo
@@ -20,6 +20,4 @@
     GetMmio(uint32 index) -> (zx.status s, AcpiMmio mmio);
     MapInterrupt(int64 index) -> (zx.status s, handle<interrupt> @handle);
     GetBti(uint32 bdf, uint32 index) -> (zx.status s, handle<bti> bti);
-    ConnectSysmem(handle<channel> connection) -> (zx.status s);
-    RegisterSysmemHeap(uint64 heap, handle<channel> connection) -> (zx.status s);
 };
diff --git a/zircon/system/banjo/ddk.protocol.pciroot/pciroot.banjo b/zircon/system/banjo/ddk.protocol.pciroot/pciroot.banjo
index 906b544..261b86f 100644
--- a/zircon/system/banjo/ddk.protocol.pciroot/pciroot.banjo
+++ b/zircon/system/banjo/ddk.protocol.pciroot/pciroot.banjo
@@ -43,8 +43,6 @@
     /// Legacy methods
     GetAuxdata(string args) -> (zx.status s, vector<voidptr> data);
     GetBti(uint32 bdf, uint32 index) -> (zx.status s, handle<bti> bti);
-    // Create a sysmem connection - used to implement ddk.protocol.sysmem.
-    ConnectSysmem(handle connection) -> (zx.status s);
     /// Get the platform information structure from the pciroot protocol to be used for bus init.
     GetPciPlatformInfo() -> (zx.status s, PciPlatformInfo info);
     /// Get IRQ information, including the swizzle table.
diff --git a/zircon/system/dev/board/x86/acpi-nswalk.c b/zircon/system/dev/board/x86/acpi-nswalk.c
index 0e3e96e..6be19e5 100644
--- a/zircon/system/dev/board/x86/acpi-nswalk.c
+++ b/zircon/system/dev/board/x86/acpi-nswalk.c
@@ -429,47 +429,12 @@
     return zx_bti_create(iommu_handle, 0, bdf, bti);
 }
 
-static zx_status_t acpi_op_connect_sysmem(void* ctx, zx_handle_t handle) {
-    acpi_device_t* dev = (acpi_device_t*)ctx;
-    mtx_lock(&dev->lock);
-
-    sysmem_protocol_t sysmem;
-    zx_status_t st = device_get_protocol(dev->platform_bus, ZX_PROTOCOL_SYSMEM, &sysmem);
-    if (st != ZX_OK) {
-        zx_handle_close(handle);
-        goto unlock;
-    }
-    st = sysmem_connect(&sysmem, handle);
-unlock:
-    mtx_unlock(&dev->lock);
-    return st;
-}
-
-static zx_status_t acpi_op_register_sysmem_heap(void* ctx, uint64_t heap, zx_handle_t handle) {
-    acpi_device_t* dev = (acpi_device_t*)ctx;
-    mtx_lock(&dev->lock);
-
-    sysmem_protocol_t sysmem;
-    zx_status_t st = device_get_protocol(dev->platform_bus, ZX_PROTOCOL_SYSMEM, &sysmem);
-    if (st != ZX_OK) {
-        zx_handle_close(handle);
-        goto unlock;
-    }
-
-    st = sysmem_register_heap(&sysmem, heap, handle);
-unlock:
-    mtx_unlock(&dev->lock);
-    return st;
-}
-
 // TODO marking unused until we publish some devices
 static __attribute__ ((unused)) acpi_protocol_ops_t acpi_proto = {
     .get_pio = acpi_op_get_pio,
     .get_mmio = acpi_op_get_mmio,
     .map_interrupt = acpi_op_map_interrupt,
     .get_bti = acpi_op_get_bti,
-    .connect_sysmem = acpi_op_connect_sysmem,
-    .register_sysmem_heap = acpi_op_register_sysmem_heap,
 };
 
 static const char* hid_from_acpi_devinfo(ACPI_DEVICE_INFO* info) {
diff --git a/zircon/system/dev/board/x86/include/pciroot.h b/zircon/system/dev/board/x86/include/pciroot.h
index f0552b4..34045f4 100644
--- a/zircon/system/dev/board/x86/include/pciroot.h
+++ b/zircon/system/dev/board/x86/include/pciroot.h
@@ -32,7 +32,6 @@
   zx_status_t PcirootGetAuxdata(const char* args, void* out_data, size_t data_size,
                                 size_t* out_data_actual);
   zx_status_t PcirootGetBti(uint32_t bdf, uint32_t index, zx::bti* bti);
-  zx_status_t PcirootConnectSysmem(zx::handle handle);
   zx_status_t PcirootGetPciPlatformInfo(pci_platform_info_t* info);
   zx_status_t PcirootGetPciIrqInfo(pci_irq_info_t* info);
 
diff --git a/zircon/system/dev/board/x86/pciroot.cc b/zircon/system/dev/board/x86/pciroot.cc
index 0e4ee25..883852a 100644
--- a/zircon/system/dev/board/x86/pciroot.cc
+++ b/zircon/system/dev/board/x86/pciroot.cc
@@ -197,17 +197,6 @@
   return zx_bti_create(iommu_handle, 0, bdf, bti);
 }
 
-static zx_status_t pciroot_op_connect_sysmem(void* context, zx_handle_t handle) {
-  acpi_device_t* dev = (acpi_device_t*)context;
-  sysmem_protocol_t sysmem;
-  zx_status_t status = device_get_protocol(dev->platform_bus, ZX_PROTOCOL_SYSMEM, &sysmem);
-  if (status != ZX_OK) {
-    zx_handle_close(handle);
-    return status;
-  }
-  return sysmem_connect(&sysmem, handle);
-}
-
 #ifdef ENABLE_USER_PCI
 zx_status_t Pciroot::PcirootGetAuxdata(const char* args, void* data, size_t bytes, size_t* actual) {
   return pciroot_op_get_auxdata(c_context(), args, data, bytes, actual);
@@ -217,15 +206,6 @@
   return pciroot_op_get_bti(c_context(), bdf, index, bti->reset_and_get_address());
 }
 
-zx_status_t Pciroot::PcirootConnectSysmem(zx::handle handle) {
-  sysmem_protocol_t sysmem;
-  zx_status_t status = device_get_protocol(platform_bus_, ZX_PROTOCOL_SYSMEM, &sysmem);
-  if (status != ZX_OK) {
-    return status;
-  }
-  return sysmem_connect(&sysmem, handle.release());
-}
-
 zx_status_t Pciroot::PcirootGetPciPlatformInfo(pci_platform_info_t* info) {
   *info = ctx_->info;
   return ZX_OK;
@@ -424,7 +404,6 @@
 static pciroot_protocol_ops_t pciroot_proto = {
     .get_auxdata = pciroot_op_get_auxdata,
     .get_bti = pciroot_op_get_bti,
-    .connect_sysmem = pciroot_op_connect_sysmem,
     .get_pci_platform_info = pciroot_op_get_pci_platform_info,
     .get_pci_irq_info = pciroot_op_get_pci_irq_info,
     .driver_should_proxy_config = pciroot_op_driver_should_proxy_config,
diff --git a/zircon/system/dev/misc/goldfish/pipe-device.cc b/zircon/system/dev/misc/goldfish/pipe-device.cc
index 2fe03e1..311d120 100644
--- a/zircon/system/dev/misc/goldfish/pipe-device.cc
+++ b/zircon/system/dev/misc/goldfish/pipe-device.cc
@@ -293,5 +293,6 @@
 
 ZIRCON_DRIVER_BEGIN(goldfish, goldfish_driver_ops, "zircon", "0.1", 3)
 BI_ABORT_IF(NE, BIND_PROTOCOL, ZX_PROTOCOL_ACPI),
-    BI_ABORT_IF(NE, BIND_ACPI_HID_0_3, 0x47465348),  // GFSH0003\0
-    BI_MATCH_IF(EQ, BIND_ACPI_HID_4_7, 0x30303033), ZIRCON_DRIVER_END(goldfish)
+  BI_ABORT_IF(NE, BIND_ACPI_HID_0_3, 0x47465348),  // GFSH0003\0
+  BI_MATCH_IF(EQ, BIND_ACPI_HID_4_7, 0x30303033), 
+ZIRCON_DRIVER_END(goldfish)