This paper reviews the present understanding of the origin of ferromagnetic response of diluted magnetic semiconductors and diluted magnetic oxides as well as in some nominally magnetically undoped materials. It is argued that these systems can be grouped into four classes. To the first belong composite materials in which precipitations of a known ferromagnetic, ferrimagnetic or antiferromagnetic compound account for magnetic characteristics at high temperatures. The second class forms alloys showing chemical nano-scale phase separation into the regions with small and large concentrations of the magnetic constituent. To the third class belong (Ga,Mn)As, heavily doped p-(Zn,Mn)Te, and related semiconductors. In these solid solutions the theory built on p-d Zeners model of hole-mediated ferromagnetism and on either the Kohn-Luttinger kp theory or the multi-orbital tight-binding approach describes qualitatively, and often quantitatively many relevant properties. Finally, in a number of carrier-doped DMS and DMO a competition between long-range ferromagnetic and short-range antiferromagnetic interactions and/or the proximity of the localisation boundary lead to an electronic nano-scale phase separation.