[fdf] Remove misc parent device

All clients have been migrated to binding to other devices, so the misc
parent device can be removed.

Bug: 77388
Tested: fx test driver-manager-tests
Change-Id: I36eec3093ffc17556bd3bfbdc6b886d900fb116c
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/555048
Fuchsia-Auto-Submit: Suraj Malhotra <surajmalhotra@google.com>
Reviewed-by: Abdulla Kamar <abdulla@google.com>
API-Review: Abdulla Kamar <abdulla@google.com>
Commit-Queue: Suraj Malhotra <surajmalhotra@google.com>
diff --git a/examples/drivers/fifo/BUILD.gn b/examples/drivers/fifo/BUILD.gn
index e0f4784..c1f7fdd 100644
--- a/examples/drivers/fifo/BUILD.gn
+++ b/examples/drivers/fifo/BUILD.gn
@@ -10,7 +10,7 @@
   rules = "demo-fifo.bind"
   header_output = "demo-fifo-bind.h"
   tests = "tests.json"
-  deps = [ "//src/devices/bind/fuchsia.misc" ]
+  deps = [ "//src/devices/bind/fuchsia.test" ]
 }
 
 group("fifo") {
diff --git a/examples/drivers/fifo/demo-fifo.bind b/examples/drivers/fifo/demo-fifo.bind
index 36ca6a2..aedb8cd 100644
--- a/examples/drivers/fifo/demo-fifo.bind
+++ b/examples/drivers/fifo/demo-fifo.bind
@@ -2,6 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-using fuchsia.misc;
+using fuchsia.test;
 
-fuchsia.BIND_PROTOCOL == fuchsia.misc.BIND_PROTOCOL.PARENT;
+fuchsia.BIND_PROTOCOL == fuchsia.test.BIND_PROTOCOL.PARENT;
diff --git a/examples/drivers/fifo/tests.json b/examples/drivers/fifo/tests.json
index 1eeaeda..fb9302e9 100644
--- a/examples/drivers/fifo/tests.json
+++ b/examples/drivers/fifo/tests.json
@@ -8,7 +8,7 @@
     },
     {
         "device": {
-            "fuchsia.BIND_PROTOCOL": "fuchsia.misc.BIND_PROTOCOL.PARENT"
+            "fuchsia.BIND_PROTOCOL": "fuchsia.test.BIND_PROTOCOL.PARENT"
         },
         "expected": "match",
         "name": "demo-fifo"
diff --git a/src/devices/bin/driver_host/core.cc b/src/devices/bin/driver_host/core.cc
index cc71650..5a968da 100644
--- a/src/devices/bin/driver_host/core.cc
+++ b/src/devices/bin/driver_host/core.cc
@@ -45,7 +45,7 @@
 void set_bind_context(internal::BindContext* ctx) { g_bind_context = ctx; }
 
 void set_creation_context(CreationContext* ctx) {
-  ZX_DEBUG_ASSERT(!ctx  || ctx->coordinator_client);
+  ZX_DEBUG_ASSERT(!ctx || ctx->coordinator_client);
   g_creation_context = ctx;
 }
 
@@ -254,7 +254,7 @@
     LOGD(ERROR, *dev, "Invalid ops for device %p", dev.get());
     return ZX_ERR_INVALID_ARGS;
   }
