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

查看:418
本文介绍了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,该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.

有关更具体的示例,请考虑高级控制和功能;电源接口(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内核模块来完成相同的操作,而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天全站免登陆