The "Underdark" — as it is referred to in D&D, though equivalents exist in many settings — refers to the massive network of caverns and connected cave systems, ranging in depth from just below the surface to around 20km in some deep parts. I have a similar set of caverns in a setting of my own.
I was just thinking about where the breathable oxygen comes from for its animal and humanoid residents. Such fantasy places usually have rich fungal life and several sentient races. On earth, our first significant O2 in the atmosphere came from the photosynthesis of cyanobacteria, which used the already available CO2 in the atmosphere.
If we assume the raw materials (oxygen stored in minerals, volcanic gases) exist, what sort of lifeforms would be the best candidate for turning the available energy in the Underdark into energy for themselves, with oxygen as a waste product, and where might they prefer to live? If nothing fitting that spot exists today exactly, could that position be filled by a lifeform that only uses traits that exist today in some capacity, even if an amalgam of different species — can a chemosynthetic plantlike structure exist?
For the sake of this question, presume the geothermal gradient is not a substantial issue, because in this setting the entirety of the massive cavern structure known as the Underdark was crafted by divines, and enchanted in such a way that the excess geothermal heat (which was above the level for mortal life to survive in most large caverns) is used up to fuel magic which supports the caverns. Places which have magma by way of volcanic/seismic activity bringing it into the area would still become very hot, though.