-  if ((dev->protocol_id() == ZX_PROTOCOL_MISC_PARENT) || (dev->protocol_id() == ZX_PROTOCOL_ROOT)) {
+  if ((dev->protocol_id() == ZX_PROTOCOL_ROOT)) {
     LOGD(ERROR, *dev, "Invalid protocol for device %p: %#x", dev.get(), dev->protocol_id());
     // These protocols is only allowed for the special
     // singleton misc or root parent devices.
diff --git a/src/devices/bin/driver_manager/coordinator.cc b/src/devices/bin/driver_manager/coordinator.cc
index a187735..0284acb 100644
--- a/src/devices/bin/driver_manager/coordinator.cc
+++ b/src/devices/bin/driver_manager/coordinator.cc
@@ -185,10 +185,6 @@
                                              ZX_PROTOCOL_ROOT, zx::vmo(), zx::channel());
   root_device_->flags = DEV_CTX_IMMORTAL | DEV_CTX_MUST_ISOLATE | DEV_CTX_MULTI_BIND;
 
-  misc_device_ = fbl::MakeRefCounted<Device>(this, "misc", fbl::String(), "misc,", root_device_,
-                                             ZX_PROTOCOL_MISC_PARENT, zx::vmo(), zx::channel());
-  misc_device_->flags = DEV_CTX_IMMORTAL | DEV_CTX_MUST_ISOLATE | DEV_CTX_MULTI_BIND;
-
   sys_device_ = fbl::MakeRefCounted<Device>(this, "sys", sys_device_driver, "sys,", root_device_, 0,
                                             zx::vmo(), zx::channel());
   sys_device_->flags = DEV_CTX_IMMORTAL | DEV_CTX_MUST_ISOLATE;
@@ -250,7 +246,6 @@
 
 void Coordinator::DumpState(VmoWriter* vmo) const {
   DumpDevice(vmo, root_device_.get(), 0);
-  DumpDevice(vmo, misc_device_.get(), 1);
   DumpDevice(vmo, sys_device_.get(), 1);
   DumpDevice(vmo, test_device_.get(), 1);
 }
@@ -1401,10 +1396,6 @@
   if (status != ZX_ERR_NEXT) {
     return status;
   }
-  status = BindDriverToDevice(misc_device_, drv, true /* autobind */, attempt_bind);
-  if (status != ZX_ERR_NEXT) {
-    return status;
-  }
   status = BindDriverToDevice(test_device_, drv, true /* autobind */, attempt_bind);
   if (status != ZX_ERR_NEXT) {
     return status;
@@ -1451,11 +1442,6 @@
     LOGF(ERROR, "DriverIndex failed to match root_device: %d", status);
     return;
   }
-  status = MatchAndBindDeviceDriverIndex(misc_device_);
-  if (status != ZX_OK && status != ZX_ERR_NEXT) {
-    LOGF(ERROR, "DriverIndex failed to match misc_device: %d", status);
-    return;
-  }
   status = MatchAndBindDeviceDriverIndex(test_device_);
   if (status != ZX_OK && status != ZX_ERR_NEXT) {
     LOGF(ERROR, "DriverIndex failed to match test_device: %d", status);
@@ -1967,7 +1953,6 @@
                                         DumpBindingPropertiesCompleter::Sync& completer) {
   VmoWriter writer{std::move(request->output)};
   DumpDeviceProps(&writer, root_device_.get());
-  DumpDeviceProps(&writer, misc_device_.get());
   DumpDeviceProps(&writer, sys_device_.get());
   DumpDeviceProps(&writer, test_device_.get());
   completer.Reply(writer.status(), writer.written(), writer.available());
diff --git a/src/devices/bin/driver_manager/coordinator.h b/src/devices/bin/driver_manager/coordinator.h
index a0908ca..644568b 100644
--- a/src/devices/bin/driver_manager/coordinator.h
+++ b/src/devices/bin/driver_manager/coordinator.h
@@ -310,7 +310,6 @@
   }
 
   const fbl::RefPtr<Device>& root_device() { return root_device_; }
-  const fbl::RefPtr<Device>& misc_device() { return misc_device_; }
   const fbl::RefPtr<Device>& sys_device() { return sys_device_; }
   const fbl::RefPtr<Device>& test_device() { return test_device_; }
 
@@ -379,7 +378,6 @@
   fbl::DoublyLinkedList<std::unique_ptr<CompositeDevice>> composite_devices_;
 
   fbl::RefPtr<Device> root_device_;
-  fbl::RefPtr<Device> misc_device_;
   fbl::RefPtr<Device> sys_device_;
   fbl::RefPtr<Device> test_device_;
 
diff --git a/src/devices/bin/driver_manager/devfs.cc b/src/devices/bin/driver_manager/devfs.cc
index 085dd77..45eac34 100644
--- a/src/devices/bin/driver_manager/devfs.cc
+++ b/src/devices/bin/driver_manager/devfs.cc
@@ -610,8 +610,7 @@
     return ZX_ERR_NO_MEMORY;
   }
 
