# 即插即用

即插即用（Plug and Play，PnP）是一系列规范的总称，涵盖硬件与软件两个方面，其目标是让个人电脑用户免于自行配置硬件；为此，它使设备检测成为可能，将设备与正确的驱动程序配对，并处理DMA通道、中断请求（IRQ）和I/O端口等资源。<sup>[1](https://wiki.osdev.org/PnP)</sup> 按照微软的实现方式，这就是Windows中让计算机能够适应硬件变化、同时对用户要求极少的组件，它使设备可以在无需手动设置、也无需熟悉计算机硬件的情况下连接或断开。<sup>[2](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/introduction-to-plug-and-play)</sup>

| 关键事实 | 详情 |
|---|---|
| 目的 | 自动发现设备、匹配驱动程序并分配硬件资源（IRQ、DMA、I/O端口、内存），无需用户设置<sup>[1](https://wiki.osdev.org/PnP)</sup><sup> • </sup><sup>[2](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/introduction-to-plug-and-play)</sup> |
| 行业起源 | 即插即用计划由英特尔公司、康柏电脑公司和微软于1992年共同推出<sup>[3](https://news.microsoft.com/source/1999/01/07/microsoft-introduces-universal-plug-and-play-initiative-to-help-consumers-get-more-from-new-and-existing-home-electronics/)</sup> |
| 主流采用 | Windows 95（1995年）带来了广泛采用；在PnP之前，用户通过跳线或DIP开关配置设备，并手动避免资源冲突<sup>[4](https://devblogs.microsoft.com/oldnewthing/20191031-00/?p=103042)</sup> |
| Windows机制 | 内核模式PnP管理器维护一棵设备树；总线驱动程序报告设备的到达与移除，管理器则安装匹配的驱动程序包<sup>[5](https://learn.microsoft.com/en-us/windows-hardware/drivers/install/pnp-manager)</sup> |
| USB识别 | USBHUB驱动程序从设备描述符中提取idVendor、idProduct和bcdDevice，以生成硬件ID和兼容ID<sup>[6](https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/plug-and-play-support)</sup> |
| 遗留状态 | 截至2001年，ACPI已承担起PnP BIOS和APM的角色，而PCI通过其配置空间天生具备即插即用能力，使PnP BIOS方案变得过时<sup>[1](https://wiki.osdev.org/PnP)</sup> |
| 网络扩展 | 微软于1999年1月7日宣布的通用即插即用，将该模式扩展到了联网的消费电器和个人电脑<sup>[3](https://news.microsoft.com/source/1999/01/07/microsoft-introduces-universal-plug-and-play-initiative-to-help-consumers-get-more-from-new-and-existing-home-electronics/)</sup> |

## 它解决的问题

在即插即用出现之前的时代，设备的设置必须通过跳线或DIP开关手动调整，用户还得负责安排好I/O端口、IRQ通道和其他资源，使设备之间绝不重叠，之后还必须手动为驱动程序设置正确的资源分配。<sup>[4](https://devblogs.microsoft.com/oldnewthing/20191031-00/?p=103042)</sup> [Windows 95](https://www.edgepedia.org/zh/windows-95)的重大成就之一，就是广泛普及了这样一种当时被形容为近乎异端的想法：设备可以是软件可配置的，操作系统可以自动解决硬件设备之间的资源冲突。<sup>[4](https://devblogs.microsoft.com/oldnewthing/20191031-00/?p=103042)</sup> Windows 95在注册表中跟踪设备资源，并利用这些配置信息自动识别和解决符合即插即用规范的设备的资源冲突；对于遗留设备，冲突会在[设备管理器](https://www.edgepedia.org/zh/device-manager)中高亮显示，以便用户和支持机构识别。<sup>[7](https://library.thedatadungeon.com/msdn-2000-04/dnwin95/html/S70C2.content.HTM)</sup>

该计划本身由英特尔、康柏和微软于1992年推出，需要设备硬件、系统软件和驱动程序三方面的支持，而硬件行业的各项计划则定义了便于识别附加板卡和系统组件的标准。<sup>[3](https://news.microsoft.com/source/1999/01/07/microsoft-introduces-universal-plug-and-play-initiative-to-help-consumers-get-more-from-new-and-existing-home-electronics/)</sup><sup> • </sup><sup>[2](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/introduction-to-plug-and-play)</sup>

## 它在Windows中如何工作

**PnP管理器。** 即插即用管理器提供Windows中PnP功能的支持，负责系统启动时的设备检测与枚举、处理系统运行期间设备的添加或移除，以及为新设备安装匹配的驱动程序包。内核模式PnP管理器维护一棵设备树，用于跟踪系统中的设备；它在启动时根据驱动程序和其他组件提供的信息构建这棵树，并在设备添加或移除时更新它。<sup>[5](https://learn.microsoft.com/en-us/windows-hardware/drivers/install/pnp-manager)</sup> 当总线驱动程序检测到子设备的到达或移除时，会向内核模式PnP管理器报告，后者要么直接在新设备上安装驱动程序包，要么通知用户模式PnP管理器需要进行安装。对于已安装驱动程序包的设备，内核模式管理器会调用该设备的设备栈中驱动程序的DriverEntry和AddDevice例程，并发送IRP_MN_START_DEVICE请求以启动设备。<sup>[5](https://learn.microsoft.com/en-us/windows-hardware/drivers/install/pnp-manager)</sup>

**资源分配。** PnP管理器确定每个设备请求的硬件资源，如输入/输出端口、中断请求、直接内存访问通道和内存位置，并适当地分配它们，当新设备需要已被占用的资源时重新配置分配。PnP设备的驱动程序不自行分配资源；所请求的资源在设备枚举时被识别。由于遗留设备的资源无法动态配置，PnP管理器会优先为遗留设备分配资源。<sup>[2](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/introduction-to-plug-and-play)</sup>

**识别与驱动程序匹配。** Windows即插即用使用设备枚举器提供的标识符来选择并安装适当的驱动程序；这些标识符在设备管理器中对用户可见，列在“硬件ID”和“兼容ID”属性中。<sup>[8](https://learn.microsoft.com/ro-ro/windows-hardware/drivers/bringup/device-management-namespace-objects)</sup> 给定设备通常有一个硬件ID列表，其中第一个是设备ID，后续ID则不那么具体，而Windows安装程序在查找驱动程序时，会将发现的设备标识字符串映射到驱动程序INF文件。<sup>[9](https://download.microsoft.com/download/8/6/2/862977E5-8D21-4A1C-8DC9-C2289244C14C/Componentization%20of%20Device%20Drivers%20in%20Windows%20Embedded%20Standard%207.pdf)</sup>

## USB示例

USB是PnP对用户来说最为可见的总线。当设备插入基于Windows的计算机时，Windows USB栈会枚举该设备，提取包括接口描述符在内的详细信息，然后为其生成一组硬件ID和兼容ID。<sup>[6](https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/plug-and-play-support)</sup> 这些信息来自称为USB描述符的数据结构：每个设备都会公开一个设备描述符，其中包含类信息、供应商和产品标识符以及配置数量；每个配置公开一个配置描述符，其中包含接口数量和电源特性；每个接口针对每个备用设置公开一个接口描述符；每个端点公开一个端点描述符，给出其类型和最大数据包大小。<sup>[10](https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/standard-usb-descriptors)</sup> 主机通过向设备的默认端点发送标准的“获取描述符”控制请求来获得这些描述符。<sup>[10](https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/standard-usb-descriptors)</sup>

USBHUB驱动程序从设备描述符中提取idVendor、idProduct和bcdDevice字段，USB驱动程序栈则使用bcdDevice连同idVendor和idProduct来生成硬件ID和兼容ID。<sup>[6](https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/plug-and-play-support)</sup><sup> • </sup><sup>[10](https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/standard-usb-descriptors)</sup> 类代码也驱动匹配：USB用三个字节定义类代码信息，分别称为基类、子类和协议，用于识别设备的功能，并名义上根据该功能加载设备驱动程序；这些代码可以出现在设备描述符中、接口描述符中，或两者兼有，具体取决于类。<sup>[11](https://usb.org/defined-class-codes)</sup> 对于没有硬件ID匹配的复合（多接口）设备，Windows即插即用使用USB\\COMPOSITE标识符来加载USB通用父驱动程序（USBCCGP）。<sup>[6](https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/plug-and-play-support)</sup>

## 遗留PnP及其替代

ISA PnP标准规定了三个8位端口用于访问配置空间，并允许通过配置空间重新分配资源以避免冲突，尽管它不允许IRQ共享。<sup>[1](https://wiki.osdev.org/PnP)</sup><sup> • </sup><sup>[12](https://wiki.osdev.org/ISA)</sup> 截至2001年，ACPI已承担起PnP BIOS和APM的角色，而PCI通过其配置空间天生具备即插即用功能，使PnP BIOS变得过时。<sup>[1](https://wiki.osdev.org/PnP)</sup> 在现代Windows系统上，连接到没有自身枚举能力的总线的设备，例如由ACPI固件描述的设备，由ACPI驱动程序Acpi.sys为PnP管理器进行枚举。<sup>[13](https://learn.microsoft.com/en-us/windows-hardware/drivers/spb/spb-device-stacks)</sup>

## 超越PC总线

该模式向两个方向扩展。在Linux中，内核设备模型将先前各自为政的、特定于总线的驱动程序模型统一为一个通用、一致的数据模型，用于描述总线和设备，体现了无缝设备“即插即用”、电源管理和热插拔的目标；当新设备注册时，总线会遍历其驱动程序列表，匹配设备ID，并调用匹配驱动程序的probe()例程以验证支持并初始化硬件。<sup>[14](https://cdn.kernel.org/doc/html/latest/driver-api/driver-model/overview.html)</sup><sup> • </sup><sup>[15](https://cdn.kernel.org/doc/html/latest/driver-api/driver-model/binding.html)</sup> 在向网络领域迈进时，微软于1999年1月7日在消费电子展上推出了[通用即插即用](https://www.edgepedia.org/zh/universal-plug-and-play)：这是一项跨行业计划，旨在建立一套描述设备和服务的共享接口，使连接到网络的设备能够被自动发现，然后无需复杂配置即可被其他设备和人们使用；微软将其定位为1992年开始的即插即用工作的下一阶段，并使其能够在任何网络介质和任何设备类型上工作，无需中央服务器。<sup>[3](https://news.microsoft.com/source/1999/01/07/microsoft-introduces-universal-plug-and-play-initiative-to-help-consumers-get-more-from-new-and-existing-home-electronics/)</sup>

## References

1. [Plug-and-Play, OSDev Wiki](https://wiki.osdev.org/PnP)
2. [Introduction to Plug and Play, Microsoft Learn (Windows drivers)](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/introduction-to-plug-and-play)
3. [Microsoft Introduces Universal Plug and Play Initiative, Microsoft press release, January 7, 1999](https://news.microsoft.com/source/1999/01/07/microsoft-introduces-universal-plug-and-play-initiative-to-help-consumers-get-more-from-new-and-existing-home-electronics/)
4. [For one internal build, Windows 95 contained an evil message, The Old New Thing, Microsoft DevBlogs](https://devblogs.microsoft.com/oldnewthing/20191031-00/?p=103042)
5. [Plug and Play Manager, Microsoft Learn (Windows drivers)](https://learn.microsoft.com/en-us/windows-hardware/drivers/install/pnp-manager)
6. [Plug and Play Support (USB enumeration), Microsoft Learn (Windows drivers)](https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/plug-and-play-support)
7. [Improved Device Support in Windows 95, Microsoft Systems Journal / MSDN archive](https://library.thedatadungeon.com/msdn-2000-04/dnwin95/html/S70C2.content.HTM)
8. [Device Management Namespace Objects, Microsoft Learn (Windows drivers)](https://learn.microsoft.com/ro-ro/windows-hardware/drivers/bringup/device-management-namespace-objects)
9. [Componentization of Device Drivers in Windows Embedded Standard 7, Microsoft download](https://download.microsoft.com/download/8/6/2/862977E5-8D21-4A1C-8DC9-C2289244C14C/Componentization%20of%20Device%20Drivers%20in%20Windows%20Embedded%20Standard%207.pdf)
10. [Standard USB Descriptors, Microsoft Learn (Windows drivers)](https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/standard-usb-descriptors)
11. [Defined Class Codes, USB Implementers Forum](https://usb.org/defined-class-codes)
12. [ISA, OSDev Wiki](https://wiki.osdev.org/ISA)
13. [SPB Device Stacks, Microsoft Learn (Windows drivers)](https://learn.microsoft.com/en-us/windows-hardware/drivers/spb/spb-device-stacks)
14. [The Linux Kernel Device Model, kernel.org documentation](https://cdn.kernel.org/doc/html/latest/driver-api/driver-model/overview.html)
15. [Driver Binding, kernel.org documentation](https://cdn.kernel.org/doc/html/latest/driver-api/driver-model/binding.html)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026; Oct 25, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Boards, peripherals & form factors › Peripherals & expansion hardware

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/plug-and-play

English original: https://www.edgepedia.org/plug-and-play
