> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man9/device_probe.9.md).

# DEVICE\_PROBE.9

`DEVICE_PROBE` — 探测设备是否存在

## 名称

`DEVICE_PROBE`

## 概要

```c
#include <sys/param.h>
#include <sys/bus.h>
```

```c
int
DEVICE_PROBE(device_t dev)
```

## 描述

`DEVICE_PROBE` 方法应探测设备是否存在。如果设备存在，应返回 0；如果找不到设备，返回 `ENXIO`。如果探测期间发生其他错误（例如内存分配失败），应返回适当的错误码。对于多个驱动程序匹配同一设备的情况，可以返回优先级值。在这种情况下，成功码为小于或等于零的值，其中最高值代表最佳匹配。失败码由正值表示，应使用常规的 UNIX 错误码。

如果驱动程序返回的成功码小于零，则不能假定它就是附加到该设备的同一个驱动程序。特别是，不能假定 softc 结构中存储的任何值在其 attach 方法中可用，并且在探测期间分配的任何资源都必须释放，并在调用 attach 方法时重新分配。此外，探测例程绝对不能有任何副作用。在调用 attach 例程之前，探测例程可能被多次调用。

如果返回的成功码为零，驱动程序可以假定它将是被附加的驱动程序，但在探测例程返回时不能持有任何资源。当驱动程序返回的成功码为零时，可以假定 softc 被保留。

## 返回值

等于或小于零的值表示成功，大于零的值表示错误（errno）。对于等于或小于零的值：零表示最高优先级，不再进一步探测；对于小于零的值，值越低优先级越低，例如 -100 表示的优先级低于 -50。

以下值按约定用于指示探测例程中不同强度的匹配。除非另有说明，这些只是建议值，并无特殊含义。

**BUS\_PROBE\_SPECIFIC** 无法重新探测的设备，且不可能存在其他驱动程序（通常是不遵循所有规则的遗留驱动程序，或具有特殊需求的驱动程序）。

**BUS\_PROBE\_VENDOR** 设备由供应商驱动程序支持。用于尚未集成到 FreeBSD 源码树的源代码或二进制驱动程序。禁止在基础操作系统中使用。

**BUS\_PROBE\_DEFAULT** 设备是匹配某个即插即用 ID 的普通设备。这是驱动程序正常使用的返回值。预期源码树中的几乎所有驱动程序都返回此值。

**BUS\_PROBE\_LOW\_PRIORITY** 驱动程序是遗留驱动程序，或对于给定即插即用 ID 是不太理想的驱动程序。该驱动程序有特殊要求，例如当两个驱动程序支持重叠系列的硬件设备时。在这种情况下，支持较老产品线的驱动程序会返回此值，而支持较新产品的驱动程序返回 BUS\_PROBE\_DEFAULT。

**BUS\_PROBE\_GENERIC** 驱动程序一般性地匹配该类型的设备。这允许驱动程序一般性地匹配所有串口，而专用驱动程序匹配因某种原因需要特殊处理的特定类型串口。

**BUS\_PROBE\_HOOVER** 驱动程序匹配总线上所有未被认领的设备。[ugen(4)](/man/man4/ugen.4.md) 设备就是一个例子。

**BUS\_PROBE\_NOWILDCARD** 驱动程序期望其父设备告知它要管理哪些子设备，实际上不进行探测。仅当其父总线明确指定使用此驱动程序时，设备才匹配。

## 参见

[device(9)](/man/man9/device.9.md), [DEVICE\_ATTACH(9)](/man/man9/device_attach.9.md), [DEVICE\_DETACH(9)](/man/man9/device_detach.9.md), [DEVICE\_IDENTIFY(9)](/man/man9/device_identify.9.md), [DEVICE\_SHUTDOWN(9)](/man/man9/device_shutdown.9.md)

## 作者

本手册页由 Doug Rabson 编写。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man9/device_probe.9.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
