API 和设备驱动程序之间的区别 [英] Difference between an API and a device driver

查看:69
本文介绍了API 和设备驱动程序之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解它们之间的关系.据我所知,他们都可以成为 HAL 的一部分.在应用程序和显卡之间进行通信的情况下 - API 可以自行完成工作还是我们必须同时依赖它们?API 是否可以直接与硬件通信,或者我们是否总是需要一个驱动程序来转换 API 的命令?

I try to understand how they both relate to each other. As far as I know, they both can be a part of the HAL. In case of a communication between an application and a graphics card - can an API get the job done on its own or do we have to rely on them both? Can an API directly communicate with the hardware or do we always need a driver in-between, which translates the command of the API?

推荐答案

TL;DR

将 API 视为描述要做什么的规范,而驱动程序则是描述如何去做的实现.

TL;DR

Think of an API as a specification that describes what to do, while a driver is an implementation that describes how to do it.

举一个人为的例子,假设我们有三种不同的声卡,我们想要在多个操作系统上很好地播放.我们可以为卡制造商定义一个API,上面写着每张卡必须支持四种方法:mute()playsound(sound)volumeup()volumedown()".通过定义 API,我们获得了一个通用接口,允许操作系统设计人员支持音频设备而无需担心硬件细节.他们知道,如果要使声卡静音,可以调用mute(),或者如果要调高音量,则调用volumeup().

As a contrived example, imagine we have three different audio cards that we want to play nicely with multiple operating systems. We can define an API for the card manufacturers that says, "Each card must support four methods: mute(), playsound(sound), volumeup() and volumedown()". By defining the API, we get a common interface that allows the operating system designers to support the audio devices without worrying about the hardware details. They know that if they want to mute the sound card, they can call mute(), or if they want to turn the volume up, they call volumeup().

然后由设备制造商实现一个实际执行这些操作的驱动程序.三种不同的声卡之间的驱动程序会有所不同,因为它们在硬件级别上有所不同,但 API 是一致的,因此下一个更高的抽象级别(操作系统)不需要知道如何处理硬件.

It is then up to the device manufacturers to implement a driver that actually performs those actions. The driver will vary between the three different audio cards because they are different at the hardware level, but the API is consistent so the next higher abstraction level (the OS) doesn't need to know how to deal with the hardware.

有关更具体的示例,请考虑 Advanced Control &电源接口 (ACPI) 规范.它为操作系统定义了一个通用接口,用于管理硬件设备的功耗和热特性.设备驱动程序或固件必须实现一些方法才能符合 ACPI".这允许 Windows 操作系统和 Linux 变体在硬件设备上执行相同的操作,而无需为硬件实现自己的驱动程序

For a more concrete example, consider the Advanced Control & Power Interface (ACPI) specification. It defines a common interface for operating systems to manage power consumption and thermal characteristics of hardware devices. There are methods that a device driver or firmware must implement in order to be "ACPI Compliant". This allows Windows operating systems and Linux variants to both perform the same actions on hardware devices without needing to implement their own drivers for the hardware

注意:Windows 通过 acpi.sys,他们称之为ACPI 驱动程序".不要让术语混淆你;尽管他们称它为驱动程序,但它实际上是进入 ACPI 界面的窗口.Linux 使用 acpi 内核模块来做同样的事情,Linux 不称其为驱动程序.也许 ACPI 不是最好的例子,但我目前没有更好的例子.

Note: Windows performs ACPI actions through acpi.sys, which they call an "ACPI Driver". Don't let the terminology confuse you; even though they call it a driver, it is really a window into the ACPI interface. Linux uses the acpi kernel module to do the same thing, and Linux doesn't call it a driver. Perhaps ACPI wasn't the best example, but I don't have anything better at the moment.

这篇关于API 和设备驱动程序之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