-  if ((dev->protocol_id() == ZX_PROTOCOL_TEST_PARENT) ||
-      (dev->protocol_id() == ZX_PROTOCOL_MISC_PARENT) || (dev->protocol_id() == ZX_PROTOCOL_MISC)) {
+  if ((dev->protocol_id() == ZX_PROTOCOL_TEST_PARENT) || (dev->protocol_id() == ZX_PROTOCOL_MISC)) {
     // misc devices are singletons, not a class
     // in the sense of other device classes.
     // They do not get aliases in /dev/class/misc/...
diff --git a/src/devices/bin/driver_manager/main.cc b/src/devices/bin/driver_manager/main.cc
index 76d5527..f89253f 100644
--- a/src/devices/bin/driver_manager/main.cc
+++ b/src/devices/bin/driver_manager/main.cc
@@ -400,7 +400,6 @@
   }
 
   devfs_init(coordinator.root_device(), loop.dispatcher());
-  devfs_publish(coordinator.root_device(), coordinator.misc_device());
   devfs_publish(coordinator.root_device(), coordinator.sys_device());
   devfs_publish(coordinator.root_device(), coordinator.test_device());
   devfs_connect_diagnostics(coordinator.inspect_manager().diagnostics_client());
diff --git a/src/devices/bin/driver_manager/misc_tests.cc b/src/devices/bin/driver_manager/misc_tests.cc
index da73feb..097f5fe 100644
--- a/src/devices/bin/driver_manager/misc_tests.cc
+++ b/src/devices/bin/driver_manager/misc_tests.cc
@@ -314,14 +314,6 @@
   }
 
   {
-    zx_bind_inst_t misc_drv_bind[] = {
-        BI_MATCH_IF(EQ, BIND_PROTOCOL, ZX_PROTOCOL_MISC_PARENT),
-    };
-    auto misc_drv = make_fake_driver(misc_drv_bind);
-    ASSERT_OK(coordinator.BindDriver(misc_drv.get(), CallOnce{__LINE__}));
-  }
-
-  {
     zx_bind_inst_t root_drv_bind[] = {
         BI_MATCH_IF(EQ, BIND_PROTOCOL, ZX_PROTOCOL_ROOT),
     };
@@ -339,15 +331,6 @@
   }
 
   {
-    zx_bind_inst_t misc_drv_bind[] = {
-        BI_MATCH_IF(EQ, BIND_PROTOCOL, ZX_PROTOCOL_MISC_PARENT),
-        BI_MATCH_IF(EQ, BIND_PROTOCOL, ZX_PROTOCOL_I2C),
-    };
-    auto misc_drv = make_fake_driver(misc_drv_bind);
-    ASSERT_OK(coordinator.BindDriver(misc_drv.get(), CallOnce{__LINE__}));
-  }
-
-  {
     zx_bind_inst_t root_drv_bind[] = {
         BI_MATCH_IF(EQ, BIND_PROTOCOL, ZX_PROTOCOL_ROOT),
         BI_MATCH_IF(EQ, BIND_PROTOCOL, ZX_PROTOCOL_I2C),
diff --git a/src/devices/bind/fuchsia.misc/fuchsia.misc.bind b/src/devices/bind/fuchsia.misc/fuchsia.misc.bind
index d4a7758..dd3c2bf5 100644
--- a/src/devices/bind/fuchsia.misc/fuchsia.misc.bind
+++ b/src/devices/bind/fuchsia.misc/fuchsia.misc.bind
@@ -6,5 +6,4 @@
 
 extend uint fuchsia.BIND_PROTOCOL {
   DEVICE = 28,
-  PARENT = 29,
 };
diff --git a/src/lib/ddk/ddk.api b/src/lib/ddk/ddk.api
index 4d3e8db..3a8659e 100644
--- a/src/lib/ddk/ddk.api
+++ b/src/lib/ddk/ddk.api
@@ -11,6 +11,6 @@
   "pkg/ddk/include/lib/ddk/metadata.h": "e92fdbb682c5259a989c0c46d448e47c",
   "pkg/ddk/include/lib/ddk/mmio-buffer.h": "c367b69b7d7339ee0216b9297921eefe",
   "pkg/ddk/include/lib/ddk/phys-iter.h": "d39773b5ab2a3175193afaf0ed41f2e0",
-  "pkg/ddk/include/lib/ddk/protodefs.h": "d4c7565bfeae55a96a9d0d53737a6f4f",
+  "pkg/ddk/include/lib/ddk/protodefs.h": "f1542da45582fc2c744bcc89e4e229fa",
   "pkg/ddk/include/lib/ddk/trace/event.h": "e538e7ff5318c397e0cd1dca545eadca"
 }
\ No newline at end of file
diff --git a/src/lib/ddk/include/lib/ddk/protodefs.h b/src/lib/ddk/include/lib/ddk/protodefs.h
index 3151c13..a802601 100644
--- a/src/lib/ddk/include/lib/ddk/protodefs.h
+++ b/src/lib/ddk/include/lib/ddk/protodefs.h
@@ -47,7 +47,6 @@
 DDK_PROTOCOL_DEF(INPUTREPORT,             26,   "input-report", 0)
 DDK_PROTOCOL_DEF(ROOT,                    27,   "root", PF_NOPUB)
 DDK_PROTOCOL_DEF(MISC,                    28,   "misc", PF_NOPUB)
-DDK_PROTOCOL_DEF(MISC_PARENT,             29,   "misc-parent", PF_NOPUB)
 DDK_PROTOCOL_DEF(ACPI,                    30,   "acpi", 0)
 DDK_PROTOCOL_DEF(PCI,                     31,   "pci", 0)
 DDK_PROTOCOL_DEF(PCIROOT,                 32,   "pci-root", PF_NOPUB)