# bumblebee-project/bbswitch architecture

> Architecture diagram of the GitHub repository bumblebee-project/bbswitch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bumblebee-project/bbswitch
- Repository: https://github.com/bumblebee-project/bbswitch

## Overview

bbswitch is a Linux kernel module for detecting an Optimus discrete GPU and controlling its power through ACPI. The principal workflow is a privileged write to `/proc/acpi/bbswitch`, which requests the card be turned on or off; users can also read its status. Initialization discovers graphics devices and ACPI handles, while suspend/resume handling restores the prior disabled state. The graph reflects the single sampled runtime source and README-documented interfaces; details of omitted code are not inferred.

Main entry points: [`bbswitch.c`](https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c) (Card power control)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_proc["Proc interface<br/>[bbswitch.c]"]
end

subgraph group_device["Device Control"]
  node_discovery["GPU discovery<br/>[bbswitch.c]"]
  node_power["Card power control<br/>[bbswitch.c]"]
end

subgraph group_lifecycle["Module Lifecycle"]
  node_lifecycle["Module lifecycle<br/>[bbswitch.c]"]
end

node_user(("Root user"))
node_acpi["ACPI firmware"]
node_pci["PCI subsystem"]
node_pm["Power events"]

node_user -->|"reads or writes"| node_proc
node_proc -->|"requests switching"| node_power
node_proc -->|"reports status"| node_user
node_lifecycle -->|"discovers devices"| node_discovery
node_discovery -->|"scans devices"| node_pci
node_discovery -->|"finds handles"| node_acpi
node_power -->|"evaluates DSM"| node_acpi
node_power -->|"sets power state"| node_pci
node_pm -->|"restores state"| node_power
node_lifecycle -->|"applies options"| node_power

click node_proc "https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c"
click node_discovery "https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c"
click node_power "https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c"
click node_lifecycle "https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_proc,node_user toneBlue
class node_discovery,node_power toneAmber
class node_lifecycle toneMint
class node_acpi,node_pci,node_pm toneIndigo
```

## Components

### User Interface

- [Proc interface](https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c): `bbswitch.c`

### Device Control

- [GPU discovery](https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c): `bbswitch.c`
- [Card power control](https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c): `bbswitch.c`

### Module Lifecycle

- [Module lifecycle](https://github.com/bumblebee-project/bbswitch/blob/master/bbswitch.c): `bbswitch.c`

### Other components

- **Root user**
- **ACPI firmware**
- **PCI subsystem**
- **Power events**

## Connections

- Root user → Proc interface: reads or writes (evidence: `README.md`)
- Proc interface → Card power control: requests switching (evidence: `README.md`)
- Proc interface → Root user: reports status (evidence: `README.md`)
- Module lifecycle → GPU discovery: discovers devices (evidence: `bbswitch.c`)
- GPU discovery → PCI subsystem: scans devices (evidence: `bbswitch.c`)
- GPU discovery → ACPI firmware: finds handles (evidence: `bbswitch.c`)
- Card power control → ACPI firmware: evaluates DSM (evidence: `bbswitch.c`)
- Card power control → PCI subsystem: sets power state (evidence: `bbswitch.c`)
- Power events → Card power control: restores state (evidence: `bbswitch.c`)
- Module lifecycle → Card power control: applies options (evidence: `README.md`)
